Introduction
Build.One offers the possibility to create word-files by the integrated printing solution DocxFactory. For that you have to do the following steps:
- Prepare your data from ABL into a json to send to DocxFactory
- Create a template for the document in Word
Preparing the data & send to DocxFactory
Easy example: Using a given json file and template
Afterwards you’ll find the example code how to merge a json file and a given word template to get a printed word file. Also you’ll find the example templates
Extended example: Get data from a TreeStruct
Afterwards you’ll find an anonymised real world customer example for getting data from a TreeGrid, calling the DocxFactory methods and creating the document. Below you’ll find the class ExportStruct.cls
as an ABL script, here all customer specific information are anonymised with Customer.TreeEntity
ExportStruct.cls
as an ABL script, here all customer specific information are anonymised with Customer.TreeEntity
GenerateDocumentParameter
Creating Word Templates
The printing functionality in Build.One works as follows:
- You have to create a template in Word, in which the data will be merged
- This template contains so called bookmarks, which is standard word functionality. These bookmarks references the name of the entity from your dataSet, these bookmark references parts of the text in the word-file, where you can add the fields from the entity by using
{fieldName}
. In the example below you’ll find: - The option in word where to enter the bookmarks
- A variable
{testField}
which will be filled on printing - A bookmark
YourDataEntity
which includes the variable from 2. - In the template itself you can use all formatting styles from word, these will be applied to the printed document. Also lists (for example positions inside a order) could be used, by having these inside one bookmark. That’s the way you can configure list views
Example: Convert a docx file into pdf
Build.One is using the Microsoft Azure Services to convert a docx file into a pdf. For configuration please contact your contact person at Build.One
Here you’ll find an example OpenEdge code for using these services to create a pdf file
block-level on error undo, throw.
USING Progress.Json.ObjectModel.*.
PROCEDURE UploadFileToSharePoint:
DEFINE INPUT PARAMETER pcFileLocation AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcFileName AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER pcServerFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE oLib AS OpenEdge.Net.HTTP.IHttpClientLibrary NO-UNDO.
DEFINE VARIABLE oClient AS OpenEdge.Net.HTTP.IHttpClient NO-UNDO.
DEFINE VARIABLE oRequest AS OpenEdge.Net.HTTP.IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS OpenEdge.Net.HTTP.IHttpResponse NO-UNDO.
DEFINE VARIABLE oRequestBody AS OpenEdge.Net.MultipartEntity NO-UNDO.
DEFINE VARIABLE oPart AS OpenEdge.Net.MessagePart NO-UNDO.
DEFINE VARIABLE oData AS OpenEdge.Core.Memptr NO-UNDO.
DEFINE VARIABLE oJsonObject AS JsonObject NO-UNDO.
DEFINE VARIABLE mpfile AS MEMPTR NO-UNDO.
FILE-INFO:FILE-NAME = SUBSTITUTE("&1/&2", pcFileLocation, pcFileName).
COPY-LOB FROM FILE file-info:full-pathname TO mpfile.
oData = NEW OpenEdge.Core.Memptr(mpfile).
oPart = NEW OpenEdge.Net.MessagePart(SUBSTITUTE('application/octet-stream; name=file', pcFileName), oData).
oPart:Headers:Put(OpenEdge.Net.HTTP.HttpHeaderBuilder:Build("Content-Disposition"):Value(SUBSTITUTE('form-data; name="file"; filename="&1"', pcFileName)):Header).
oPart:Headers:Put(OpenEdge.Net.HTTP.HttpHeaderBuilder:Build("Content-Type"):Value("application/vnd.openxmlformats-officedocument.wordprocessingml.document"):Header).
oRequestBody = NEW OpenEdge.Net.MultipartEntity().
oRequestBody:AddPart(oPart).
oLib = OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder:Build():sslVerifyHost(FALSE):Library.
oClient = OpenEdge.Net.HTTP.ClientBuilder:Build():UsingLibrary(oLib):SetNumRetries(0):Client.
oRequest = OpenEdge.Net.HTTP.RequestBuilder:Post("http://gateway:3000/resource/graph/files", oRequestBody)
:ContentType("multipart/form-data")
:AddHeader("MIME-Version", "1.0")
:AddHeader("Connection", "Keep-Alive")
:WithData(oRequestBody, "multipart/form-data")
:Request.
oResponse = oClient:Execute(oRequest).
IF oResponse:ContentType = 'application/json' THEN
DO:
oJsonObject = CAST(oResponse:Entity, JsonObject).
pcServerFileName = oJsonObject:GetCharacter("serverFileName").
END.
CATCH e AS Progress.Lang.AppError :
MESSAGE 'Error' SKIP e:ReturnValue SKIP e:GetMessage(1).
END CATCH.
FINALLY:
SET-SIZE(mpfile) = 0.
END FINALLY.
END PROCEDURE.
PROCEDURE DownloadFileFromSharePoint:
DEFINE INPUT PARAMETER pcServerFileName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcOutputFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE oLib AS OpenEdge.Net.HTTP.IHttpClientLibrary NO-UNDO.
DEFINE VARIABLE oClient AS OpenEdge.Net.HTTP.IHttpClient NO-UNDO.
DEFINE VARIABLE oRequest AS OpenEdge.Net.HTTP.IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS OpenEdge.Net.HTTP.IHttpResponse NO-UNDO.
DEFINE VARIABLE oJsonObject AS JsonObject NO-UNDO.
DEFINE VARIABLE oPayload AS OpenEdge.Core.Memptr NO-UNDO.
oLib = OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder:Build():sslVerifyHost(FALSE):Library.
oClient = OpenEdge.Net.HTTP.ClientBuilder:Build():UsingLibrary(oLib):SetNumRetries(0):Client.
oRequest = OpenEdge.Net.HTTP.RequestBuilder:Get(SUBSTITUTE("http://gateway:3000/resource/graph/files/&1/ConvertToPdf", pcServerFileName)):Request.
oResponse = oClient:Execute(oRequest).
IF oResponse:ContentType = 'application/json' THEN
DO:
oJsonObject = CAST(oResponse:Entity, JsonObject).
MESSAGE STRING(oJsonObject:GetJsonText()).
END.
ELSE
DO:
oPayload = CAST(oResponse:Entity, OpenEdge.Core.ByteBucket):GetBytes().
COPY-LOB oPayload:Value TO FILE pcOutputFileName.
END.
CATCH e AS Progress.Lang.AppError :
MESSAGE 'Error' SKIP e:ReturnValue SKIP e:GetMessage(1).
END CATCH.
END PROCEDURE.
DEFINE VARIABLE cServerFileName AS CHARACTER NO-UNDO.
RUN UploadFileToSharePoint(SUBSTITUTE("&1/master", Akioma.Swat.SessionManager:DataDirectoryServer), "Doc1.docx", OUTPUT cServerFileName).
RUN DownloadFileFromSharePoint(cServerFileName, SUBSTITUTE("&1/&2", SESSION:TEMP-DIR, "myFile2.pdf")).
Back to Documentation
Back to Home Page