【发布时间】:2018-05-25 02:30:54
【问题描述】:
由于我是 Aspose 新手,因此在以下情况下我需要帮助。
我想使用 Aspose 将多个 PDF 合并为 1 个 PDF,我可以轻松完成,但问题是,我想将 PDF 大小限制为 200MB。
这意味着,如果我合并的 PDF 大小大于 200MB,那么我需要将 PDF 拆分为多个 PDF。 例如,如果我合并的 PDF 为 300MB,那么第一个 PDF 应为 200MB,并且第二个 PDF 应该是 100MB。
主要问题是,我无法在下面的代码中找到文档的大小。我正在使用下面的代码。
Document destinationPdfDocument = new Document();
Document sourcePdfDocument = new Document();
//Merge PDF one by one
for (int i = 0; i < filesFromDirectory.Count(); i++)
{
if (i == 0)
{
destinationPdfDocument = new Document(filesFromDirectory[i].FullName);
}
else
{
// Open second document
sourcePdfDocument = new Document(filesFromDirectory[i].FullName);
// Add pages of second document to the first
destinationPdfDocument.Pages.Add(sourcePdfDocument.Pages);
//** I need to check size of destinationPdfDocument over here to limit the size of resultant PDF**
}
}
// Encrypt PDF
destinationPdfDocument.Encrypt("userP", "ownerP", 0, CryptoAlgorithm.AESx128);
string finalPdfPath = Path.Combine(destinationSourceDirectory, destinatedPdfPath);
// Save concatenated output file
destinationPdfDocument.Save(finalPdfPath);
还可以根据大小合并 PDF 的其他方式。
提前致谢
【问题讨论】:
标签: c# pdf merge aspose aspose.pdf