Superimposing PDF pages - objective-c

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];
}

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:
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.

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.

Related

Smallest possible invisible PDF?

This question is related to What is the smallest possible valid PDF?, but goes one step further: I'd like a PDF file that is as small as possible, but also invisible.
That means:
it contains no text or other objects (or if that's not possible, only completely transparent ones), and
it has no background (or if that's not possible, a completely transparent background).
When I open this file in a compliant PDF viewer, the background color of the viewer panel should show through completely, and when I embed it in a document on top of other elements, only these other elements should show.
PDF pages have no background color by default (if you need an explicit background you have to draw a colored rectangle that covers the entire page).
PDF viewers will use a default white background to simulate a paper page, so the actual background depends on the PDF viewer.
When you place a PDF page on top of another one it will not block the underlying content if it does not have an explicit background.

live tiles in Windows Phone and Grids

I'm trying to create a live tile for my application, using a user control.
The user control contains a grid, an image and a rectangle filled with color.
Now here comes the funny part.
I want the rectangle to act as a background for the tile's title, and the image to fill the rest of the tile. And i said to myself, well, lets put some rows in that grid and set the like you usually set them in a WPF/SL application.
I then write the entire thing in a WBM and save it to isostore.
The problem is, the parser seems to ignore the presence of grid's rows. regardless of what I try, the rectangle is not shown, and the image covers the full tile, when it should only cover the first row. It is as if the grid didn't even existed.
Another funny aspect is that it doesn't matter if I use rows or columns, the result is the same.
Any ideas?
Are you using the following method?
Dynamic LiveTile - adding background image?
I recently implemented a Live Tile using a Grid with Rows and Columns for layout of some TextBlocks. I encountered similar challenges, so I placed the control that I was using for my Live Tile on a blank page in my app to better see what was happening. Does the control render correctly when displayed on a page (versus being rendered to a WriteableBitmap)?
Another idea. Instead of trying to position the Rectangle relative to the tile's Title, why not leave the Title property blank and put the same text in a TextBlock within the user control?
If you are careful about the font and positioning of the TextBlock, the text on the resulting background image can appear indistinguishable from text displayed from the Title property. I decided to follow this strategy myself. I found the font information in the following answer:
Font size and family for a tile's title
Otherwise, could you post an example of the XAML you are using?

PDF Highlighting above image / below text

i'm trying to highlight text in a pdf, and have the highlighted rectangle to be drawn under the text.
It works fine on most PDF's, but I jumped into a problem when the text I'm trying to highlight has an image/background under it. The problem is that the highlight rectangle is drawn under the image as well, so it is not visible.
The drawing order I have is this:
draw a blank rectangle with the page size
draw the highlight
draw the pdf using CGContextDrawPDFPage(context, page);
Is there a way to draw the PDF images and text separately? so that I could go
blank rectangle
pdf images/background
highlight
pdf text
Do I have to do something to the pdf / context so that it draws it automatically the way I want it to? I've tried messing with the context but nothing worked so far, it's all drawn entirely under or entirely above the full pdf
Every reader I've seen does this (PDFExpert, GoodReader, iAnnotate to name a few), so it can't be impossible, I just haven't found the solution yet :)
Any help will help, thanks in advance!!
Cheers
My understanding is that these other apps are reading and rendering the PDF themselves (they support selecting text, or adding annotations, for example), so they would be able to much more easily layer things in the way you're mentioning.
The CGPDFDocument you're starting with is an opaque object (in the OO sense, not transparency) that can draw itself, but I don't know of any way to break out and render various sublayers of the document.
As a way forward, you could look at using Core Image (iOS5+) or some other method to blend the highlights layer with the PDF. If you used the right filter (Multiply, maybe), the darker text would still come through and a .3 alpha highlight would blend with any background.

iOS page based application clear color issue

I'm trying to make a page based application in iOS where the actual page is a non-rectangular image (contains clear color). However, the shadow that appears when I turn the page doesn't seem to ignore the transparency of the image (see below).
Screenshot http://img543.imageshack.us/img543/9730/pagecurl.png
Does anyone know if it's possible to modify this behavior?
Thanks in advance.
Have you tried setting your UIPageViewController's view's frame so that it sits just within the border defined by your custom page image?
(So in your case, the largest rectangle that fits inside your white page image)
The way UIPageViewController handles a page curl animation with views that extend beyond its own view's frame can be thought of as follows:
Think of the overhang as rigid. it does not bend like the rest of the page, but it does maintain the angle at the edge of the UIPageViewController's frame. If the overhang (i.e. parts of your image or view that extend beyond the UIPageViewController's frame), is small, the fact that the overhang animates as rigid (instead of the bendy, flexible page) is visually negligible.
However, without any further modifications, the pages will only flip when a touch is started INSIDE the UIPageViewController's view's frame. But it would be better if it could react to touches anywhere on your white page image. If you want the pages to react to touches inside another view's frame (e.g. the view holding your white page image), try the following:
otherView.gestureRecognizers = myPageViewController.gestureRecognizers;
The problem is that the iOS framework puts a shadow over the entire bounds of the view controller you specify for the page, so any transparent areas will look shadowed. You could try masking your view controller (viewController.view.layer.mask and viewController.view.layer.masksToBounds) and see if that helps.
Hopefully Apple improves this framework for a future iOS release. It sure would be nice to disable that shadow or have a way to do it yourself but there you go.

Chaning the background color around a PDF in a UIWebView on Device

I'm using a webview to display a PDF.
The webview displays the PDF at it's actual size which is a little smaller than the size of the webvieww itself, revealing the scroll view underneath it.
I've tried setting the Webview to opaque and setting it's background color to another color, which works fine and dandy in the simulator, but fails to change the color on the device. On the device it changes the color of the background of the view behind the scroll view, this can be seen when the PDF is pulled all the way down.
I've also tried setting all the UIView's backgrounds, by iterating through the subviews but to no avail.
I've updated a diagram to help illustrate which area I'd like to color.
Uploaded Diagram
You really shouldn't mess around with UIWebView's internals.
They can change anytime and your code might just crash on the next version of iOS.
If you need more control about pdf display, you might wanna take a look at other possibilities to show pdf, like using the CGPDFDrawPage* functions. Of course they are pretty low-level and it's a lot of work required until you can get fast page display, zooming, etc all right.