Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. totalPages = (int)CGPDFDocumentGetNumberOfPages(PDFDocument);
  2.  
  3. NSLog(@"total pages %i",totalPages);
  4.  
  5. //struct CGPDFPage *page =CGPDFDocumentGetPage(PDFDocument, 1);
  6.  
  7. CGFloat width = 600.0;
  8.  
  9. // Get the page
  10. CGPDFPageRef myPageRef = CGPDFDocumentGetPage(PDFDocument, i);
  11.  
  12.  
  13. // Changed this line for the line above which is a generic line
  14. //CGPDFPageRef page = [self getPage:page_number];
  15.  
  16. CGRect pageRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFMediaBox);
  17.  
  18. CGFloat pdfScale = width/pageRect.size.width;
  19.  
  20. pageRect.size = CGSizeMake(pageRect.size.width*pdfScale, pageRect.size.height*pdfScale);
  21.  
  22. pageRect.origin = CGPointZero;
  23.  
  24.  
  25. UIGraphicsBeginImageContext(pageRect.size);
  26.  
  27. CGContextRef context = UIGraphicsGetCurrentContext();
  28.  
  29. // White BG
  30. CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
  31. CGContextFillRect(context,pageRect);
  32.  
  33. CGContextSaveGState(context);
  34.  
  35. // ***********
  36. // Next 3 lines makes the rotations so that the page look in the right direction
  37. // ***********
  38. CGContextTranslateCTM(context, 0.0, pageRect.size.height);
  39. CGContextScaleCTM(context, 1.0, -1.0);
  40. CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFMediaBox, pageRect, 0, true));
  41.  
  42. CGContextDrawPDFPage(context, myPageRef);
  43. CGContextRestoreGState(context);
  44.  
  45. imageView= UIGraphicsGetImageFromCurrentImageContext();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement