使用带图像的c#代码生成时pdf文件的大小限制是多少? [英] What is the size limit of pdf file when generated using c# code with images?

查看:191
本文介绍了使用带图像的c#代码生成时pdf文件的大小限制是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web应用程序使用C#代码生成PDF文件。 PDF文件包含.tiff图像。如果包含图像的文件夹大小超过1GB,则浏览器会自动关闭。使用C#代码生成PDF文件的图像大小限制是什么?

I am using web application to generate PDF file using C# code. PDF file contains .tiff images. If size of a folder containing images goes beyond 1GB then browser gets closed automatically. What is the size limit of images to generate PDF file using C# code?

推荐答案

您的问题的答案取决于三个参数:

The answer to your question depends on three parameters:


  1. PDF版本:在PDF 1.5与PDF 1.5及更高版本之前,

  2. PDF样式:纯文本交叉引用表与交叉引用流,

  3. iText(夏普)版本:5.3之前5.3及更高版本。

让我们从PDF版本和交叉引用表开始。如果您不知道:交叉引用表定义PDF中每个对象的字节偏移量。

Let's start with the PDF version and the cross-reference table. In case you didn't know: the cross-reference table defines the byte offsets of every object inside the PDF.

在PDF 1.5之前的PDF版本中,交叉引用引用表以纯文本形式添加,每个字节偏移量使用十位数定义。因此,文件的大小将限制为10到第十个字节(大约10千兆字节)。

In PDF versions prior to PDF 1.5, the Cross-reference table is added in plain text, and each byte offset is defined using ten digits. Hence the size of a file will be limited to 10 to the tenth bytes (approximately 10 gigabytes).

版本低于PDF的PDF的最大大小PDF 1.5约为10千兆字节。

从PDF 1.5开始,您可以选择是否要以纯文本格式创建交叉引用表,或者是否您想使用交叉引用流。如果您使用交叉引用流,则仅10位数限制将消失。

Starting with PDF 1.5, you can choose whether you want to create a cross-reference table in plain text, or whether you want to use a cross-reference stream. If you use a cross-reference stream, the "10 digits only" limitation disappears.

使用版本PDF 1.5或更高版本的PDF的最大大小压缩的交叉引用流仅取决于处理PDF的软件的限制。

如果您使用iText(夏普),则需要确保如果您需要大于10千兆字节的文件,则使用压缩的交叉引用流创建文件。

If you use iText(Sharp), you need to make sure that you create your files with a compressed cross-reference stream if you need files bigger than 10 gigabytes.

iText的版本也很重要:

The version of iText also matters:


  • iText 5.3之前的所有版本仅支持最大约2千兆字节的文件,因为所有字节偏移都存储为 int 这些版本中的值。

  • 从5.3开始,iText支持最大1 TB的文件,因为所有字节偏移都存储为 long 值这些版本。

  • All versions prior to iText 5.3 only supported files up to about 2 gigabytes because all byte offsets are stored as int values in those versions.
  • From 5.3 on, iText supports files up to 1 terabyte because all byte offsets are stored as long values in those versions.

在5.3之前使用iText版本创建的PDF的最大大小为2千兆字节。使用iText版本5.3及更高版本创建的PDF的最大大小为1 TB。

但是:您还需要考虑并非所有观看者都可以渲染一个很大的文件。虽然该文件可能完全符合ISO-32000-1,但您可能会达到内存限制。

However: you also need to take into consideration that not all viewers can render a file that big. While the file may be completely compliant with ISO-32000-1, you may hit memory limits.

您通过互联网向随机PDF查看器插件发送1千兆字节随机机器上的随机浏览器。如果它是一台旧机器,它甚至不会有1千兆字节的内存。当最终用户连接速度较慢时,最终用户将不得不永远等待获取完整文件。您无法预测浏览器和PDF查看器的响应方式。我的猜测是浏览器由于内存不足异常而关闭。这不是由PDF固有的限制引起的问题,也不是iText(夏普)的限制引起的问题。这纯粹是您设计所固有的限制。您不应该向浏览器发送千兆字节。将它们写入云中的共享驱动器。

You are sending 1 gigabyte over the internet to a random PDF viewer plugin in a random browser on a random machine. If it's an old machine, it won't even have 1 gigabyte of memory. When the end user has a slow connection, the end user will have to wait forever to get the full file. There is no way you can predict how the browser and the PDF viewer will respond. My guess is that the browser shuts down because of an out-of-memory exception. This is not a problem that is caused by a limitation that is inherent to PDF, nor to a limitation of iText(Sharp). It is purely a limitation that is inherent to your design. You shouldn't send gigabytes to a browser. Write them to a shared drive in the cloud instead.

这篇关于使用带图像的c#代码生成时pdf文件的大小限制是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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