8
A
回答
3
我的理解是,你會創建一個CGPDFContext,繪製你的UIImage,並保存到一個文件。不過,我自己並沒有這樣做。
15
你好,我發現這個工程, 希望它有幫助!
-(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();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];
// 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);
}
+0
似乎是一個很好的概念,但繪製了一個空白的PDF文件? 「aView」drawRect需要什麼? – WrightsCS 2010-12-17 02:44:45
+1
完全它的工作....比q sooooooooo多streeter amduser440071 – 2011-12-06 05:11:48
0
我也收到了一個空白pdf。儘管現在工作了。嘗試改變:
//[aView drawRect:aView.bounds]; // <- This
[aView.layer renderInContext:UIGraphicsGetCurrentContext()]; // <- To This
-1
可以啓動一個PDF圖形上下文,然後繪製的圖像到它,使用:
[UIImage drawInRect: someRect];
您可以看到文檔,他們給生成的一個很好的解釋PDF格式。 pdf生成有一個很好的教程here。
相關問題
- 1. 如何將UIImage轉換爲xcode中的PDF文件?
- 2. 將html文件轉換爲PDF文件?
- 3. 將.jrxml文件轉換爲.pdf文件
- 4. 將pdf文件轉換爲word文檔
- 5. 將文本文件轉換爲pdf
- 6. 查看PDF文件在UIImage或UIScroller中轉換爲BLOB圖像
- 7. 將文本轉換爲PDF
- 8. 將pdf轉換爲文本
- 9. 將文檔轉換爲pdf
- 10. 將xml文件轉換爲pdf c#
- 11. 將HTML文件轉換爲PDF
- 12. 將pdf轉換爲word doc文件
- 13. PHP:將html文件轉換爲pdf
- 14. 如何將gp4文件轉換爲pdf
- 15. codeigniter將excel文件轉換爲pdf
- 16. 如何將.CATDrawing文件轉換爲.pdf
- 17. 將可打印文件轉換爲PDF
- 18. 將C#錶轉換爲PDF文件
- 19. 將給定的文件轉換爲PDF
- 20. 將jpeg圖片轉換爲pdf文件
- 21. 將android佈局轉換爲PDF文件
- 22. 可能將HTM文件轉換爲PDF
- 23. 將doc文件轉換爲PDF
- 24. pdfbox將圖像轉換爲pdf文件
- 25. 將單個doc文件轉換爲pdf
- 26. getBlob()正在將文件轉換爲pdf
- 27. 將pdf文件轉換爲單個jpeg?
- 28. 將dwg文件轉換爲pdf
- 29. 將HTML轉換爲PDF文件
- 30. 使用java將文件轉換爲PDF
爲什麼?雖然有可能,但PDF已針對存儲文檔和矢量圖形進行了優化,而UIImage是一個位圖... – kennytm 2010-03-15 14:16:35