Save PDF document programmatically

Use Document to persist changes to a PDF.

Save a PDF to a file

  1. Open the input PDF as a Document.
  2. Add an empty page with PageCollection::Add().
  3. 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

  1. Open the input PDF as a Document.
  2. Add an empty page with PageCollection::Add().
  3. Open a writable file stream with System::IO::File::OpenWrite().
  4. 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

  1. Open the input PDF as a Document.
  2. Create PdfFormatConversionOptions with PdfFormat::PDF_A_3U.
  3. Convert the document with Convert().
  4. 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);
}