I have a pdf that is made up of a bunch of scanned pages. I want to add page numbers that show up on each page.
First I tried using draw:
convert testin.pdf -draw 'text 100,100 "%p"' testout.pdf
but I would just get the literal "%p" I tried a few different combinations with no luck.
Finally I tried using annotate instead, and got further, but it still is not doing what I need. If I do this:
convert -pointsize 12 -annotate 0x0+10+20 "%p %f" testin.pdf testout.pdf
Then all of my pages say "1 testin.pdf" on them. So I am still not getting the correct page number on each page. So ImageMagick is loosing the page number of each page and just thinks that each page is number 1. (Perhaps it converts each page to a temporary file a single page long?)
Is there any way that I can add page numbers?
Thanks,
--Adam
Adding numbering to images fails
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding numbering to images fails
Unfortunately, I don't think IM will parse string formats like the %p directly into -draw. You need to store that in a shell variable. But I don't know that IM will know what page you have in the pdf. I don't work with them often.
For example try:
page=`convert testin.pdf -format "%p" info:`
convert testin.pdf -draw 'text 100,100 $page' testout.pdf
This might work in one step:
convert testin.pdf -draw 'text 100,100 $(convert testin.pdf -format "%p" info:) testout.pdf
Try it with %t rather than %p to see if it recognizes the top of the file name, if it does not work because IM cannot figure out the page number in the pdf.
Note however, that IM is not the best tool for pdf to pdf operations as it will convert the pdf to raster format and then back again, which may cause other quality issues or loss of pages or the like.
Get Adobe Acrobat. That should number pages fine.
For example try:
page=`convert testin.pdf -format "%p" info:`
convert testin.pdf -draw 'text 100,100 $page' testout.pdf
This might work in one step:
convert testin.pdf -draw 'text 100,100 $(convert testin.pdf -format "%p" info:) testout.pdf
Try it with %t rather than %p to see if it recognizes the top of the file name, if it does not work because IM cannot figure out the page number in the pdf.
Note however, that IM is not the best tool for pdf to pdf operations as it will convert the pdf to raster format and then back again, which may cause other quality issues or loss of pages or the like.
Get Adobe Acrobat. That should number pages fine.
Re: Adding numbering to images fails
No luck.
Both ways that you suggest give an error.
convert testin.pdf -draw 'text 100,100 $page' testout.pdf
convert: Non-conforming drawing primitive definition `page'.
convert testin.pdf -draw 'text 100,100 $(convert testin.pdf -format "%p" info:)' testout.pdf
convert: Non-conforming drawing primitive definition `('.
But, I don't see how they would work, because both seem to give just a whole list of page numbers, so wouldn't all the pages show up on each page?
%t with annotate does give the correct file name:
convert -pointsize 12 -annotate 0x0+10+20 "Adam %t" testin.pdf testout.pdf
I figured that IM would be fine for these, because they are already scans of pages anyway, so they are raster. And I just need to have some bulk numbering added to the pages.
Both ways that you suggest give an error.
convert testin.pdf -draw 'text 100,100 $page' testout.pdf
convert: Non-conforming drawing primitive definition `page'.
convert testin.pdf -draw 'text 100,100 $(convert testin.pdf -format "%p" info:)' testout.pdf
convert: Non-conforming drawing primitive definition `('.
But, I don't see how they would work, because both seem to give just a whole list of page numbers, so wouldn't all the pages show up on each page?
%t with annotate does give the correct file name:
convert -pointsize 12 -annotate 0x0+10+20 "Adam %t" testin.pdf testout.pdf
I figured that IM would be fine for these, because they are already scans of pages anyway, so they are raster. And I just need to have some bulk numbering added to the pages.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Adding numbering to images fails
If it works at all, you need to separate pages in your pdf, number them, then recombine again into a multipage format. I am not sure if image.pdf[index] will identify pdf pages or not. As it is now your command is accessing all pages and thus you are getting %p to identify all the pages in the pdf.
I have never seen any discussion of %p and what it does, nor do I understand how IM handles pdf pages. So I will defer to Anthony or anyone else with more knowledge than I on this topic.
I have never seen any discussion of %p and what it does, nor do I understand how IM handles pdf pages. So I will defer to Anthony or anyone else with more knowledge than I on this topic.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Adding numbering to images fails
First '%' escapes can not be used from -draw, as it interferes with -draw's use in handling SVG vector format images.
Use -annotate instead, which does do '%' escape substitutions.
Second are your wanting %p or are you wanting %s You can set the starting page number using -scene
Use -annotate instead, which does do '%' escape substitutions.
Second are your wanting %p or are you wanting %s You can set the starting page number using -scene
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/