tavinus / pdfScale

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

Feature - Any way to show the GhostScript parameters/command-line being used? #7

Closed BryanEllis closed 6 years ago

BryanEllis commented 6 years ago

It would be nice to see the GhostScript command being used. I develop in many ways one being the use of a .Net Wrapper for GhostScript. If I had the command line I could then translate it into the calls for the .Net Wrapper enabling me to match the functionality in my application.

tavinus commented 6 years ago

Hi!
I am not really sure why you would want the GS call. I mean, if you are scripting around it you should probably just use the call itself and you will need to process parameters yourself anyways.

Besides, there are only 2 GS calls in the script, one for resizing and one for scaling. And since it is FLOSS you can just get from the source.

These are the two functions that run ONLY the GS calls: (anything that starts with a $ is a variable that was pre-defined)

# Runs GS call for scaling, nothing else should run here
gsPageScale() {
        # Scale page
        gs \
-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
-dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dSubsetFonts=true -dEmbedAllFonts=true \
-dDEVICEWIDTHPOINTS=$PGWIDTH -dDEVICEHEIGHTPOINTS=$PGHEIGHT \
-sOutputFile="$OUTFILEPDF" \
-c "<</BeginPage{$SCALE $SCALE scale $XTRANS $YTRANS translate}>> setpagedevice" \
-f "$INFILEPDF" 
}
# Runs GS call for resizing, nothing else should run here
gsPageResize() {
        # Change page size
        gs \
-q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
-dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dSubsetFonts=true -dEmbedAllFonts=true \
-dDEVICEWIDTHPOINTS=$RESIZE_WIDTH -dDEVICEHEIGHTPOINTS=$RESIZE_HEIGHT \
-dAutoRotatePages=$AUTO_ROTATION \
-dFIXEDMEDIA -dPDFFitPage \
-sOutputFile="$OUTFILEPDF" \
-f "$INFILEPDF" 
}

You said .Net but is that on Windows?
And you would run bash there through what exactly?
Also, what ghostscript are you using? Unix or Windows?

Here are some links about discussions on how we got to these GS calls:

Maybe I didn't understand exactly what you want, let me know.
If you still want that, I may be able to create two similar functions, say gsPrintPageResize() and gsPrintPageScale() and then use a flag to call them instead of the original ones (bypassing execution).

I still think this may add weird complexity to pdfScale though, so I will think a bit about it.
For example, if you are going to process the GS output we should probably make sure I don't print anything else, except on some errors. Then we have to document that and all.

I may find some time to make changes to pdfScale soon and then I will readress this.
Cheers!
Gus

tavinus commented 6 years ago

Hi!
I have created a new version (v2.2.1) that can simulate/dry-run and also print the Ghostscript call.

The release notes also have examples on the new options, which are replicated below:


v2.2.1 - Simulacron

New options to simulate / generate GS call

--dry-run


Please let me know if this fixes your problem.

Cheers!
Gus

BryanEllis commented 6 years ago

20731 - BRINGING IN THE SHEAVES.pdf 20731 - BRINGING IN THE SHEAVES - VERSE 1.pdf

I am working on Windows 10 but using the new Linux sub-environment with Bash I am able to run your PDFScale without problems. I use the GhostScript library which simply wraps the internals of GhostScript so they can be called in-process from .NET but basically you pass the various command-line parameters as arguments to the method calls on the library. Due to this, I am hoping once I get the command-line working to convert the PDF files, I can simply call the library with the same parameters to handle the files in an automated fashion. Since I have not used Bash or Bash scripting previously I was a bit lazy in trying to decipher the source code to find the GhostScript calls. I appreciate your help and the new version. I will let you know how it goes once I try it. I have attached one of the offending PDF files. I have 850 of these so far and the list is growing. At any time there may be corrections to any given file which would necessitate a rescale/resize to get an 8.5x11 format from the 6x9 format that is in the file. I have thousands of PDFs like the second one I attached (VERSE 1) which I simply convert to bitonal PNG files for use in creating PowerPoint slide shows to display during a worship service. I use GhostScript to do this conversion but figuring out how was much simpler than the task of rescaling/resizing the other files. Thank you for all you have done with PDFScale!!!!

BryanEllis commented 6 years ago

This works great!!!! I am so thankful to have found PDFScale!

tavinus commented 6 years ago

Thanks for the feedback!
Seems like you need a little script to run pdfScale on all those files.
A simple for loop on ls should sufice.

Glad this can be usefull.

Cheers!
Gus

tavinus commented 6 years ago

Not sure if you are using the calls and all, but there was a late update that corrected the printing of the resize call (was printing scale). Please just update to the latest version if you haven't already.