ios- uiscrollview 中的 pdf 生成 [英] ios- pdf generation in uiscrollview
问题描述
在我的 ios 应用程序中,我在滚动视图中列出了一些数据.单击按钮时,页面中的数据将以 pdf 文件格式生成.以下是部分代码.
in my ios app i am listing out some data in scroll view. When a button is clicked the datas in the page are been generated in pdf file format. Following is the bit of code.
- (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];
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);
}
从上面的代码,我能够生成一个 pdf 文件,但我面临以下问题.如果我有 50 多个数据,在我的应用程序中,我只能看到前 10 个数据,而要查看其他数据,我需要滚动它们.在这种情况下,当生成 pdf 文件时,它只获取前 10 个数据而不是其他数据.其他数据如何获取
From the above code, i am able to generate a pdf file, but i am facing the following issue. If i have more than 50 data, in my app i am able to see only the first 10 data and to see the others i need to scroll them. In this case when the pdf file gets generated it is taking only the data of first 10 and not the others. How to get the other data too
推荐答案
renderInContext:
只会渲染你当前看到的 - UIScrollView 很智能,只会在你需要的层次结构中拥有正确的视图现在.您需要一个 for 循环来手动滚动和重绘.这可能很难正确,可能在滚动后手动调用 [aView layoutSubviews] 以强制 scrollView 立即重新排列子视图.
renderInContext:
will only render what you currently see - UIScrollView is smart and will only have the views in the hierarchy that you need right now. You need a for-loop to manually scroll and redraw. This might be tricky to get right, maybe call [aView layoutSubviews] manually after scrolling to force the scrollView to rearrange the subviews instantly.
这篇关于ios- uiscrollview 中的 pdf 生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!