Search Results for

    Show / Hide Table of Contents

    Plugin: Aspose Word

    Introduction

    This plugin provides the most complete and efficient set of Word document processing solution without any Microsoft Word dependencies.

    Features

    Create PDF from Word template

    Merge data to a Word document template and return a PDF as result.

    Method Name: CreatePDFFromWordTemplate

    Input

    • WordTemplate (required)
    • MergedData (required)

    Output

    • Data as array bytes of pdf file.

    Example

    var documentApi = ctx.Use<IDocumentApi>();
    
    var input = ctx.Input;
    var wordDoc = input["WordDocument"];
    var wordDocBytes = documentApi.ReadAllBytes(wordDoc);
    
    var mergedData = new Dictionary<string, object>(); 
    mergedData.Add("first_name", "John");
    mergedData.Add("last_name", "Doe");
    mergedData.Add("address", "Virumgårdsvej 17A, 2830");
    mergedData.Add("city", "Virum");
    mergedData.Add("phone", "+45 70 26 29 70");
    mergedData.Add("email", "contact@globeteam.com");
    
    var sysDocApi = ctx.Use<ISysDocumentApi>();
    var result = sysDocApi.ReadAllBytes("avatar");
    mergedData.Add("ImageField", result);
    
    var parameters = new Dictionary<string, object>();
    parameters.Add("WordTemplate", wordDocBytes);
    parameters.Add("MergedData", mergedData);
    
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposeWord", "CreatePDFFromWordTemplate", parameters);
    
    var pdfDocBytes = pluginResult.Get<byte[]>("PDFResult");
    var pdfDoc = documentApi.Create(Path.GetFileNameWithoutExtension(wordDoc.FileName)+".pdf");
    
    documentApi.Store(pdfDoc, pdfDocBytes);
    var dataApi = ctx.Use<IDataApi>();
    dataApi.Update(input["Id"], new 
    {
        PDFDocument = pdfDoc
    });
    

    Create file from Word template

    Merge data to a Word document template and return the binary of file, user must input the save format.

    Method Name: CreateFileFromWordTemplate

    Input

    • WordTemplate: It's required, this field is the binary of file Word template
    • MergedData: It's optional, contains merged data which is used to populate to the merge fields which are textual, formatted placeholders in a template.
    • SaveFormat: It's required. This field presents the file extension of file output (e.g. doc, docx, pdf, text, html...), refer supported save format

    Output

    • FileResult: binary of file.
    • IsSuccess:
      • true if create file successfully.
      • false if there are exception while creating file.
    • Error: if there are exception while creating file, it has value

    Example

    var documentApi = ctx.Use<IDocumentApi>();
    var sysDocumentApi = ctx.Use<ISysDocumentApi>(); 
    
    var wordDocBytes = sysDocumentApi.ReadAllBytes("template-word");
    
    var mergedData = new Dictionary<string, object>(); 
    mergedData.Add("first_name", "William");
    mergedData.Add("last_name", "Hill");
    mergedData.Add("address", "Virumgårdsvej 17A, 2830");
    mergedData.Add("city", "Virum");
    mergedData.Add("phone", "+45 70 26 29 70");
    
    var parameters = new Dictionary<string, object>();
    parameters.Add("WordTemplate", wordDocBytes);
    parameters.Add("MergedData", mergedData);
    parameters.Add("SaveFormat", "Docx");
    
    var pluginApi = ctx.Use<IPluginApi>(); 
    var pluginResult = pluginApi.Invoke("CwAsposeWord", "CreateFileFromWordTemplate", parameters);
    
    var fileBytes = pluginResult.Get<byte[]>("FileResult");
    

    Installation

    Requirements

    • Casewhere v2.6 or later
    • A valid Aspose Word license

    Configuration

    We need to provide the valid purchased license to make sure no water mark appeared on the generated pdf document.

    Example

    { 
    	"License": //a base64 string
    } 
    

    Releases

    1.0.0 - 15/05/2020

    Changelog

    • Create PDF from Word template

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

    1.1.0 - 31/05/2022

    Changelog

    • Create File from Word template

    Download (login required): Aspose Word plugin v1.1.0

    In This Article
    Back to top Generated by DocFX