Click or drag to resize

PdfSaveOptions Class

Represents a class that stores saving options for Adobe Portable Document Format (PDF) format.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentSaveOptions
    SautinSoft.DocumentPdfSaveOptions

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public sealed class PdfSaveOptions : SaveOptions

The PdfSaveOptions type exposes the following members.

Constructors
 NameDescription
Public methodCode examplePdfSaveOptions Initializes a new instance of the PdfSaveOptions class.
Top
Properties
 NameDescription
Public propertyAllowFontSubsetting Allow subsetting while embedding font into output PDF. Default value: true.
Public propertyClipboardTextProtection Gets and sets the protection on copying of all text from PDF document through clipboard.
Public propertyCode exampleCompliance Specifies the PDF standards compliance level for output documents. Default is PDF_15.
Public propertyCompression Allows to set compression to change size of the PDF document.
Public propertyContentType Gets the content-type for PDF file format: application/pdf.
(Overrides SaveOptionsContentType)
Public propertyCode exampleDigitalSignature Gets the digital signature options.
Public propertyEmbedAllFonts Embed all used fonts inside the PDF document. Default value: false.
Public propertyEmbeddedImageFormat Gets and sets the format to embed images in the saving document. Default value: Auto.
Public propertyEmbeddedJpegQuality Gets and sets the value value indicating Jpeg quality level. Affects only to the images which embedded in Jpeg format. Default value: 90.
Public propertyCode exampleEncryptionDetails Gets the encryption options.
Public propertyFacturXXML Gets and sets the stream of the XML file for Factur-x/Order-x.
Public propertyCode examplePageCount Gets or sets the number of pages to save.
Public propertyPageIndex Gets or sets the 0-based index of the first page to save. Default is 0.
Public propertyPaginatorOptions Gets or sets paginator options.
Public propertyPreserveContentControls Specifies whether to preserve Microsoft Word content controls as native PDF's form fields or convert them to text. Default is true.
Public propertyCode examplePreserveFormFields Specifies whether to preserve Microsoft Word form fields as native PDF's form fields or convert them to text. Default is true.
Public propertySelectedPages Gets or sets a custom page 0-based index set for save. Setting PageIndex or PageCount properties are overrides SelectedPages.
Public propertyUseCoreFonts Gets or sets a value determining whether or not to substitute TrueType fonts Arial, Times New Roman, Courier New and Symbol with core PDF Type 1 fonts. Default value: false.
Top
Example

See Developer Guide: How to save a document in PDF format

How to save a document in PDF format using C#
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {

        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            SaveToPdfFile();
            SaveToPdfStream();
        }

        /// <summary>
        /// Creates a new document and saves it as PDF file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-pdf-net-csharp-vb.php
        /// </remarks>
        static void SaveToPdfFile()
        {
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!\nFrom file.", new CharacterFormat() { FontColor = Color.Green, Size = 20});

            string filePath = @"Result-file.pdf";

            dc.Save(filePath, new PdfSaveOptions()
            {
                Compliance = PdfCompliance.PDF_A1a,
                PreserveFormFields = true
            });

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }

        /// <summary>
        /// Creates a new document and saves it as PDF/A using MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-pdf-net-csharp-vb.php
        /// </remarks>
        static void SaveToPdfStream()
        {
            // There variables are necessary only for demonstration purposes.
            byte[] fileData = null;
            string filePath = @"Result-stream.pdf";

            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!\nFrom MemoryStream.", new CharacterFormat() { FontColor = Color.Orange, Size = 20 });

            // Let's save our document to a MemoryStream.
            using (MemoryStream ms = new MemoryStream())
            {
                dc.Save(ms, new PdfSaveOptions()
                {
                    PageIndex = 0,
                    PageCount = 1,
                    Compliance = PdfCompliance.PDF_A1a
                });
                fileData = ms.ToArray();
            }
            File.WriteAllBytes(filePath, fileData);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });

        }
    }
}
How to save a document in PDF format using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        SaveToPdfFile()
        SaveToPdfStream()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Creates a new document and saves it as PDF file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-pdf-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToPdfFile()
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!" & vbLf & "From file.", New CharacterFormat() With {
            .FontColor = Color.Green,
            .Size = 20
        })

        Dim filePath As String = "Result-file.pdf"

        dc.Save(filePath, New PdfSaveOptions() With {
                .Compliance = PdfCompliance.PDF_A1a,
                .PreserveFormFields = True
            })

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub

    ''' <summary>
    ''' Creates a new document and saves it as PDF/A using MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-pdf-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToPdfStream()
        ' There variables are necessary only for demonstration purposes.
        Dim fileData() As Byte = Nothing
        Dim filePath As String = "Result-stream.pdf"

        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!" & vbLf & "From MemoryStream.", New CharacterFormat() With {
            .FontColor = Color.Orange,
            .Size = 20
        })

        ' Let's save our document to a MemoryStream.
        Using ms As New MemoryStream()
            dc.Save(ms, New PdfSaveOptions() With {
                .PageIndex = 0,
                .PageCount = 1,
                .Compliance = PdfCompliance.PDF_A1a
            })
            fileData = ms.ToArray()
        End Using
        File.WriteAllBytes(filePath, fileData)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})

    End Sub
End Module
See Also