Search Results for

    Show / Hide Table of Contents

    Plugin: Aspose PDF

    Introduction

    The plugin provides the ability to add, replace text, paragraph and image to a PDF file by using Aspose.PDF library.

    image-20220317091502649

    Features

    Add a text into a PDF file

    Add a text into a PDF file at a specified position and return a PDF file as a result.

    Method name: AddTextToPDF

    Input:

    • PDFDocument(required): The document to add text into.
    • Text(required): Text to be added into the document.

    Output:

    • PDFDocument: The document with text added in.

    Example

    var parameters = new Dictionary<string, object>();
    parameters.Add("PDFDocument", pdfDocBytes); // pdfDocBytes is byte array of the PDF file.
    parameters.Add("TextContent", ctx.Get<string>("TextContent"));
    parameters.Add("PositionX", ctx.Get<int>("PositionX"));
    parameters.Add("PositionY", ctx.Get<int>("PositionY"));
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePDF", "AddTextToPDF", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Add a paragraph into a PDF file

    Add a paragraph into a PDF file at a specified position and return a PDF file as a result.

    Method name: AddParagraphToPDF

    Input:

    • PDFDocument(required): The document to add paragraph into.
    • Text(required): Paragraph to be added into the document.

    Output:

    • PDFDocument: The document with paragraph added in.

    Example

    var parameters = new Dictionary<string, object>();
    parameters.Add("PDFDocument", pdfDocBytes); // pdfDocBytes is byte array of the PDF file.
    parameters.Add("ParagraphContent", textContent);
    parameters.Add("UpperRightX", ctx.Get<int>("UpperRightX"));
    parameters.Add("UpperRightY", ctx.Get<int>("UpperRightY"));
    parameters.Add("LowerLeftX", ctx.Get<int>("LowerLeftX"));
    parameters.Add("LowerLeftY", ctx.Get<int>("LowerLeftY"));
    parameters.Add("SubsequentLinesIndent", ctx.Get<int>("SubsequentLinesIndent"));
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePDF", "AddParagraphToPDF", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Replace a text in a PDF file

    Replace a text in a PDF file at a specified position and return a PDF file as a result.

    Method name: ReplaceTextInPDF

    Input:

    • PDFDocument(required): The document to replace text.
    • OldValue(required): The text to be replaced in a document.
    • NewValue(required): The text to replace.

    Output:

    • PDFDocument: The document with the text replaced.

    Example

    var parameters = new Dictionary<string, object>();
    parameters.Add("PDFDocument", pdfDocBytes); // pdfDocBytes is byte array of the PDF file.
    parameters.Add("OldValue", oldValue);
    parameters.Add("NewValue", newValue);
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePDF", "ReplaceTextInPDF", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Add an image into a PDF file

    Add an image into a PDF file at a specified position and return a PDF file as a result.

    Method name: AddImageToPDF

    Input:

    • PDFDocument(required): The document to add image into.
    • Image(required): The image to be added into the document.

    Output:

    • PDFDocument: The document with the image added in.

    Example

    var parameters = new Dictionary<string, object>();
    parameters.Add("PDFDocument", pdfDocBytes); // pdfDocBytes is byte array of the PDF file.
    parameters.Add("Image", imageBytes); // imageBytes is byte array of the image file.
    parameters.Add("UpperRightX", ctx.Get<int>("UpperRightX"));
    parameters.Add("UpperRightY", ctx.Get<int>("UpperRightY"));
    parameters.Add("LowerLeftX", ctx.Get<int>("LowerLeftX"));
    parameters.Add("LowerLeftY", ctx.Get<int>("LowerLeftY"));
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePDF", "AddImageToPDF", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Replace an image in a PDF file

    Replace an image in a PDF file and return a PDF file as a result.

    Method name: ReplaceImageInPDF

    Input:

    • PDFDocument(required): The document to add image into.
    • Image(required): The image to replace the image in the document.
    • ImageIndex(required): The index of the image to be replaced in the document.

    Output:

    • PDFDocument: The document with the image replaced.

    Example

    var parameters = new Dictionary<string, object>();
    parameters.Add("PDFDocument", pdfDocBytes); // pdfDocBytes is byte array of the PDF file.
    parameters.Add("Image", imageBytes); // imageBytes is byte array of the image file.
    parameters.Add("ImageIndex", ctx.Get<int>("ImageIndex"));
    parameters.Add("PageNumber", ctx.Get<int>("PageNumber"));
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePDF", "ReplaceImageInPDF", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Convert Html content to PDF document

    Able to convert Html as a string, and return a PDF file as a result.

    Method name: HtmlToPdf

    Input:

    • HtmlContent (required): string - The html content that will be used to convert.

    Output:

    • PDFResult: byte[] - The stream content as Byte array
    • IsSuccess: boolean - true if successful
    • Error: string

    Example

    var htmlContent = "<html><head></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
    var parameters = new Dictionary<string, object>();
    parameters.Add("HtmlContent", htmlContent);
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposePdf", "HtmlToPdf", parameters);
    var pdfDocResultBytes = pluginResult.Get<byte[]>("PDFResult");
    

    Plugin Result

    Check license result

    var licenseValid = pluginResult.Get<byte[]>("LicenseValid");
    var licenseError = pluginResult.Get("LicenseError");
    // just have value when LicenseValid is false
    
    

    Error message

    var outputResult = pluginResult.Get<string>("Output");

    ​

    Installation

    Requirements

    • Casewhere v2.6 or later
    • A valid AsposePDF license

    Configuration

    A valid purchased license needs to be provided to have no watermark appeared on the generated pdf document.

    Example

    { 
    	"License": //a base64 string
    } 
    

    Releases

    1.0.1 - 23/09/2022

    Changelog

    • Add method: Convert Html to Pdf

    Download (login required): Aspose PDF plugin v1.0.1

    1.0.0 - 10/01/2022

    Changelog

    • Add text to PDF
    • Add paragraph to PDF
    • Replace text in PDF
    • Add image to PDF
    • Replace image in PDF

    Download (login required): Aspose PDF plugin v1.0.0

    In This Article
    Back to top Generated by DocFX