Change PDF Viewer Preferences in C++

Use PdfContentEditor for this task. The examples below retain the original C++ code and API Reference steps.

Change viewer preferences

Read the existing viewer-preference flags and set the additional bit represented by 1.

  1. Create PdfContentEditor.
  2. Bind the PDF input with Facade::BindPdf().
  3. Set the viewer flags with PdfContentEditor::ChangeViewerPreference().
  4. Read the viewer flags with PdfContentEditor::GetViewerPreference().
  5. Save the resulting PDF with PdfContentEditor::Save().
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <system/string.h>

namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void ChangeViewerPreferences(String inputFile, String outputFile)
{
    auto editor = MakeObject<PdfContentEditor>();

    editor->BindPdf(inputFile);
    editor->ChangeViewerPreference(editor->GetViewerPreference() | 1);
    editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor