使用 iTextSharp 或 iText 等庫,您可以通過 PdfReader 從 PDF 檔案中提取元資料:
using (var reader = new PdfReader(pdfBytes))
{
return reader.Metadata == null ? null : Encoding.UTF8.GetString(reader.Metadata);
}
這些型別的庫在能夠整理元資料之前完全決議 PDF 檔案。在我的情況下,這將導致系統資源的高使用率,因為我們每秒收到很多請求,并且帶有大型 PDF。
有沒有辦法從 PDF 中提取元資料而無需先將其完全加載到記憶體中?
uj5u.com熱心網友回復:
iText 5.x 也允許部分閱讀 PDF,只是看起來有點復雜。
代替
using (var reader = new PdfReader(pdfBytes))
用
using (var reader = new PdfReader(new RandomAccessFileOrArray(pdfBytes), null, true))
最后true要求部分閱讀。
uj5u.com熱心網友回復:
使用PDF4NET,您可以在不將整個檔案加載到記憶體中的情況下提取 XMP 元資料:
// This does a minimal parsing of the PDF file and loads
// only a few objects from the file
PDFFile pdfFile = new PDFFile(new MemoryStream(pdfBytes));
string xmpMetadata = pdfFile.ExtractXmpMetadata();
更新 1:代碼更改為從位元組陣列加載檔案
免責宣告:我為開發 PDF4NET 庫的公司作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/358584.html
上一篇:提取pdf矢量物件
