我從iPad應用程序中的UIView創建PDF。它的大小爲768 * 2000。當我創建pdf時,它會創建相同的大小,並在一個頁面上顯示所有內容。所以我在iPad上打印時遇到問題。我使用下面的代碼來創建PDF: -從UIView在iPad中創建pdf的問題應用程序
-(void)drawPdf:(UIView *)previewView{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Waypoint Data.pdf"];
//CGRect tempRect = CGRectMake(0, 0, 768, 1068);
CGContextRef pdfContext = [self createPDFContext:previewView.bounds path:(CFStringRef)writableDBPath];
CGContextBeginPage (pdfContext,nil); // 6
//turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0, previewView.bounds.size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);
//Draw view into PDF
[previewView.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);// 8
CGContextRelease (pdfContext);
}
//Create empty PDF context on iPhone for later randering in it
-(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path{
CGContextRef myOutContext = NULL;
CFURLRef url;
url = CFURLCreateWithFileSystemPath (NULL, // 1
path,
kCFURLPOSIXPathStyle,
false);
if (url != NULL) {
myOutContext = CGPDFContextCreateWithURL (url,// 2
&inMediaBox, NULL);
CFRelease(url);// 3
}
return myOutContext;// 4
}
任何人都可以建議我如何縮小pdf大小,它有多個頁面?
在此先感謝。
你發現瞭解決方案嗎? – 2012-04-08 17:17:22