IacDocument.Append Method

The Append method can be used to append or concatenate a PDF file to the current document.

 

Syntax

Visual Basic .NET:

Public Function Append(document As AmyuniPDFCreator.IacDocument) As Boolean

C#:

public bool Append(AmyuniPDFCreator.IacDocument document)

C++/CX:

public: bool Append(AmyuniPDFCreator.IacDocument^ document)

JavaScript:

Boolean append(AmyuniPDFCreator.IacDocument document)

 

Parameters

document

Reference to the second document that should be appended to the current one.

 

Return Value

True if the Append succeeds, False otherwise.

 

Remarks

Member of AmyuniPDFCreator.IacDocument.

The document to be appended has to be opened by the caller before it can be appended. If the document is password protected, the owner’s password will be needed to append.

See Also:

IacDocument.AppendAsync, IacDocument.Merge, IacDocument.MergeAsync, IacDocument.OpenAsync, IacDocument.SaveAsync

 

Example

Concatenating PDF files with Amyuni PDF Creator for Windows Store Apps.

Dim doc1 As AmyuniPDFCreator.IacDocument = New AmyuniPDFCreator.IacDocument()

' Set the license key

doc1.SetLicenseKey("Amyuni PDF Creator WinRT-UWP Evaluation", "07EFCDAB01000100F280477A62560570D2805290D715A3744214C2755E1A174DABC5DF79946E4D3E88696CBF0724548B26CC8DE76773")

 

' Open a test file asyncronously, from one of the folders where 

' a Windows Store Application has read access by default

Dim file As Windows.Storage.StorageFile = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("TestFile1.pdf")

Dim result As Boolean = Await fPDFCreator.Document.OpenAsync(file, "")

If result Then

    ' Open the second test file asyncronously

    Dim doc2 As AmyuniPDFCreator.IacDocument = New AmyuniPDFCreator.IacDocument()

    file = Await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("TestFile2.pdf")

    result = Await doc2.OpenAsync(file, "")

    If (result) Then

        ' Appending/Contatenating the second document after the first one

        result = doc1.Append(doc2)

        If (result) Then

            ' Saving the resulting file asyncronously, into one of the folders where 

            ' a Windows Store Application has write access by default

            Dim tempPath As String = Windows.Storage.ApplicationData.Current.TemporaryFolder.Path

            result = Await doc1.SaveAsync(System.IO.Path.Combine(tempPath, "append_result.pdf"))

            If (result) Then

                Await (New Windows.UI.Popups.MessageDialog(

                    "Append Succedded!" + Environment.NewLine + System.IO.Path.Combine(tempPath, "append_result.pdf"),

                    "Append Sample")).ShowAsync()

            Else

                Await (New Windows.UI.Popups.MessageDialog("Append Failed", "Append Sample")).ShowAsync()

            End If

        End If

    End If

End If

AmyuniPDFCreator.IacDocument doc1 = new AmyuniPDFCreator.IacDocument();

// Set the license key

doc1.SetLicenseKey("Amyuni PDF Creator WinRT-UWP Evaluation", "07EFCDAB01000100F280477A62560570D2805290D715A3744214C2755E1A174DABC5DF79946E4D3E88696CBF0724548B26CC8DE76773");

 

// Open a test file asyncronously, from one of the folders where 

// a Windows Store Application has read access by default

string tempPath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

bool result = await doc1.OpenAsync(Path.Combine(tempPath, "TestFile1.pdf"), "");

if (result)

{

    // Open the second test file asyncronously

    AmyuniPDFCreator.IacDocument doc2 = new AmyuniPDFCreator.IacDocument();

    result = await doc2.OpenAsync(Path.Combine(tempPath, "TestFile2.pdf"), "");

    if (result)

    {

        // Appending/Contatenating the second document after the first one

        result = doc1.Append(doc2);

        if (result)

        {

            // Saving the resulting file asyncronously, into one of the folders where 

            // a Windows Store Application has write access by default

            tempPath = Windows.Storage.ApplicationData.Current.TemporaryFolder.Path;

            result = await doc1.SaveAsync(System.IO.Path.Combine(tempPath, "append_result.pdf"));

            if (result)

                await(new Windows.UI.Popups.MessageDialog(

                    "Append Succedded!" + Environment.NewLine + System.IO.Path.Combine(tempPath, "append_result.pdf"),

                    "Append Sample")).ShowAsync();

            else

                await(new Windows.UI.Popups.MessageDialog("Append Failed", "Append Sample")).ShowAsync();

        }

    }

}

AmyuniPDFCreator::IacDocument^ doc1 = ref new AmyuniPDFCreator::IacDocument();

// Set the license key

doc1->SetLicenseKey( "Amyuni PDF Creator WinRT-UWP Evaluation", "07EFCDAB01000100F280477A62560570D2805290D715A3744214C2755E1A174DABC5DF79946E4D3E88696CBF0724548B26CC8DE76773");

 

// Open a test file asyncronously, from one of the folders where 

// a Windows Store Application has read access by default

String^ tempPath = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;

concurrency::create_task(doc1->OpenAsync(tempPath + "\\TestFile1.pdf", "")).

then([=](bool result)

{

    if (result)

    {

        // Open the second test file asyncronously

        AmyuniPDFCreator::IacDocument^ doc2 = ref new AmyuniPDFCreator::IacDocument();

        concurrency::create_task(doc2->OpenAsync(tempPath + "\\TestFile2.pdf", "")).

        then([=](bool result)

        {

            if (result)

            {

                // Appending/Contatenating the second document after the first one

                result = doc1->Append( doc2 );

                if (result)

                {

                    // Saving the resulting file asyncronously, into one of the folders where 

                    // a Windows Store Application has write access by default

                    Platform::String^ tempPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path;

                    concurrency::create_task(doc1->SaveAsync(tempPath + "\\append_result.pdf" )).then( [=](bool result)

                    {

                        if (result)

                        {

                            String^ message = ref new String(L"Append Succedded! \n");

                            message += tempPath;

                            message += "\\append_result.pdf";

                            Windows::UI::Popups::MessageDialog^ dialog = ref new Windows::UI::Popups::MessageDialog( message, "Append Sample");

                            concurrency::create_task(dialog ->ShowAsync());

                        }

                        else

                        {

                            Windows::UI::Popups::MessageDialog^ dialog = ref new Windows::UI::Popups::MessageDialog("Append Failed", "Append Sample");

                            concurrency::create_task(dialog ->ShowAsync());

                        }

                    });

                }

            }

        });

    }

});

var doc1 = new AmyuniPDFCreator.IacDocument();

 

// Set the license key

doc1.setLicenseKey("Amyuni PDF Creator WinRT-UWP Evaluation", "07EFCDAB01000100F280477A62560570D2805290D715A3744214C2755E1A174DABC5DF79946E4D3E88696CBF0724548B26CC8DE76773");

 

// Open a test file asyncronously, from one of the folders where 

// a Windows Store Application has read access by default

var tempPath = Windows.ApplicationModel.Package.current.installedLocation.path;

Windows.Storage.StorageFile.getFileFromPathAsync(tempPath + "\\TestFile1.pdf").

then(function (file) {

 

    // Get a stream object for the input file

    file.openAsync(Windows.Storage.FileAccessMode.read).

    then(function (inStream) {

 

        // Open the PDF document from the file stream

        doc1.openAsync(inStream, "").

        then(function (result) {

            if (result) {

 

                // Open the second test file asyncronously

                Windows.Storage.StorageFile.getFileFromPathAsync(tempPath + "\\TestFile2.pdf").

                then(function (file) {

                    file.openAsync(Windows.Storage.FileAccessMode.read).

                    then(function (inStream) {

                        var doc2 = new AmyuniPDFCreator.IacDocument();

                        doc2.openAsync(inStream, "").

                        then(function (result) {

                            if (result) {

 

                                // Appending/Contatenating the second document after the first one

                                doc1.append(doc2);

 

                                // Saving the resulting file asyncronously, into one of the folders where 

                                // a Windows Store Application has write access by default

                                // Not all the overloads of the saveAsync method are available in Javascript

                                var temporaryFolder = Windows.Storage.ApplicationData.current.temporaryFolder;

                                temporaryFolder.getFileAsync("append_output.pdf").

                                then(function (file) {

                                    file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (outStream) {

                                        doc1.saveAsync(outStream).then(function (result) {

                                            if (result)

                                                (new Windows.UI.Popups.MessageDialog("append Succedded! \n" + file.path, "append Sample")).showAsync();

                                            else 

                                                (new Windows.UI.Popups.MessageDialog("append Failed", "append Sample")).showAsync();

                                        });

                                    });

                                }, function (error) {

 

                                    // The output file does not exist, let' s create a new one

                                    temporaryFolder.createFileAsync("append_output.pdf").

                                    then(function (file) {

                                        file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(function (outStream) {

                                            doc1.saveAsync(outStream).then(function (result) {

                                                if (result)

                                                    (new Windows.UI.Popups.MessageDialog("append Succedded! \n" + file.path, "append Sample")).showAsync();

                                                else 

                                                    (new Windows.UI.Popups.MessageDialog("append Failed", "append Sample")).showAsync();

                                            });

                                        });

                                    });

                                });

                            }

                            else

                                (new Windows.UI.Popups.MessageDialog("append Failed", "append Sample")).showAsync();

                        });

                    });

                });

            }

        });

    });

});