在iphone应用程序中从UIScrollView创建PDF [英] Creating PDF from UIScrollView in iphone app
本文介绍了在iphone应用程序中从UIScrollView创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从UIView创建pdf到pdf它运行正常但我有 scrollView
我想要转换为pdf的内容但它只显示pdf中的可见部分而不是整个 scrollView
内容。这是我的代码
I am creating pdf from UIView to pdf it works fine but i have scrollView
with content which i want to convert to pdf but it only show visible part in pdf not the whole scrollView
content. here is my code
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
NSMutableData *pdfData = [NSMutableData data];
// Get Scrollview size
CGRect scrollSize = CGRectMake(1018,76,scrollView.contentSize.width,scrollView.contentSize.height);
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, scrollSize, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
推荐答案
这会给你可见的部分UIScrollView
THis gives you the visible portion of the UIScrollView
CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.bounds.size;
float theScale = 1.0 / scale;
visibleRect.origin.x *= theScale;
visibleRect.origin.y *= theScale;
visibleRect.size.width *= theScale;
visibleRect.size.height *= theScale;
所以你可以在 UIGraphicsBeginPDFContextToData中使用它(pdfData,aView.bounds,nil );
参数的一些细微变化。
so you can use this in UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
by some minor changes in the parameters.
这篇关于在iphone应用程序中从UIScrollView创建PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文