我看到aspose PDF for c++介绍中有包含PDF合并和拆分的功能。但是在文档和示例中都没有找到相关的描述,可以给我一些相关的资料参考吗
2 Likes
为了使用 Aspose.PDF for C++ 合并 PDF 文档,请使用以下代码示例:
// Open first document
auto doc1 = MakeObject<Document>(u"file1.pdf");
// Open second document
auto doc2 = MakeObject<Document>(u"file2.pdf");
// Add pages of second document to the first
doc1->get_Pages()->Add(doc2->get_Pages());
// Save concatenated output file
doc1->Save(u"merged-pdf.pdf");
此外,以下代码可用于拆分 PDF 文件:
// Load PDF file
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf");
// Page counter
int pageCount = 1;
// Loop through all the pages
for (auto page : pdfDocument->get_Pages())
{
// Create new document
auto newDoc = MakeObject<Document>();
// Add page to the document
newDoc->get_Pages()->Add(page);
// Save as PDF
newDoc->Save(u"OutputDirectory\\Sample_Page_" + System::Convert::ToString(pageCount) + u"_out.pdf");
pageCount++;
}