我有一個長的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