tavinus / pdfScale

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

Grep failed? #3

Closed mhulse closed 7 years ago

mhulse commented 7 years ago

Hi,

I love this tool! Thanks for creating it. 👍

Just noticing that on my macOS, Sierra, I get a failed message for grep:

$ pdfscale -v -v -r 'custom in 5.955 8.515' -f disable -s 1.1 foo.pdf
2017-07-03:23:34:54 | pdfscale v2.1.2 - Verbose Execution
2017-07-03:23:34:54 |    Mixed Tasks: Resize & Scale
2017-07-03:23:34:54 |     Input File: foo.pdf
2017-07-03:23:34:54 |    Output File: foo.CUSTOM.SCALED.pdf
2017-07-03:23:34:54 |  Get Page Size: Adaptive Enabled
2017-07-03:23:34:54 |         Method: Grep
2017-07-03:23:34:54 |                 Failed
2017-07-03:23:34:54 |         Method: Mac Quartz mdls
2017-07-03:23:34:54 |   Source Width: 612 postscript-points
2017-07-03:23:34:54 |  Source Height: 792 postscript-points
2017-07-03:23:34:54 |    Auto Rotate: PageByPage
2017-07-03:23:34:54 |    Flip Detect: Disabled
2017-07-03:23:34:54 |   Run Resizing: CUSTOM ( 429 x 613 ) pts
2017-07-03:23:35:13 |      New Width: 429 postscript-points
2017-07-03:23:35:13 |     New Height: 613 postscript-points
2017-07-03:23:35:13 |   Scale Factor: 1.1
2017-07-03:23:35:13 |  Translation X: -19.499766
2017-07-03:23:35:13 |  Translation Y: -27.863302
2017-07-03:23:35:13 |    Run Scaling: 10 %
2017-07-03:23:35:35 |   Final Status: File created successfully

Is that normal?

Thanks!

tavinus commented 7 years ago

Hi there!
Sorry for the late answer.

Yes, that is kind of normal. What happens is that some PDFs do not have a MediaBox definition on its main container. On those cases the GREP method for getting the original page size will fail.

As you can see, the grep method failed and then it tried mdls and succeeded.

That is the main reason I created the "adaptive method" for getting the page size. So, unless you are forcing a method of detection, you are using adaptive and it should failsafe to one of the other methods. On MacOS it will try to use mdls which reads the metadata from Spotlight and should always work (unless the file was just created and the system has not yet created the metadata for it).

In any case, if it says: Final Status: File created successfully, you should have no problems.

Cheers!
Gus

mhulse commented 7 years ago

Awesome! Great to hear. Thanks so much @tavinus, this code rocks! :octocat: