gpt4 book ai didi

iphone - 如何编写上下文来绘制多页 PDF?

转载 作者:行者123 更新时间:2023-12-03 21:24:44 25 4
gpt4 key购买 nike

我正在使用以下代码绘制 PDF:

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);
//CGContextSetLineCap(pdfContext, kCGLineCapButt);

// Done creating our PDF Context, now it's time to draw to it

CGContextBeginPage (pdfContext, &pageRect);

但是当调用开始页面方法时,它只绘制一个页面。我如何声明它可以绘制多个页面的正确上下文?

这是我到目前为止所拥有的:

-(void)createPDFFileWithRect: (CGRect) pageRect andFileName:(const char*)filename
{

// This code block sets up our PDF Context so that we can draw to it
CGPDFContextCreateWithURL(url,
((0, 0), (1000, 1000)), nil);
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);
//CGContextSetLineCap(pdfContext, kCGLineCapButt);

// Done creating our PDF Context, now it's time to draw to it

// Starts our first page
//for(int i =0;i<2;i++)
//{
CGContextBeginPage (pdfContext, &pageRect);

//CGContextRef pdfContext1;

//CGContextBeginPage (pdfContext, &pageRect);
//}
// Draws a black rectangle around the page inset by 50 on all sides
CGContextStrokeRect(pdfContext, CGRectMake(50, 50, 500,700));



CGContextShowTextAtPoint (pdfContext, 60, 699, 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);
// cpde to draw a new page
// CGContextBeginPage (pdfContext, &pageRect);
// We are done with our context now, so we release it
CGContextRelease (pdfContext);
}

最佳答案

抱歉,我对 PDF 的东西不太熟悉,所以这可能不是很有帮助。

我有一个小型的、尚未发布的、粗糙的 PDF 应用程序,我用它来绘图(稍微简化了一点):

CGPDFPageRef page = CGPDFDocumentGetPage(pdf, currentPage);
CGContextSaveGState(context);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, bounds, 0, true);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);

我在代码中的任何地方都没有看到 CGContextDrawPDFPage。我们是否使用两种不同的技术,您是否忘记包含部分代码或其他内容?

关于iphone - 如何编写上下文来绘制多页 PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1218873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com