在PdfSharp中编写和阅读CustomValues花费的时间太长



我有一个c#方法,它为给定的pdf文件编写一个自定义值。为了编写pdf的自定义值,我使用的是PdfSharp 1.50.5147

这里的问题是PdfReader。打开等待pdf的时间太长:

https://www.mouser.com.tr/catalog/English/103/dload/pdf/mouser.pdf

public bool WritePropertyToFile(string filePath, string extension, string key, string value)
{
try
{
document = PdfReader.Open(filePath);  //Here it lasts 2.5 minutes !!
var properties = document.CustomValues.Elements;
properties.SetString("/" + key, value);
document.Save(filePath);
document = null;
return true;
}
catch (Exception)
{
if (document != null)
document = null;
throw;
}
}

我的要求是为给定的文件编写和读取以毫秒为单位的自定义值。尽管许多pdf文件的自定义值可以在毫秒内写入和读取,但像这样的一些文件可能会给我带来问题。

我需要打开整个文档来编写或读取自定义值吗?有不同的技术吗?你对这个问题有什么建议吗?

目前,由于PdfSharp首先在内存中加载整个pdf,因此没有方法在PdfSharp's中快速打开大型pdf。你试图打开的pdf文件是一个高达168MB的文件。

您可以扩展PdfSharp,并尝试先加载预告片内容,然后根据预告片条目读取每个内容块。

最新更新