【发布时间】:2014-02-04 19:55:10
【问题描述】:
这个问题之前已经发布过(Creating PDF from UIScrollView in iphone app),我使用的代码来自here。
这里是代码
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, 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];
documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
}
设置:我有一个 UIScrollView,里面是一个 UIView。我想保存整个 UIView(950,500px),它位于(520,500)的空间(UIScrollView 大小)中。生成的PDF只有UIScrollView的大小(520,500)
我阅读了answer,但他显然更改了代码,但它对我不起作用。我整天都在努力解决这个问题。
我是初学者,所以请指出我应该在我的问题中添加的任何我错过的内容。谢谢。
PS - 这是一个 iPad 应用程序。
【问题讨论】:
-
createPDFfromUIView:的第一个参数是内部的UIView还是UIScrollView?我认为应该是UIView,如果还不是这样的话。 -
@Taum 是的,我正在使用 UIView
标签: ios objective-c uiscrollview