IacDocument.Open Method

The Open method opens a PDF, Postscript, XPS, or image format like TIFF, PNG or JPEG, files from any .NET stream. The Open method reads all the file contents into memory and closes the file right-away. The OpenEx method opens each page as it is requested, keeping the file handle open. OpenEx has the advantage of being more efficient but prevents other applications from writing to the file while it is being viewed.

 

Syntax

Visual Basic .NET:

Public Function Open(stream As System.IO.Stream, pwd As String) As Boolean

C#:

public bool Open(System.IO.Stream stream , string pwd)

 

Parameters

stream

.NET stream object containing the PDF or XPS document

pwd

Password to use if document is protected.

 

Return Value

Returns True if document opened successfully, False otherwise.

The exception Amyuni.PDFCreator.IacException.LicenseKeyError might be generated if the provided license is not valid or wrong.

 

Remarks

To check if a document is protected and ask the user for the password, you can use the following example.

 

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 stream

    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 stream

    fileRead.Close();

    fileWrite.Close();

 

    // terminate library to free resources

    acPDFCreatorLib.Terminate();

 

    // destroy objects

    doc.Dispose();

}