Save PDF document programmatically
Contents
[
Hide
]
Use Document to persist changes to a PDF.
Save a PDF to a file
- Open the input PDF as a Document.
- Add an empty page with PageCollection::Add().
- Save the modified document to the output path with Document::Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
using namespace System;
using namespace Aspose::Pdf;
void SaveDocument(String path_infile, String path_outfile)
{
auto document = MakeObject<Document>(path_infile);
document->get_Pages()->Add();
document->Save(path_outfile);
}
Save a PDF to a stream
- Open the input PDF as a Document.
- Add an empty page with PageCollection::Add().
- Open a writable file stream with System::IO::File::OpenWrite().
- Pass the stream to Document::Save().
#include <system/io/file.h>
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
using namespace System;
using namespace Aspose::Pdf;
void SaveDocumentStream(String path_infile, String path_outfile)
{
auto document = MakeObject<Document>(path_infile);
document->get_Pages()->Add();
auto fileStream = System::IO::File::OpenWrite(path_outfile);
document->Save(fileStream);
}
Convert and save as PDF/A-3u
- Open the input PDF as a Document.
- Create PdfFormatConversionOptions with PdfFormat::PDF_A_3U.
- Convert the document with Convert().
- Save the result with Document::Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/IO/ConvertStrategies/PdfFormat.h>
#include <Aspose.PDF.Cpp/PdfFormatConversionOptions.h>
using namespace System;
using namespace Aspose::Pdf;
void SaveDocumentAsPdfA(String path_infile, String path_outfile)
{
auto document = MakeObject<Document>(path_infile);
auto options = MakeObject<PdfFormatConversionOptions>(Aspose::Pdf::PdfFormat::PDF_A_3U);
document->Convert(options);
document->Save(path_outfile);
}