使用 Aspose.Net 保存 PDF 文件大小不断增大? - 我该如何防止这种情况发生?
我正在评估 Aspose.Net - 到目前为止它非常适合我的需求。 (ITextSharp、PDFOne、CLPrint、Adobe 和 ABCPdf (WebSupergoo) 不能满足我的需求 - 不是这个问题的重点,所以请不要回答“您尝试过 X 了吗?”)
我想从文件加载 PDF一次,然后循环,设置一些表单字段,然后保存。效果很好,除了我注意到文件大小不断增长。我认为这是由于表单字段造成的,但事实并非如此...请注意这个令人不安的代码和结果:
代码
static void Main(string[] args)
{
var form = new Aspose.Pdf.Facades.Form(@"c:\test.pdf");
for (int i = 0; i < 100; i++)
{
using (var tempStream = new MemoryStream())
{
form.DestStream = tempStream;
form.Save();
Console.WriteLine("Size: " + tempStream.Length);
}
}
}
令人不安的结果
你们中是否有人使用 Aspose 一次加载 PDF,然后多次保存,并以某种方式克服了文件大小不断增长的问题?
PS - 如果我每次都重新更新对象,文件大小会保持较低,但速度会较慢
I'm evaluating Aspose.Net - so far it's great for my needs. (ITextSharp, PDFOne, CLPrint, Adobe and ABCPdf (WebSupergoo) did not meet my needs - not the point of this question, so please don't answer with "have you tried X yet?")
I want to load a PDF from file once, then in a loop, set some form fields, then save it. Works great, except I noticed the file size constantly growing. I figured it was due to the form fields, but this isn't the case... notice this disturbing code and result:
The Code
static void Main(string[] args)
{
var form = new Aspose.Pdf.Facades.Form(@"c:\test.pdf");
for (int i = 0; i < 100; i++)
{
using (var tempStream = new MemoryStream())
{
form.DestStream = tempStream;
form.Save();
Console.WriteLine("Size: " + tempStream.Length);
}
}
}
The Disturbing Result
Have any of you used Aspose to load a PDF once, and then save it multiple times, and somehow overcame the growing file-size issue?
P.S. - If I re-new-up the object every time, the file size stays low, but that's slower
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
输出文件大小随着每次迭代而增加,因为您在评估模式下使用该组件。在评估模式下工作时,它会在 PDF 文件中添加评估水印。此外,在评估模式下,由于评估检查和水印等原因,组件也会慢一些。
请使用带有许可证文件的组件。如果您只是进行评估,那么您可以获得 30 天的临时许可证 测试应用程序而没有任何此类限制。
另外,请确保您使用的是最新版本的组件 - Aspose.Pdf for .NET 6.3.0。
如果您仍然发现任何其他疑问或问题,请与我们分享。
我还添加了我最后收到的带有许可证文件的输出的快照:
披露:我工作作为 Aspose 的开发人员传播者。
The output file size increases with each iteration because you're using the component in evaluation mode. When working in evaluation mode, it adds evaluation watermarks in the PDF file. Moreover, in evaluation mode, component is little slower too due to the evaluation checks and watermarks etc.
Please use the component with the license file. If you're just evaluating then you may get a temporary license for 30 days to test the application without any such limitations.
Also, please make sure that you're using the latest version of the component -- Aspose.Pdf for .NET 6.3.0.
If you still find any further questions or issues, please share with us.
I have also added a snapshot of the output received at my end with the license file:
Disclosure: I work as a developer evangelist at Aspose.