我有一个长的HTML页面,并希望将其转换为多页PDF文件。iOS - 从HTML内容创建多页PDF
对于给定的字符串内容,我遵循 apple和here - how to make multi page PDF中提供的说明。
但格式化NSString(有一些像数据)比创建一个HTML页面是困难的。我已经创建了这个html并在UIWebView中显示它。
现在我想创建一个PDF从这个HTML到多页 PDF文件。
我使用的代码可以创建单个PDF。
- (void)createPDFfromUIView:(UIWebView *)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); }
任何一个可以帮助吗?
Wehrung你是男人。我只是看了一下示例应用程序及其所需的全部内容。但是我的要求变了,做了其他的事情。但这真棒。我可能会在将来使用它。感谢您的努力和专门解释的事情。 – Viraj 2012-11-15 05:40:55
这个框架的问题是它不会捕获任何文本框中的任何数据。他们都将是空白的。 – GuybrushThreepwood 2013-08-29 11:17:57
它很棒!真棒人! – Rudi 2014-09-28 10:59:54