0

I have PDFs made of of SVGs, one per page. Old PDFs were created with SVGs with a fill color of #000000, but we have and want newer PDFs with a fill color of #b5b5b5.

Until now, I'll go in by hand with inkscape, open the old PDF, select all layers, then set the fill color of the SVGs to #b5b5b5ff from #000000ff, then save. This is tedious.

Can I automate this somehow with an inkscape script or command line options?

Thanks!

2
  • Well pdf is just text so yes you can do it on the command line. But you may find ghostscript, or adobe acrobat (not reader) handy
    – joojaa
    Commented Aug 23, 2023 at 17:36
  • I'm open to any solution, Inkscape is the only thing that I know does it.
    – user319249
    Commented Aug 23, 2023 at 17:57

1 Answer 1

0

PDFs generally do not use #000000ff or SVG structures (those are designed for HTML long after PDF was designed)

So decompressing a PDF you would have problems seeking that colour, Luckily you are not attempting all 4 as that would perhaps be a mammoth PDF editor task deciding which change and which do not.

So in a PDF rgb stroke is probably like all Black objects [0 0 0] or 0 0 0 rg or RG, or one of many other methods. Thus without your sample no way to tell exactly what needs to change but #b5b5b5 is in CMYK set as cmyk(0%, 0%, 0%, 29%) or RGB = 0.29 0.29 0.29

enter image description here

Both those values are likely many bytes more than the black entry which could be as short as say = 1 K. This is a major problem when PDF cannot simply be edited as one byte more or one byte less and not corrupt the objects index (xref in the tail).

In this very simple case we can instantly see, save 0 1 0 rg will make ALL black green (NOTE the number of bytes did not change, we just toggled green on from off)

enter image description here

However edit as 0.29 0.29 0.29 rg will usually corrupt the file.

You have 3 fairly easy options.

  1. use a command line tool like cpdf and tell it to turn black objects grey, however it is like cracking walnuts with a precision jack hammer, it needs a light touch [on] paper and run (joke). It should work in this case to turn ALL fills to the desired 50 shade of grey ? enter image description here

  2. Decompress the PDF with say mutool, and use a text editor in one small area (like I did) and save then use mutool clean in.pdf out.pdf to heal the rift. OR if the rift is minor Acrobat will open the file and offer to rewrite on save but that's slow as one at a time. enter image description here

Answer

build a script that can be called with each filename in turn

enter image description here

Here are the steps in a windows console (fart-it is a SourceForge FnR tool)

Apps\PDF\mupdf\1.20.0>mutool clean -d rainbow.pdf decompressed.pdf

Apps\PDF\mupdf\1.20.0>copy decompressed.pdf decompressed.pdf.bak
Overwrite decompressed.pdf.bak? (Yes/No/All): y
        1 file(s) copied.

Apps\PDF\mupdf\1.20.0>fart -b -B -- decompressed.pdf "0 0 0 RG 0 0 0 rg" "0 0 0 RG 0.29 0.29 0.29 rg"
Warning: fart may corrupt binary files
decompressed.pdf
Replaced 1 occurence(s) in 1 file(s).

Apps\PDF\mupdf\1.20.0>mutool clean -z decompressed.pdf output.pdf
error: cannot recognize xref format
warning: trying to repair broken xref
warning: repairing PDF document

Apps\PDF\mupdf\1.20.0>output.pdf
  1. Do it with a graphics scalpel tool like inkscape.
1
  • I did it with inkscape!
    – user319249
    Commented Nov 17, 2023 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.