IacDocument.Save Method

The Save method saves a PDF document to any .NET stream

 

Syntax

Visual Basic .NET:

Public Function Save(stream As System.IO.Stream, option AsAmyuni. PDFCreator.IacFileSaveOption) As Boolean
Public Function Save(stream As System.IO.Stream) As Boolean

C#:

public bool Save(System.IO.Stream stream, Amyuni.PDFCreator.IacFileSaveOption  option)
public bool Save(System.IO.Stream stream)

 

Parameters

stream

.NET stream object where the PDF document will be stored.

option

(Optional) Part of the document to save. The SaveOption is of type IacFileSaveOption which is defined as follows:

 

Option

Value

Description

acFileSaveAll

0

Save document data and view. This option should be only used with PDF created by Amyuni PDF Creator.

The document can be viewed with any PDF viewer and retains all design data.

acFileSaveView

1

Save only document view.

The document can be viewed with any PDF viewer including Amyuni PDF Creator but all design data such as database connection, OLE objects, is lost.

acFileSaveDesign

2

Save only document data.

The document can be opened, viewed and edited only with the Amyuni PDF Creator. It will show as blank pages in other viewers.

acFileSaveDefault

-1

Take the default Save option stored in the document object, i.e., one of the 3 options above.

acFileSavePDFA_7

3

[Obsolete]

acFileSavePDFA

4

Save document keeping the PDFALevel and PDFAConformance values from the original file. Otherwise, it will be marked as PDF/A-1b.  However, this flag doesn't adjust the other requirements to be valid PDF/A like Embedding Fonts, etc, only the PDFALevel value.

acFileSavePDF14

5

Save document PDF Specifications Version 1.4.

acFileSavePDFUA

 

6

Save the file with XMP metadata compatible with PDF/UA

 

 

Return Value

Returns Value True if the call succeeded and False otherwise. This method launches an exception if the document cannot be saved.

 

Remarks

When creating the output FileStream, it is important to use the option FileMode.Create as opposed to FileMode.OpenOrCreate will keep the original data in the PDF file, so if the new file is smaller than the original, stray characters remain by the end of the PDF file which can be flagged as invalid.

 

For acFileSavePDFUA needs to set the PDFALevel to 1 (PDFA-1). This is for future development and support for higher versions of PDF/UA. So the same level attribute is used for PDF/A and PDF/UA.

We still need to set the ViewerPreferences and DocumentLanguage for PDF/UA, these will not be created automatically:

doc.Attribute("ViewerPreferences").Value = "/DisplayDocTitle true"

doc.Attribute("DocumentLanguage").Value = "en"

doc.Attribute("FileSaveOption").Value = acFileSavePDFUA

 

Member of Amyuni.PDFCreator.IacDocument.

Example

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Creator .NET Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B"

 

    ' Initialize library

    ' This should be done once

    acPDFCreatorLib.Initialize()

 

    ' set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Create new stream object

    Dim fileRead As System.IO.Stream = System.IO.File.OpenRead("C:\temp\PDFDocument.pdf")

 

    ' Create a new PDF document

    Dim doc As New Amyuni.PDFCreator.IacDocument()

 

    ' Open PDF file

    Dim password As String = ""

    doc.Open(fileRead, password)

 

    ' Create new stream object

    Dim fileWrite As System.IO.Stream = System.IO.File.OpenWrite("C:\temp\CreatePDFDocument_resulting.pdf")

 

    ' Save PDF file

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView)

 

    ' Close the streams

    fileRead.Close()

    fileWrite.Close()

 

    ' terminate library to free resources

    acPDFCreatorLib.Terminate()

 

    ' destroy objects

    doc.Dispose()

End Sub

public void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Creator .NET Evaluation";

    const string strActivationCode = "07EFCDAB0100010025C3B7B351579FF94C49112EAF7368612744C7237C2F6A215A53E83A9ECCFFE54C52063CB05338BDE555773D7B1B";

 

    // Initialize library

    // This should be done once

    acPDFCreatorLib.Initialize();

 

    // set license key This is needed only with licensed version

    acPDFCreatorLib.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Create new stream object

    System.IO.FileStream fileRead = new System.IO.FileStream(@"C:\temp\PDFDocument.pdf",

            System.IO.FileMode.Open,

            System.IO.FileAccess.Read,

            System.IO.FileShare.Read);

 

    // Create a new PDF document

    Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument();

 

    // Open PDF file

    String password = "";

    doc.Open(fileRead, password);

 

    // Create new stream object

    System.IO.FileStream fileWrite = new System.IO.FileStream(@"C:\temp\CreatePDFDocument_resulting.pdf",

            System.IO.FileMode.Create,

            System.IO.FileAccess.Write,

            System.IO.FileShare.Read);

 

    // Save PDF File

    doc.Save(fileWrite, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);

 

    // Close the streams

    fileRead.Close();

    fileWrite.Close();

 

    // terminate library to free resources

    acPDFCreatorLib.Terminate();

 

    // destroy objects

    doc.Dispose();

}