Page 1 of 1
Composite PDF with opaque backgrounds
Posted: 2016-11-13T14:05:31-07:00
by matejaputic
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?
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-13T15:27:25-07:00
by snibgo
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.
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-14T07:38:08-07:00
by matejaputic
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?
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-14T10:51:32-07:00
by fmw42
If the pdf has multiple pages, then try
Code: Select all
convert -density DD image.pdf -transparent white -background none -flatten image.png
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.
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-15T07:22:30-07:00
by matejaputic
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
Code: Select all
composite -gravity center a144-hegarty.pdf a144-hegarty-composite.pdf
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.
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-15T08:37:17-07:00
by snibgo
Calling your PDF "neural.pdf":
Code: Select all
convert neural.pdf -compose Darken -layers Merge d.png
Doesn't that do what you want?
Re: Composite PDF with opaque backgrounds
Posted: 2016-11-15T15:41:41-07:00
by matejaputic
That's it! Thank you so much!