views:

71

answers:

2

Hello, I am trying to superimpose two pdf pages; one on top of the other. I am using Cocoa and the PDFKit framework. When I superimpose the second page onto the first, the second page covers the content of the first page entirely (so the first page is no longer visible). Is there a way to change the transparency of the second page so that its background is fully transparent so that the page underneath it is visible?

Thanks.

EDIT: Here is my method. Create a subclass of PDFPage that holds an instance of another PDFPage and in the following method of the PDFPage class, draw the superimposed page.

- (void)drawWithBox:(PDFDisplayBox)box
{       
    [super drawWithBox:box];

    [overlayedPage drawWithBox:box];        
}
A: 

You might want to try rendering the PDF into a bitmap to be displayed in a Core Animation layer. Then you can set the transparency of the layers to whatever you need.

Tim Rupe
After looking at every method and class in PDFkit I still cannot find how to overlay PDF pages the way I want it so this is exactly the direction that I am heading now (unless some suggest another viable method). Thanks
David
+1  A: 

Your code may be fine.

It can be caused by the PDF itself if it does have a non-transparent (white) background.

I would first try to operate with 2 PDFs that have "known good" (transparent) backgrounds, like most PDFs have.

You can easily check enable Acrobat Reader to show transparent background as a non-white raster. Use the settings dialog to achieve this:
Adobe Reader showing page background is transparent
This page has a background that is transparent. However, the white box's background is... white.

If your page background is non-transparent and white, the Reader would display all the page background in white.

pipitas
Thanks. You are absolutely right. The background of the superimposed PDF is not transparent. I've converted the document to a bitmap and superimposed the document with some transparency. It is so so. To make it better, my next approach is to use the bitmap and remove the background altogether using a core image threshold filter.
David
@David: if this answer helped you to go forward, please upvote it.
pipitas