draw on a specific pdf page

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
arno
Posts: 2
Joined: 2011-11-11T03:05:19-07:00
Authentication code: 8675308

draw on a specific pdf page

Post by arno »

I have a command like this:

Code: Select all

mogrify -density 300 -compress ZIP -fill none -stroke green -strokewidth 5 -draw 'rectangle 200,200 800,300' Page.com.pdf
With this it creates a nice rectangle. However, if my pdf has more then 1 page, it draws on all of them. If i specify a page number it deletes the rest of the pages.

Code: Select all

mogrify -density 300 -compress ZIP -fill none -stroke green -strokewidth 5 -draw 'rectangle 200,200 800,300' Page.com.pdf[0]
Is it possible to apply the changes to a specific page without deleting the rest?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: draw on a specific pdf page

Post by anthony »

First please note that Imagemagick is not designed for vector images like PDF!
It can do it, but you need a lot of care and understanding of what is going on to get acceptable results.

See A word about Vector Image formats
http://www.imagemagick.org/Usage/formats/#vector


Having said that. Yes you can!
You find can not use mogrify. But convert. You read in the PDF, extract the old page into parenthesis, modify it ans then replace the original page.

See Combining Image Sequence Operations
http://www.imagemagick.org/Usage/basics/#seq_combine
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
arno
Posts: 2
Joined: 2011-11-11T03:05:19-07:00
Authentication code: 8675308

Re: draw on a specific pdf page

Post by arno »

Thanks! I'm using scans, so the pdf is already araster image in a pdf. I almost got it working. Next problem appears. I tried both commands (the enters mine for readability. Original command doesn't have enters):

Code: Select all

convert -density 300 -compress ZIP file1.pdf  \( -clone 0 -fill none -strokewidth 9 -stroke blue -draw 'rectangle 1595,289 1876,342' 
																	 -stroke purple -draw 'rectangle 250,1188 1077,1266' 
																	 -stroke green -draw 'rectangle 399,1873 1946,1930' \)
	-swap 0 +delete  -append file2.pdf

Code: Select all

convert -density 300 -compress ZIP  file1.pdf  \( -clone 0 -fill none -strokewidth 9 -stroke blue -draw 'rectangle 1595,289 1876,342' 
																	 -stroke purple -draw 'rectangle 250,1188 1077,1266' 
																	 -stroke green -draw 'rectangle 399,1873 1946,1930' \)
	-delete 1 -insert 1 -append file2.pdf
The original has 2 pages, the result has got 1 long page. I'm using this with pdf and multiple-page tiff's. I tried '+repage' and '-page a4' but that doesn't seem to affect the result.


Edit - NVM, deleting -append wasn't that difficult.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: draw on a specific pdf page

Post by anthony »

Remove the append! That was just for the example for its results display.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply