PDFPageView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // PDFPageView.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/16/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PDFPageView.h"
  9. @implementation PDFPageView
  10. // Only override drawRect: if you perform custom drawing.
  11. // An empty implementation adversely affects performance during animation.
  12. - (void)drawRect:(CGRect)rect {
  13. // Drawing code
  14. //CGPDFDocumentRef document = [self OpenPDF:@"GEIC - Home Improvement Contract 2016.pdf"];
  15. CGContextRef context = UIGraphicsGetCurrentContext();
  16. [self MyDisplayPDFPage:context index:self.pageIndex ];//file:@"GEIC - Home Improvement Contract 2016.pdf"];
  17. }
  18. -(void) MyDisplayPDFPage:(CGContextRef) myContext index:(size_t)pageNumber //file:(NSString*) filename//(, , const char *filename)
  19. {
  20. {
  21. CGPDFPageRef page = self.pageRef;
  22. CGContextSaveGState (myContext);
  23. CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
  24. // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
  25. // CGContextScaleCTM(myContext, 1, -1);
  26. CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.frame, 0, true);
  27. CGContextConcatCTM(myContext, pdfTransform);
  28. CGContextScaleCTM(myContext, 1, -1);
  29. CGContextTranslateCTM(myContext, 0, -self.frame.size.height/pdfTransform.a);
  30. CGContextDrawPDFPage (myContext, page);
  31. CGContextRestoreGState (myContext);
  32. }
  33. // CGPDFPageRef page = self.pageRef;
  34. //
  35. // CGContextSaveGState (myContext);
  36. //
  37. // CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
  38. //
  39. // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
  40. // // Reverse the Y axis to grow from bottom to top.
  41. // CGContextScaleCTM(myContext, 1, -1);
  42. //
  43. // CGContextDrawPDFPage (myContext, page);
  44. // CGContextRestoreGState (myContext);
  45. // return ;
  46. // {
  47. //
  48. // // CGPDFDocumentRef document;
  49. // CGPDFPageRef page = self.pageRef;
  50. //
  51. // CGContextSaveGState (myContext);
  52. //
  53. //
  54. // CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
  55. //
  56. // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
  57. // CGContextScaleCTM(myContext, 1, -1);
  58. //
  59. // CGContextDrawPDFPage (myContext, page);
  60. // CGContextRestoreGState (myContext);
  61. // }
  62. /*
  63. // CGPDFDocumentRef document;
  64. CGPDFPageRef page = self.pageRef;
  65. // document = [self OpenPDF:filename]; // 1 创建PDFDocument对象
  66. // page = CGPDFDocumentGetPage (document, pageNumber); // 2 获取指定页的PDF文档
  67. // CGAffineTransform m;
  68. // m = CGPDFPageGetDrawingTransform (page, kCGPDFMediaBox, self.bounds, -180, true);
  69. CGContextSaveGState (myContext);
  70. CGContextTranslateCTM(myContext, 80, self.frame.size.height);
  71. CGContextScaleCTM(myContext, 1, -1);
  72. // CGContextConcatCTM (myContext, m);
  73. // CGContextClipToRect (myContext,CGPDFPageGetBoxRect (page, kCGPDFCropBox));
  74. CGContextDrawPDFPage (myContext, page);
  75. CGContextRestoreGState (myContext);
  76. */
  77. // CGContextDrawPDFPage (myContext, page); // 3 将PDF绘制到图形上下文中
  78. // CGPDFDocumentRelease (document);
  79. }
  80. @end