Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PDF in iPad

Tags:

pdf

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 http://www.freeimagehosting.net/uploads/6b8bb69bb9.png

Thanks

like image 716
RVN Avatar asked Feb 27 '23 05:02

RVN


1 Answers

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.

like image 142
David Dunham Avatar answered Mar 11 '23 18:03

David Dunham