| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //
- // PDFPageView.m
- // AntsContract
- //
- // Created by Ray on 12/16/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "PDFPageView.h"
- @implementation PDFPageView
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
-
- //CGPDFDocumentRef document = [self OpenPDF:@"GEIC - Home Improvement Contract 2016.pdf"];
-
-
-
-
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- [self MyDisplayPDFPage:context index:self.pageIndex ];//file:@"GEIC - Home Improvement Contract 2016.pdf"];
- }
- -(void) MyDisplayPDFPage:(CGContextRef) myContext index:(size_t)pageNumber //file:(NSString*) filename//(, , const char *filename)
- {
-
- // double vwidth=self.frame.size.width;
- // double vheight = self.frame.size.height;
-
-
- {
- CGPDFPageRef page = self.pageRef;
- CGContextSaveGState (myContext);
-
- // CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
-
- // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
- // CGContextScaleCTM(myContext, 1, -1);
- // CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.frame, 0, true);
-
- CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
- double scalex = self.frame.size.width/mediabox.size.width;
- double scaley = self.frame.size.height/mediabox.size.height;
-
- double scale = scalex<scaley?scalex:scaley;
-
- CGAffineTransform translate_transform = CGAffineTransformMakeTranslation ( (self.frame.size.width-mediabox.size.width*scale)/2, 0 );
-
- CGAffineTransform scale_transform=CGAffineTransformScale ( translate_transform, scale, scale );
-
- CGContextConcatCTM(myContext, scale_transform);
-
- CGContextScaleCTM(myContext, 1, -1);
- CGContextTranslateCTM(myContext, 0, -self.frame.size.height/scale_transform.a);
-
- CGContextDrawPDFPage (myContext, page);
- CGContextRestoreGState (myContext);
- }
-
-
-
-
-
- // CGPDFPageRef page = self.pageRef;
- //
- // CGContextSaveGState (myContext);
- //
- // CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
- //
- // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
- // // Reverse the Y axis to grow from bottom to top.
- // CGContextScaleCTM(myContext, 1, -1);
- //
- // CGContextDrawPDFPage (myContext, page);
- // CGContextRestoreGState (myContext);
- // return ;
-
- // {
- //
- // // CGPDFDocumentRef document;
- // CGPDFPageRef page = self.pageRef;
- //
- // CGContextSaveGState (myContext);
- //
- //
- // CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
- //
- // CGContextTranslateCTM(myContext, 0, mediabox.size.height);
- // CGContextScaleCTM(myContext, 1, -1);
- //
- // CGContextDrawPDFPage (myContext, page);
- // CGContextRestoreGState (myContext);
- // }
-
-
-
-
-
- /*
- // CGPDFDocumentRef document;
- CGPDFPageRef page = self.pageRef;
- // document = [self OpenPDF:filename]; // 1 创建PDFDocument对象
- // page = CGPDFDocumentGetPage (document, pageNumber); // 2 获取指定页的PDF文档
-
-
- // CGAffineTransform m;
- // m = CGPDFPageGetDrawingTransform (page, kCGPDFMediaBox, self.bounds, -180, true);
- CGContextSaveGState (myContext);
-
- CGContextTranslateCTM(myContext, 80, self.frame.size.height);
- CGContextScaleCTM(myContext, 1, -1);
-
- // CGContextConcatCTM (myContext, m);
- // CGContextClipToRect (myContext,CGPDFPageGetBoxRect (page, kCGPDFCropBox));
- CGContextDrawPDFPage (myContext, page);
- CGContextRestoreGState (myContext);
- */
-
- // CGContextDrawPDFPage (myContext, page); // 3 将PDF绘制到图形上下文中
- // CGPDFDocumentRelease (document);
- }
- @end
|