我有一个c#方法,它为给定的pdf文件写一个自定义值。为了为pdf编写自定义值,我使用了PdfSharp 1.50.5147
这里的问题是PdfReader.Open等待pdf belove的时间太长了:
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文件的自定义值可以在毫秒内写入和读取,但其中一些文件可能会给我带来问题。
是否需要打开整个文档才能写入或读取自定义值?有没有不同的技术来解决这个问题?你对这个问题有什么建议吗?
发布于 2021-01-28 04:15:23
目前,由于PdfSharp首先将整个pdf加载到内存中,因此没有方法在PdfSharp中快速打开大型pdf。你试图打开的pdf是一个巨大的168MB文件。
您可以扩展PdfSharp并尝试先加载预告片内容,然后根据预告片条目读取每个内容块。
https://stackoverflow.com/questions/65547610
复制相似问题