-1
A
回答
0
void CreatePDFFile (CGRect pageRect, const char *filename)
{
// This code block sets up our PDF Context so that we can draw to it
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
// Create a CFString from the filename we provide to this method when we call it
path = CFStringCreateWithCString (NULL, filename,
kCFStringEncodingUTF8);
// Create a CFURL using the CFString we just defined
url = CFURLCreateWithFileSystemPath (NULL, path,
kCFURLPOSIXPathStyle, 0);
CFRelease (path);
// This dictionary contains extra options mostly for 'signing' the PDF
myDictionary = CFDictionaryCreateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
// Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
// Cleanup our mess
CFRelease(myDictionary);
CFRelease(url);
// Done creating our PDF Context, now it's time to draw to it
// Starts our first page
CGContextBeginPage (pdfContext, &pageRect);
// Draws a black rectangle around the page inset by 50 on all sides
CGContextStrokeRect(pdfContext, CGRectMake(50, 50, pageRect.size.width - 100, pageRect.size.height - 100));
// This code block will create an image that we then draw to the page
const char *picture = "Picture";
CGImageRef image;
CGDataProviderRef provider;
CFStringRef picturePath;
CFURLRef pictureURL;
picturePath = CFStringCreateWithCString (NULL, picture,
kCFStringEncodingUTF8);
pictureURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), picturePath, CFSTR("png"), NULL);
CFRelease(picturePath);
provider = CGDataProviderCreateWithURL (pictureURL);
CFRelease (pictureURL);
image = CGImageCreateWithPNGDataProvider (provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
CGContextDrawImage (pdfContext, CGRectMake(200, 200, 207, 385),image);
CGImageRelease (image);
// End image code
// Adding some text on top of the image we just added
CGContextSelectFont (pdfContext, "Helvetica", 16, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
const char *text = "Hello World!";
CGContextShowTextAtPoint (pdfContext, 260, 390, text, strlen(text));
// End text
// We are done drawing to this page, let's end it
// We could add as many pages as we wanted using CGContextBeginPage/CGContextEndPage
CGContextEndPage (pdfContext);
// We are done with our context now, so we release it
CGContextRelease (pdfContext);
相關問題
- 1. 如何以特定格式以編程方式創建PDF?
- 2. 以編程方式創建PDF相冊
- 3. 如何以編程方式從PDF文件創建PDF書籤?
- 4. 如何在iOS中以編程方式創建範圍滑塊?
- 5. 以編程方式創建searchview ios
- 6. 以編程方式創建iOS UIStackView
- 7. ios以編程方式創建視圖
- 8. 以編程方式創建NSObjects ios
- 9. iOS以編程方式創建視圖
- 10. 如何以編程方式在ios 11中打開pdf標記
- 11. 如何在iOS上以編程方式創建.txt文件
- 12. 如何以編程方式創建iOS應用程序視圖
- 13. 如何在iphone應用程序中以編程方式創建PDF文件?
- 14. 以編程方式在PDF文件中創建鏈接
- 15. 如何以編程方式創建UIButton
- 16. 如何以編程方式創建GPO?
- 17. 如何以編程方式創建JPEG
- 18. 如何以編程方式創建DrawerLayout
- 19. 如何以編程方式創建NSPopover
- 20. 如何以編程方式創建SplitView?
- 21. 如何以編程方式創建Tabbar
- 22. 如何以編程方式創建UIViewController?
- 23. 如何以編程方式創建UISplitViewController?
- 24. 如何以編程方式創建CustomCell?
- 25. 如何以編程方式創建UIScrollView?
- 26. 如何以編程方式創建dojox.mobile.TabBar?
- 27. 如何以編程方式創建ProgressBar?
- 28. 如何以編程方式創建UIScrollview
- 29. 如何以編程方式創建UICollectionViewCell
- 30. 如何以編程方式創建NSFetchedPropertyDescription?
編輯:下面是一個在iPhone項目中使用libHaru的GitHub的例子。 – 2013-05-04 21:27:20
如何在pdf中創建表格? – user2350731 2013-05-07 14:01:01
如何以編程方式在ios中創建(動態寫入數據)多頁面pdf? – user2350731 2013-05-09 04:21:26