Configuring License Information

Before any operation can be done on the PDFCreator library or control, the library or the control needs to be activated using the SetLicenseKey method as shown below.

Sample code for using the PDFCreator control to open a PDF file for viewing or editing:

 

 

using AmyuniPDFCreator;

 

bool ProcessFile()

{

    // Comment this line and uncomment the next one for retrieving the document

    // object from the Xaml PDF control

    IacDocument document = new IacDocument();

    // IacDocument document = fPDFCreator.Document; 

 

    // Set the License key

    document.SetLicenseKey( "Amyuni PDF Creator UWP Evaluation", "07EFCDAB01000100F14AD5A9E030AECD96034C06D18A11862EDA58136BDDF81DBD92DFABA49863B65E442ABBE229E14C7FCE484409DC");

 

    // Prepare the FileOpenPicker Dialog for Windows Store Applications

    var filePicker1 = new Windows.Storage.Pickers.FileOpenPicker();

    filePicker1.FileTypeFilter.Add(".pdf");

 

    // Show the FileOpenPicker Dialog 

    var selectedFile = await filePicker1.PickSingleFileAsync();

 

    // Open a pdf document selected by a user asynchronously

    bool result = await document.OpenAsync(selectedFile, "");

 

    // Switch to design mode before adding objects to the document

    document.ReportState = IacReportState.acReportStateDesign;

 

    // Getting the first page of the document

    IacPage page = document.GetPage(1);

 

    // Adding a frame object to the page.

    // A frame is a rectangular area that can have text, border, and

    // a background color.

    IacObject frame = page.CreateObject(IacObjectType.acObjectTypeText,"Frame 1");

 

    // Position the frame

    // x, y, width, height  

    frame.Coordinates = new Windows.Foundation.Rect(200, 600, 1800, 200); 

 

    // Set the Text attribute

    frame.AttributeByName("Text").Value = "Hello";

 

    // Set the Font attribute

    frame.AttributeByName("TextFont").Value = "Arial, 32, 500, 0, 0";

 

    // Prepare the FileSavePicker Dialog for Windows Store Applications

    var filePickerSave = new Windows.Storage.Pickers.FileSavePicker();

    filePickerSave.FileTypeChoices.Add(

                        "PDF File", new List<string>(new string[1] {".pdf"}));

    filePickerSave.SuggestedFileName = "OutputDocument";

    filePickerSave.SuggestedStartLocation = 

                        Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

 

    // Show the FileSavePicker Dialog 

    var selectedOutFile = await filePickerSave.PickSaveFileAsync();

 

    // Save the modified document to a new file

    return await document.SaveAsync( selectedOutFile );

}

 

#include <ppltasks.h>

using namespace concurrency;

using namespace Windows::Storage;

using namespace AmyuniPDFCreator;

 

void MyPage::ProcessFile()

{

  // Comment this line and uncomment the next one for retrieving the document

  // object from the Xaml PDF control

  auto pdfDoc = ref new IacDocument(); 

 

  // Set license key

  pdfDoc->SetLicenseKey("Amyuni PDF Creator UWP Evaluation", "07EFCDAB01000100F14AD5A9E030AECD96034C06D18A11862EDA58136BDDF81DBD92DFABA49863B65E442ABBE229E14C7FCE484409DC");

 

  // Prepare the FileOpenPicker Dialog for Windows Store Applications

  auto filePicker = ref new Pickers::FileOpenPicker();

  filePicker->FileTypeFilter->Append(".pdf");

 

  // Show the FileOpenPicker Dialog 

  task<void> pickFileTask = create_task( 

      filePicker->PickSingleFileAsync() ).then(

          [this, pdfDoc](StorageFile^ selectedFile){

 

    // Open a pdf document selected by a user asynchronously

    return create_task(pdfDoc->OpenAsync(selectedFile, "")).then( 

        [this, pdfDoc,selectedFile](bool succeded){

      if(succeded)

      {

        // Switch to design mode before adding objects to the document

        pdfDoc->ReportState = IacReportState::acReportStateDesign;

 

        // Getting the first page of the document

        IacPage^ page = pdfDoc->GetPage(1);

 

        // Adding a frame object to the page.

        // A frame is a rectangular area that can have text, border, and

        // a background color.

        IacObject^ frame = page->CreateObject(

            IacObjectType::acObjectTypeText, "Frame1");

 

        // Position the frame

        // x, y, width, height

        frame->Coordinates = Windows::Foundation::Rect(200, 600, 1800, 200); 

 

        // Setting the Text attribute

        frame->AttributeByName("Text")->Value = "Hello";

 

        // Setting the Font attribute

        frame->AttributeByName("TextFont")->Value = "Arial, 32, 500, 0, 0";        

 

        // Prepare the FileSavePicker Dialog for Windows Store Applications

        auto filePickerSave = ref new Pickers::FileSavePicker();

        auto pdfExtensions = ref new Platform::Collections::Vector<string^>(); 

        pdfExtensions->Append(".pdf"); 

        filePickerSave->FileTypeChoices->Insert("PDF File", pdfExtensions);

        filePickerSave->SuggestedFileName = "Concatenated Document";

        filePickerSave->SuggestedStartLocation = 

                    Pickers::PickerLocationId::DocumentsLibrary;

 

        // Show the FileSavePicker Dialog 

        return concurrency::create_task(          

            filePickerSave->PickSaveFileAsync()).then(

                        [this,pdfDoc](StorageFile^ saveFile){

 

            // Save the modified document to a new file

          return concurrency::create_task(            

              pdfDoc->SaveAsync(

                  saveFile, IacFileSaveOption::acFileSaveView)).then(

                      [](bool result){

            if (!result)

            {

              // saving failed

              // TODO: error handling

            }

          });

        });

      }

      else; // TODO: error handling

    });

  });

}

 

function processFile() {

  // The Xaml PDF control cannot be used from JavaScript,

  // but we can still use the IacDocument class

  var pdfDoc = new AmyuniPDFCreator.IacDocument();

 

  // Set license key

  pdfDoc.SetLicenseKey("Amyuni PDF Creator UWP Evaluation"07EFCDAB01000100F14AD5A9E030AECD96034C06D18A11862EDA58136BDDF81DBD92DFABA49863B65E442ABBE229E14C7FCE484409DC");

 

  // Prepare the FileOpenPicker Dialog for Windows Store Applications

  var filePicker1 = new Windows.Storage.Pickers.FileOpenPicker();

  filePicker1.fileTypeFilter.append(".pdf");

 

  // Show the FileOpenPicker Dialog

  filePicker1.pickSingleFileAsync().then( function(selectedFile){

    // Retrieve a stream object from a pdf file selected by the user

    selectedFile.openAsync(Windows.Storage.FileAccessMode.read).then(

        function(inStream) {

        // Open the input stream containing the PDF file

      return pdfDoc.openAsync(inStream, "").done( function(openSuccedded){

        if (openSuccedded) {

          // Switch to design mode before adding objects to the document

          pdfDoc.ReportState = 

                      AmyuniPDFCreator.IacReportState.acReportStateDesign;

 

          // Getting the first page of the document

          var page = pdfDoc.getPage(1);          

 

          // Adding a frame object to the page.

          // A frame is a rectangular area that can have text, border, and

          // a background color.

          var frame = page.createObject(

              AmyuniPDFCreator.IacObjectType.acObjectTypeFrame, "Frame1");

 

          // Position the frame

          frame.attributeByName("Left").value = 200;

          frame.attributeByName("Top").value = 600;

          frame.attributeByName("Right").value = 2000;

          frame.attributeByName("Bottom").value = 800;

 

          // Setting the Text attribute

          frame.attributeByName("Text").value = "Hello";

 

          // Setting the Font attribute

          frame.attributeByName("TextFont").value = "Arial, 32, 500, 0, 0";

 

          // Prepare the FileSavePicker Dialog for Windows Store Applications

          var filePickerSave = new Windows.Storage.Pickers.FileSavePicker();

          filePickerSave.fileTypeChoices.insert("PDF File", [".pdf"]);

          filePickerSave.suggestedFileName = "Output Document";

          filePickerSave.suggestedStartLocation = 

                  Windows.Storage.Pickers.PickerLocationId.documentsLibrary;

 

          // Show the FileSavePicker Dialog 

          return filePickerSave.pickSaveFileAsync().done(function(selectedFile){

            // Save the modified document to a new file

            return pdfDoc.saveAsync(selectedFile);

          });

        }

      });

    });

  });

}