【问题标题】:Is it possible to create a pdf with different page sizes in iOS - Objective C?是否可以在 iOS - Objective C 中创建具有不同页面大小的 pdf?
【发布时间】:2016-01-05 23:55:45
【问题描述】:

我已经多次完成所有页面大小相同的 pdf。真的可以在 iOS 上制作混合尺寸的 PDF 吗? (例如固定宽度和多高度页面)

我发现周围有很多不一致的答案,而关于特定平台功能的数据很少。

【问题讨论】:

  • UIGraphicsBeginPDFPageWithInfoCGPDFContextBeginPage
  • 你应该发布一个实际的答案。如果可以帮助其他人,可以回答您自己的问题。 cmets 中的代码不可读。
  • 对不起,我贴错了:-)
  • 不,将其发布为答案。不要把答案放在问题中。

标签: ios objective-c pdf core-graphics


【解决方案1】:

这就像用不同的媒体框添加每个页面一样简单。

// Start PDF file
NSMutableData *pdfFile = [[NSMutableData alloc] init];
CGDataConsumerRef pdfConsumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)pdfFile);

CGRect mediaBox = CGRectMake(0, 0, pageSize.width, pageSize.height);
    CGContextRef pdfContext = CGPDFContextCreate(pdfConsumer, &mediaBox, NULL);

CGContextBeginPage(pdfContext, &mediaBox);

CGContextDrawImage(pdfContext, imageBox, [image CGImage]);
CGContextEndPage(pdfContext);

// Change mediabox

CGContextBeginPage(pdfContext, &mediaBox);
... etc....
CGContextEndPage(pdfContext);

// Close pdf

CGContextRelease(pdfContext);
CGDataConsumerRelease(pdfConsumer);

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 2013-05-01
    • 1970-01-01
    • 2013-04-29
    相关资源
    最近更新 更多