RVN
RVN

Reputation: 4177

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

Thanks

Upvotes: 4

Views: 2805

Answers (2)

Ravi Chokshi
Ravi Chokshi

Reputation: 1166

if you have navigation bar enable , it will leave about 10px on both side.. it will aspect fit only if you will draw on whole area (768*1004)..

Upvotes: 0

David Dunham
David Dunham

Reputation: 8329

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.

Upvotes: 8

Related Questions