Plugin: Aspose Word
Introduction
This plugin provides a complete and efficient set of Word document processing capabilities without any Microsoft Word dependencies.
Features
Create PDF from Word template
Merge data into a Word document template and return a PDF as the result.
Method Name: CreatePDFFromWordTemplate
Input
- WordTemplate (required)
- MergedData (required)
Output
- Data as a byte array of the 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 into a Word document template and return the file binary. You must specify the save format.
Method Name: CreateFileFromWordTemplate
Input
- WordTemplate: Required. This field is the binary of the Word template file.
- MergedData: Optional. Contains the merged data used to populate the merge fields, which are textual, formatted placeholders in a template.
- SaveFormat: Required. This field specifies the file extension of the output file (e.g. doc, docx, pdf, text, html...); refer to supported save format
Output
- FileResult: binary of file.
- IsSuccess:
trueif the file is created successfully.falseif an exception occurs while creating the file.
- Error: has a value if an exception occurs while creating the file.
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
A valid purchased license must be provided to ensure no watermark appears 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