0

I have some PDFs, that are intended for (in this case) laser cutting - so basically, their only contents are some vector lines/geometry, no raster/bitmap content, no text content.

Turns out, those PDFs have duplicate vectors - for instance, I'd have a rectangle with white background, - and then, an extra line for each of the lines of the rectangle outline.

So, basically, I need to get rid of the duplicate lines - and I'd prefer not importing this PDF in a vector application (Inkscape, LibreOffice Draw), because they will then surely add some other stuff in the PDF, and possibly change the page size etc.

So, I was wondering - is there a command line tool, that I could use to inspect the vector content of PDFs, as in this pseudocode:

$ some-pdf-tool --infile test.pdf --inspect-vectors
Opening "test.pdf" - 4 pages;
Page 1, size 100x30 mm:
- id:#1, line: 2 points [(0,0), (0,10)], outline color: #000000, thickness 1pt
- id:#2, line: 2 points [(0,10), (10,10)], outline color: #000000, thickness 1pt
- id:#3, line: 2 points [(10,10), (10,0)], outline color: #000000, thickness 1pt
- id:#4, line: 2 points [(10,0), (0,0)], outline color: #000000, thickness 1pt
- id:#5, polygon: 4 points [(0,0), (0,10), (10,10), (10,0)], outline color: #000000, thickness 1pt, fill: #FFFFFF

... and then possibly filter into a new PDF, as in this pseudocode:

$ some-pdf-tool --infile test.pdf --filter-vector-ids=1,2,3,4 --outfile test_out.pdf

... which would result with a test_out.pdf with only the "id:#5, polygon" shape present (and the other lines removed), and nothing else changed from the original input test.pdf?

  • 1
    First step would be to use something like mutool to decompress PDF streams, open the resulting file in a text editor and have a look at how the "vectors" are actually implemented (Postscript primitives? Something else?). Reading the PDF specification for that is recommended. Once you have that, you can think about extracting and working on your particular vectors, removing duplicates. There won't be a general tool, as there's no general encoding. It may be easier to get whatever produces the PDFs to produce something else. – dirkt Jan 15 at 8:13
  • Thanks @dirkt - especially for "There won't be a general tool, as there's no general encoding", was hoping otherwise - but its good to know this and keep this in mind. – sdaau Jan 15 at 8:18
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.