Convert section of PDF?
Convert section of PDF?
I have a need to create a JPEG image from part of PDF file. I need to run this via a command line. It will be used in a script. I would like to know if this is possible with ImageMagick. I need the top of the page to be the width with a 16:9 ratio result. Is this possible in ImageMagick? Thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert section of PDF?
What is your IM version and platform? Please always provide that as syntax may differ.
I am not sure I understand your request. What do you mean by "I need the top of the page to be the width with a 16:9 ratio result"?
Can you explain further what part of the PDF file you want to make into a JPG image?
Is that 16:9 as width:height or height:width?
Do you mean take the top part of the PDF, such that your grab the full width and make the height=(9/16)*width?
A diagram might help! You can upload any diagram or your input PDF to some place such as dropbox.com and put the URL here.
I am not sure I understand your request. What do you mean by "I need the top of the page to be the width with a 16:9 ratio result"?
Can you explain further what part of the PDF file you want to make into a JPG image?
Is that 16:9 as width:height or height:width?
Do you mean take the top part of the PDF, such that your grab the full width and make the height=(9/16)*width?
A diagram might help! You can upload any diagram or your input PDF to some place such as dropbox.com and put the URL here.
Re: Convert section of PDF?
Hi, and thanks for the help. You have it correct... grab the full width and make the height=(9/16). I need to process and use as a an image programmatically in script.
http://pctechtv.com/extra/forum/imageMa ... dfArea.png
Thanks!
http://pctechtv.com/extra/forum/imageMa ... dfArea.png
Thanks!
Re: Convert section of PDF?
Sorry the version I am using is ImageMagick-7.0.3-3-Q16-x64, I am on Window 10 64bit.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Convert section of PDF?
If the 16:9 section you want starts at the top left of the page, this command should extract that from the first page of a PDF...pctechtv wrote:Hi, and thanks for the help. You have it correct... grab the full width and make the height=(9/16). I need to process and use as a an image programmatically in script.
Code: Select all
magick -density 300 mypdf.pdf[0] -crop %[w]x%[fx:w/16*9]+0+0 output.jpg
You may need to specify a background color and maybe flatten the image onto the background if the background is transparent in the original PDF. Put "-background white -flatten" after the input file name.
You can change the input size and resolution by changing that "-density" setting that comes before the input filename. You can change the output size by doing a "-resize" operation before the output filename.
If you're including the command in a BAT script on Windows you'll need to use double percent signs "%%" anywhere you use single ones on the command line.
Re: Convert section of PDF?
Thanks for the help. This community is great so fast to help. How should I be entering my file location I have entered with/without quotes and I keep getting something like this.
FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -... much longer saying no file found and other things. I am entering a full path like so "C:\CTestAC1\Pointer.pdf"
Thanks
FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -... much longer saying no file found and other things. I am entering a full path like so "C:\CTestAC1\Pointer.pdf"
Code: Select all
magick -density 300 "C:\CTestAC1\Pointer.pdf"[0] -crop %[w]x%[fx:w*0.5625]+0+0 "C:\CTestAC1\School1.pdf"
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert section of PDF?
You probably haven't installed Ghostscript.
snibgo's IM pages: im.snibgo.com
Re: Convert section of PDF?
That is exactly what the problem was. Thanks so much!You probably haven't installed Ghostscript.
Re: Convert section of PDF?
The code sample @GeeMack provided is really cool because it captures a 16:9 ratio no matter what the size of the pdf is. I now see that if my pdf is wider than 8.5 inches I want to scale it down. How could I make the output of the image scale to an 8.5 inch width but stay 16:9 after capture? Thanks
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert section of PDF?
Do you want to change the number of pixels so that the density (dots per inch) remain the same but the number of inches changes to 8.5?pctechtv wrote:How could I make the output of the image scale to an 8.5 inch width but stay 16:9 after capture?
Or do you simply want to change the density so the number of pixels stays the same but they span 8.5 inches?
snibgo's IM pages: im.snibgo.com
Re: Convert section of PDF?
Because I want to sometimes print the image (on 8.5 x 11) paper, I want to keep the whole page width in view. so I think that is the first option. I want to scale the page down evenly. Evenly to 8.5 width but still see everything. Actually, I may have confused things by saying, "after capture." It can happen within the capture command. If the original command also scales the size to 8.5 inch if would be great. Thanks
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert section of PDF?
At 300 dpi, the width 8.5 inches will be 300*8.5=2550 pixels. The height will be 8.5*9/16 inches, or 300*8.5*9/16=1434 pixels.
So add "-resize 2550x1434" after the crop. (I would also add "+repage" between the crop and the resize.)
So add "-resize 2550x1434" after the crop. (I would also add "+repage" between the crop and the resize.)
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Convert section of PDF?
You're using ImageMagick 7, so you have some really handy options for doing just that. If you want to resize to 8.5 inches wide using the current resolution you can do the calculation right in the resize operation, something like this...pctechtv wrote:If the original command also scales the size to 8.5 inch if would be great. Thanks
Code: Select all
magick -density 300 mypdf.pdf[0] ^
-crop %[w]x%[fx:w/16*9]+0+0 +repage -resize %[fx:resolution.x*8.5]x output.jpg
The "-density" setting before the input file name can be important when processing a PDF because it determines the quality of the rest of the processing and the output.
As snibgo mentioned, it's usually a good idea to put a "+repage" after your "-crop" operation.
Re: Convert section of PDF?
Wow thank you again @snibgo and @GeeMack super helpful. I have been able to do EXACTLY what I wanted to do. The other great part is your syntax examples are helping understand what everything is in the ImageMagick guides.
Re: Convert section of PDF?
I'm thinking there must be an option to leave off the last part with the output directory and tell ImageMagick just to create the jpeg in the original file's directory. If so how is this done? Thanks