tavinus / pdfScale

Bash Script to Scale and Resize PDFs using Ghostscript
MIT License
242 stars 36 forks source link

Export-Import PDF Metadata - Geospatial data not written to output #42

Open twestley opened 1 year ago

twestley commented 1 year ago

I tried scaling a CalTopo PDF map with geospatial data. The scaling works; I like it.

But the output file was missing the geospatial data.

tavinus commented 1 year ago

Any examples? Maybe changing the mode could help. We depend on Ghostscript. If it is possible in GS, we can do it...

twestley commented 1 year ago

Thanks for responding. The attached script, scale.txt, generates a PDF file but fails to reproduce the spatial data in it. What am I doing wrong? (I'm using Avenza Maps on iPhone to determine whether I've got spatial data or not.)

scale.txt -i AmherstPeanut.pdf -o AmherstPeanut-scaled.pdf -s 0.9

AmherstPeanut.pdf scale.txt

tavinus commented 1 year ago

From this post, it seems like Ghostscript will never preserve metadata. https://unix.stackexchange.com/questions/50475/how-to-make-ghostscript-not-wipe-pdf-metadata

However, you can use exiftool or pdftk to copy the metadata from one pdf to another (needs to be tested). You will probably need to install them in your system though. There are examples on the link above. You could replace the whole gs call in the pdftk example with the pdfscale call if you want.

Maybe this could be added as an optional feature to pdfscale.

twestley commented 1 year ago

Thanks for looking at this. After trying qpdf, pdftk, pdfunite, and pdfjam, I discovered that qpdf works to overlay a legend pdf on a map pdf:

qpdf --overlay legend.pdf --repeat=1 -- map.pdf combined.pdf

The geospatial data is retained in combined.pdf above so problem solved.

tavinus commented 1 year ago

Pretty interesting. I may have a look into this when I have some time. Maybe we can automate this process within pdfScale (external tool install will be needed though).