ghostscript.net可以将PDF文件划分为多个部分吗? [英] Can ghostscript.net divide a PDF file to multiple sections?

查看:131
本文介绍了ghostscript.net可以将PDF文件划分为多个部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常长的PDF文件(58x500英寸).目标是将一个大型矢量pdf文件划分为一定百分比.例如,%25 =高125英寸,而宽度保持不变.因此,一个大的pdf将分为4页.

I have a very long PDF file (58x500 inches). The goal is to divide one large vector pdf file to a certain percentage. For example %25 = 125 inches in height while the width stay the same. So one large pdf will be divided into 4 pages.

ImageMagick能够做到这一点,但是如果将dpi更改为300,它就会崩溃.是否可以使用Ghostscript做到这一点?我目前正在使用Ghostscipt.net和C#.

ImageMagick was able to do this but it crashes if I changed the dpi to 300. Is it possible to do this with Ghostscript? I am currenlty using Ghostscipt.net and C#.

有人可以指出我正确的方向吗?

Can someone point me to the right direction?

推荐答案

我提到了 netvips 在注释中-它会进行渐进式PDF渲染(它使用poppler而不是ghostscript),因此您可以以300 DPI加载整个页面并将其写为四个巨大的光栅文件.

I mentioned netvips in a comment -- it will do progressive PDF rendering (it uses poppler rather than ghostscript), so you can load the whole page at 300 DPI and write it out as four huge raster files.

我实际上在这台笔记本电脑上没有C#,但这就是您在Python中要做的事情. C#代码几乎相同.

I don't actually have C# on this laptop, but here's what you'd do in Python. The C# code would be almost the same.

import sys
import pyvips

image = pyvips.Image.image_new_from_file(sys.argv[1], dpi=300, access="sequential")
n_pages = 4

for n in range(n_pages):
    filename = f"page-{n}.tif"
    print(f"rendering {filename} ...")

    y = int(n * image.height / n_pages)
    page_height = int(min(image.height / n_pages, image.height - y))
    page = image.crop(0, y, image.width, page_height)
    page.write_to_file(filename)

access="sequential"将libvips置于顺序模式下-像素将仅根据最终写入操作的需要进行计算.您应该仅使用少量的内存就可以渲染200,000像素的高图像.

The access="sequential" puts libvips into sequential mode -- pixels will only be computed on demand from the final write operation. You should be able to render your 200,000 pixel high image using only a modest amount of memory.

您当然不需要使用tif,jpg可能会更明智,如果用于打印,很少有人会注意到.

You don't need to use tif of course, jpg might be more sensible, and if this is for printing, few people will notice.

每个人都说,最好将向量格式保留尽可能长的时间.

As everyone said, it would be better to keep as a vector format for as long as you can.

这篇关于ghostscript.net可以将PDF文件划分为多个部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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