为什么将PDF页面与CGContextDrawPDFPage组合会创建非常大的输出文件? [英] Why does combining PDF pages with CGContextDrawPDFPage create very large output files?

查看:1108
本文介绍了为什么将PDF页面与CGContextDrawPDFPage组合会创建非常大的输出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这个尝试扔在一起一个简单的Automator脚本来组合几个一页PDF文件。我有88个文件要结合,每个刚好大约300KB,所以我预计最终产品是大约30MB;使用Combine PDFs Automator操作生成的PDF文件为300 + MB。

I ran into this trying to throw together a simple Automator script to combine several one-page PDF files. I had 88 files to combine, each just about exactly 300KB, so I expected the final product to be about 30MB; the resulting PDF file, using the Combine PDFs Automator action, was 300+MB.

自动化操作使用Python脚本与Foundation绑定来创建新的PDF文档与CoreGraphics PDF API。没有什么似乎不合适。基本上,它这样做(简化,但这些是高点):

Poking around, the Automator action uses a Python script, with Foundation bindings, to create the new PDF document with the CoreGraphics PDF APIs. Nothing seems out of place. Basically, it's doing this (simplified, but these are the high points):

writeContext = CGPDFContextCreateWithURL(outURL, None, None)
for url in inURLs:
    doc = CGPDFDocumentCreateWithURL(url)
    page = CGPDFDocumentGetPage(doc, 1)
    mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox)
    CGContextBeginPage(writeContext, mediaBox)
    CGContextDrawPDFPage(writeContext, page)
    CGContextEndPage(writeContext)
CGPDFContextClose(writeContext)

我不能想象CGContextDrawPDFPage在绘制到PDF上下文时,只会复制该页面的PDF数据(带有一些窗口)。

I can't imagine that CGContextDrawPDFPage, when drawing to a PDF context, would do anything but copy the PDF data for that page (with some window-dressing).

即使合并一个PDF,输出也是2.8MB,相比之下,300KB的原始单页PDF。

Even when "combining" just one PDF, the output is 2.8MB, compared to the 300KB original one-page PDF.

与原始页面完全相同的页面:文本可在相同位置选择,图形看起来相同,页面大小完全相同。

The resulting PDFs look exactly the same page-by-page as the original pages: text is selectable in the same places, graphics look identical, the pages are exactly the same size.

任何

推荐答案

输入PDF包含相同的字体集或不同的集合吗?也许如果原件不包含嵌入字体,但输出确实,这可能解释一些增长。

Do the input PDFs contain the same set of fonts, or different sets? Maybe if the originals don't contain embedded fonts, but the output does, that could account for some of the growth.

这篇关于为什么将PDF页面与CGContextDrawPDFPage组合会创建非常大的输出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆