Note that there are some explanatory texts on larger screens.

plurals
  1. PORotating PDF document, shrinks after a while
    text
    copied!<p>I have a problem in rotating the PDF document. I am able to rotate the document, but after some rotations the document is diminishing its dimensions. I can't find what's wrong. Here's my code:</p> <pre><code>//////// Creating document and pdfContext related code ////// -(IBAction)rotate { BOOL ok = [self CopyFileIfNotExists:@"Untitled.pdf"]; fileLoc = [self PathForFile:@"Untitled.pdf"]; angle = angle + 90; pdfDoc = [self MyGetPDFDocumentRef:[fileLoc UTF8String]]; CGPDFPageRef page = CGPDFDocumentGetPage (pdfDoc, 1); //CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); CGRect pageRect = CGRectMake(0, 0, 612, 792); [self MyCreatePDFFile:pageRect :[fileLoc UTF8String]]; } -(void) MyCreatePDFFile :(CGRect)pageRect :(const char *)filename { CFStringRef path; CFURLRef url; CFMutableDictionaryRef myDictionary = NULL; path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8); url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0); CFRelease (path); myDictionary = CFDictionaryCreateMutable(NULL, 0, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File")); CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name")); pdfContext = CGPDFContextCreateWithURL (url, &amp;pageRect, myDictionary); CFRelease(myDictionary); CFRelease(url); CGContextBeginPage (pdfContext, &amp;pageRect); [self myDrawContent:pdfContext]; CGContextEndPage (pdfContext); CGContextRelease (pdfContext); } -(void)myDrawContent:(CGContextRef )context { int noOfPages = CGPDFDocumentGetNumberOfPages(pdfDoc); CGRect pageRect = CGRectMake(0, 0, 612, 792); for( int i = 1 ; i &lt;= noOfPages ; i++ ) { CGPDFPageRef page = CGPDFDocumentGetPage (pdfDoc, i); //pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); //[self MyDisplayPDFPage:pdfContext :i :[fileLoc UTF8String]]; [self MyDrawPDFPageInRect:pdfContext :page :kCGPDFMediaBox :pageRect :angle :true]; } } -(void) MyDrawPDFPageInRect:(CGContextRef)context :(CGPDFPageRef)page :(CGPDFBox)box :(CGRect)rect :(int)rotation :(bool)preserveAspectRatio { //////// this is rotating code of PDF /// CGAffineTransform m; m = CGPDFPageGetDrawingTransform (page, box, rect, rotation, preserveAspectRatio); CGContextSaveGState (context); CGContextConcatCTM (context, m); CGRect pageframe = CGPDFPageGetBoxRect (page, box); CGContextClipToRect (context,pageframe); CGContextDrawPDFPage (context, page); CGContextRestoreGState (context); } -(CGPDFDocumentRef) MyGetPDFDocumentRef: (const char *)filename { CFStringRef path; CFURLRef url; CGPDFDocumentRef document; path = CFStringCreateWithCString (NULL, filename,kCFStringEncodingUTF8); url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0); CFRelease (path); document = CGPDFDocumentCreateWithURL (url); CFRelease(url); int count = CGPDFDocumentGetNumberOfPages (document); if (count == 0) { printf("`%s' needs at least one page!", filename); return NULL; } return document; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload