Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created April 5, 2024 04:55
Merge Documents via C++ Applications

Merge Microsoft Word Documents, Excel Spreadsheets, Powerpoint Presentations and PDF Documents via C++ Application.

Aspose::Cells::Startup();
Workbook wkb(u"input.xlsx");
wkb.Combine(Workbook(u"Combine.xlsx"));
wkb.Save(u"Output.xlsx");
Aspose::Cells::Cleanup();
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Text;
String _dataDir("C:\\Samples\\");
String pdfDocumentFileName1("Concat1.pdf");
String pdfDocumentFileName2("Concat2.pdf");
String outputFileName("ConcatenatePdfFiles.pdf");
auto pdfDocument1 = MakeObject<Document>(_dataDir + pdfDocumentFileName1);
auto pdfDocument2 = MakeObject<Document>(_dataDir + pdfDocumentFileName2);
pdfDocument1->get_Pages()->Add(pdfDocument2->get_Pages());
pdfDocument1->Save(_dataDir+outputFileName);
auto pres1 = System::MakeObject<Presentation>(u"pres1.pptx");
auto pres2 = System::MakeObject<Presentation>(u"pres2.pptx");
for (const auto& slide : pres2->get_Slides())
{
pres1->get_Slides()->AddClone(slide);
//pres1->get_Slides()->AddClone(slide, pres2->get_Masters()->idx_get(0), true);
}
pres1->Save(u"combined.pptx", SaveFormat::Pptx);
using namespace Aspose::Words;
std::vector<String> fileNames { u"Input1.docx", u"Input2.docx" };
auto output = MakeObject<Document>();
output->RemoveAllChildren();
for (const auto& fileName : fileNames){
auto input = MakeObject<Document>(fileName);
output->AppendDocument(input, ImportFormatMode::KeepSourceFormatting);
}
output->Save(u"Output.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment