tags:

views:

1092

answers:

1
+2  Q: 

Using PDF in iPad

Has Anyone tried using PDF in iPad Application, using CGPDf functions. I have used this in iPhone and it works perfectly , but when i use the same code in iPad , the Page are Shrunk in size, after a try outs i set the Scale as follows

CGContextScaleCTM(context,1.85, -1.80);

This time the it fits the screen perfectly , but that was just a trial and error , why does it not fit the screen as in iPhone, i have set the view size correctly too.

Anyone having a clue about it please let me know.

and also this is my drawRect method where i am drawing the PDF page

void drawRect:(CGRect)rect{

UIGraphicsBeginPDFPage();
CGContextRef context = UIGraphicsGetCurrentContext();
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 1.0, self.frame.size.height);
CGContextScaleCTM(context,1.0, -1.0);   
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);

}

alt text

Thanks

+4  A: 

You'll want to do something like

CGRect  box = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
CGFloat scale = bounds.size.width / box.size.width;
if (bounds.size.height / box.size.height < scale)
    scale = bounds.size.height / box.size.height;

to adapt to the PDF's size.

David Dunham
Thanks David that did work !Now it fit's perfectly , however i am facing another problem, i have my PDF Page view in a scrollview , so that i could zoom the PDF Page, but when i zoom in the scroll view the PDF Page view just get enlarged and text in PDF loose clarity. any way to overcome this?I tried calling setNeedsDisplay method on the View but getting messed up.Thanks
RVN
If it works, how about voting up the answer, so it's easier to spot that?You'll need to do some funky stuff. Basically, the default behavior is to scale up the pixels that would be drawn at 100% scale. So you'll need to draw them at the new scale, and reset the scroller to 100% so it draws them unscaled.
David Dunham
Voted up, and will try your idea, thanks for that.
RVN