I would like to create a composite of all pages in a PDF to use as a tool for determining crop margins for cutting out page numbers and headers, etc. So far this has been working well:
> composite -gravity center mydocument.pdf mydocument-composite.pdf
This works fine for PDFs with transparent backgrounds, but I'm having trouble with PDFs with opaque backgrounds. How can I process the PDF to remove or make white backgrounds transparent, and then create a composite of all the pages?
Composite PDF with opaque backgrounds
-
- Posts: 4
- Joined: 2016-11-13T14:01:23-07:00
- Authentication code: 1151
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Composite PDF with opaque backgrounds
What version IM are you using? On what platform?
I would use "convert", not "composite".
"-transparent White" will turn white pixels transparent. But I think you want to make one image that is black where any of the pages are black. "-compose Darken" will do that.
I would use "convert", not "composite".
"-transparent White" will turn white pixels transparent. But I think you want to make one image that is black where any of the pages are black. "-compose Darken" will do that.
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2016-11-13T14:01:23-07:00
- Authentication code: 1151
Re: Composite PDF with opaque backgrounds
I am using ImageMagick 6.9.5-4 Q16 x86_64 2016-07-30 on OSX 10.10.5
I apologize I wasn't clear, I need two things:
1. Convert a PDF with white backgrounds into a PDF (or PNGs or any other format) with transparent backgrounds
2. Composite the pages of the PDF with transparent backgrounds into one image or one PDF
I am converting the PDF to an e-reader format and I want to be able to see how large I need to set the crop margins so that the page numbers and headings on each page get cut out. Looking at the composite image makes this easy because it's like looking at all the pages in the PDF at once. I need help doing step 1. I have already tried
> convert -transparent White mydocument.pdf
which does not work. Does anyone have any ideas how to do this?
I apologize I wasn't clear, I need two things:
1. Convert a PDF with white backgrounds into a PDF (or PNGs or any other format) with transparent backgrounds
2. Composite the pages of the PDF with transparent backgrounds into one image or one PDF
I am converting the PDF to an e-reader format and I want to be able to see how large I need to set the crop margins so that the page numbers and headings on each page get cut out. Looking at the composite image makes this easy because it's like looking at all the pages in the PDF at once. I need help doing step 1. I have already tried
> convert -transparent White mydocument.pdf
which does not work. Does anyone have any ideas how to do this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Composite PDF with opaque backgrounds
If the pdf has multiple pages, then try
Where DD is the dpi you want to use to convert the vector pdf to raster data. Use 72 if you do not want to enlarge the output.
If the white is not pure white, then add -fuzz XX% before -transparent
But perhaps you should provide and example of your PDF, so we can experiment with it. You can post to some place such as dropbox.com and put the URL here.
Code: Select all
convert -density DD image.pdf -transparent white -background none -flatten image.png
If the white is not pure white, then add -fuzz XX% before -transparent
But perhaps you should provide and example of your PDF, so we can experiment with it. You can post to some place such as dropbox.com and put the URL here.
-
- Posts: 4
- Joined: 2016-11-13T14:01:23-07:00
- Authentication code: 1151
Re: Composite PDF with opaque backgrounds
Here is an example of a paper that I processed successfully
Original: http://cs.stanford.edu/~zdevito/a144-hegarty.pdf
Processed: https://app.box.com/s/wv7hnwf1fda78kq3hp46x5kxiakpnu2f
which was processed with
This is the output that I want. All of the pages are composited into one, and I can easily measure how large I have to set the crop margins so that the headers and footers from each page are removed.
Here is an example of a paper that did not work:
Original: https://pdfs.semanticscholar.org/82fd/a ... 0a4330.pdf
With the same command as above, the output looks like this:
Processed: https://app.box.com/s/8byjky1ovp7po3kblr9td1hqqon1oaez
I have also tried many variations of the commands suggested by fmw42 and snibgo (thank you) with no luck. I have tried including -transparent-color white, -transparent white, -background none, etc. Nothing seems to work.
Does the first document work but the second one doesn't because the first document does not have a background color?
Could it be that they are different PDF formats, e.g., one is native and the other might be images of pages?
I would appreciate your guidance, thanks.
Original: http://cs.stanford.edu/~zdevito/a144-hegarty.pdf
Processed: https://app.box.com/s/wv7hnwf1fda78kq3hp46x5kxiakpnu2f
which was processed with
Code: Select all
composite -gravity center a144-hegarty.pdf a144-hegarty-composite.pdf
Here is an example of a paper that did not work:
Original: https://pdfs.semanticscholar.org/82fd/a ... 0a4330.pdf
With the same command as above, the output looks like this:
Processed: https://app.box.com/s/8byjky1ovp7po3kblr9td1hqqon1oaez
I have also tried many variations of the commands suggested by fmw42 and snibgo (thank you) with no luck. I have tried including -transparent-color white, -transparent white, -background none, etc. Nothing seems to work.
Does the first document work but the second one doesn't because the first document does not have a background color?
Could it be that they are different PDF formats, e.g., one is native and the other might be images of pages?
I would appreciate your guidance, thanks.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Composite PDF with opaque backgrounds
Calling your PDF "neural.pdf":
Doesn't that do what you want?
Code: Select all
convert neural.pdf -compose Darken -layers Merge d.png
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2016-11-13T14:01:23-07:00
- Authentication code: 1151
Re: Composite PDF with opaque backgrounds
That's it! Thank you so much!