Closed BryanEllis closed 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
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:
START
/ END
tagscaling
gs call)$ pdfscale ../pdfScale-linuxmagazin.pdf -s 1.05 --dry-run --print-gs-call
[GS SCALE CALL STARTS]
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sOutputFile="../pdfScale-linuxmagazin.SCALED.pdf" -c "<</BeginPage{1.05 1.05 scale -14.571108 -18.856728 translate}>> setpagedevice" -f "../pdfScale-linuxmagazin.pdf"
[GS SCALE CALL ENDS]
$ ./pdfScale.sh -v -v ../pdfScale-linuxmagazin.pdf -s 1.05 --hor-align left --vert-align top --xtrans -20 --ytrans 50 --dry-run --gs-call -r source
2018-04-01:10:43:28 | pdfScale.sh v2.2.1 - Verbose Execution
2018-04-01:10:43:28 | Mixed Tasks: Resize & Scale
2018-04-01:10:43:28 | Dry-Run: TRUE (Simulating)
2018-04-01:10:43:28 | Input File: ../pdfScale-linuxmagazin.pdf
2018-04-01:10:43:28 | Output File: ../pdfScale-linuxmagazin.SOURCE.SCALED.pdf
2018-04-01:10:43:28 | Get Page Size: Adaptive Enabled
2018-04-01:10:43:28 | Method: Grep
2018-04-01:10:43:28 | Source Width: 612 postscript-points
2018-04-01:10:43:28 | Source Height: 792 postscript-points
2018-04-01:10:43:28 | Auto Rotate: PageByPage
2018-04-01:10:43:28 | Flip Detect: No change needed
2018-04-01:10:43:29 | Run Resizing: SOURCE ( 612 x 792 ) pts
2018-04-01:10:43:29 | New Width: 612 postscript-points
2018-04-01:10:43:29 | New Height: 792 postscript-points
2018-04-01:10:43:29 | Scale Factor: 1.05
2018-04-01:10:43:29 | Vert-Align: TOP
2018-04-01:10:43:29 | Hor-Align: LEFT
2018-04-01:10:43:29 | Translation X: -20.00 = 0.00 + -20.00 (offset)
2018-04-01:10:43:29 | Translation Y: 12.29 = -37.71 + 50.00 (offset)
2018-04-01:10:43:29 | Run Scaling: 5 %
2018-04-01:10:43:29 | Final Status: Simulation completed successfully
[GS RESIZE CALL STARTS]
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sOutputFile="../pdfScale-linuxmagazin.SOURCE.SCALED.225177550_TEMP_2509725132.pdf" -c "<</BeginPage{1.05 1.05 scale translate}>> setpagedevice" -f "../pdfScale-linuxmagazin.pdf"
[GS RESIZE CALL ENDS]
[GS SCALE CALL STARTS]
"/usr/bin/gs" -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.5" -dPDFSETTINGS="/printer" -dColorImageResolution=300 -dGrayImageResolution=300 -dColorImageDownsampleType="/Bicubic" -dGrayImageDownsampleType="/Bicubic" -dColorConversionStrategy=/LeaveColorUnchanged -dSubsetFonts=true -dEmbedAllFonts=true -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sOutputFile="../pdfScale-linuxmagazin.SOURCE.SCALED.pdf" -c "<</BeginPage{1.05 1.05 scale -20 12.286544 translate}>> setpagedevice" -f "../pdfScale-linuxmagazin.SOURCE.SCALED.225177550_TEMP_2509725132.pdf"
[GS SCALE CALL ENDS]
Please let me know if this fixes your problem.
Cheers!
Gus
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!!!!
This works great!!!! I am so thankful to have found PDFScale!
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
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.
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.