Question
CR England
US
Last activity: 28 May 2019 1:37 EDT
pzGenerateDocument returns corrupted file
I have a requirement to generate a Word Document that relies on a template. However when I use the OOTB pzGenerateDocument function to generate this document it returns a file that is corrupted and requires repair to view. The dynamic fields get filled out but I want to solve this corrupted file issue. Has anyone run into this and if so what was your solution?
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
British Telecom
IN
Hi ,
Its always helpful to provide the PEGA version and also screen shot/doc of corrupted file and steps to reproduce .
So that It helps others to try out and suggest any info on this.
Please provide this Info, will get back to you on this.
CR England
US
I found a work around for this if you can stomach a pdf. It will return a file that is not corrupted but it will be in the pdf format.
I found a work around for this if you can stomach a pdf. It will return a file that is not corrupted but it will be in the pdf format.
//call the api to generate word document
try{
url = alwo_worddocgeneration.GenerateWordDocument({Word Template}, tools,"{Primary Page Class}",null);
docFilePath = tools.findPage("pxProcess").getString("pxServiceExportPath") + pega_rules_string.whatComesAfterLast(url, '/');
java.io.DataInputStream tempSourceInputStreamGeneratedFile = new java.io.DataInputStream(new PRInputStream(docFilePath));
//convert word doc to pdf
org.docx4j.openpackaging.packages.WordprocessingMLPackage wordMLPackage = org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(tempSourceInputStreamGeneratedFile);
//Converting above input stream to output stream
java.io.ByteArrayOutputStream tempTargetOutputStreamGeneratedFile = new java.io.ByteArrayOutputStream();
org.docx4j.Docx4J.toPDF(wordMLPackage, tempTargetOutputStreamGeneratedFile);
//Converting above OutputStream to byte array and then encoding it
byte[] byteArrayFinalFileSource = Base64Util.encode(tempTargetOutputStreamGeneratedFile.toByteArray());
//Converting encoded byte array to string
strFileData = new String(byteArrayFinalFileSource);
}catch(Exception e)
{
oLog.error("Error in generating the document");
}
The GenerateWordDocument function correlates to pzGenerateDocument its just usable in my current context. So you may have to save as it. As far as the rest of it goes all you have to do after this to make it into an attachment is make a new attachment page and set the source for the file to the local variable strFileData (you will have to have this in your activity). You will also need a word template to use.
-
Alexey Privalov
Centene Corporation
US
Hello
This looks like a post that can help me achieve my use case. With this, I am guessing the word document will be stored in /tempDir/StaticContent/global/ServiceExport which we are converting to .pdf
Can you please let me know if there is any way filename.pdf to ServiceExport directory.
Thanks in advance.
CR England
US
Well the file should be there in the export directory. From there you should be able to download and whatnot. The end bit of this is so that we can attach the file to a case.
Centene Corporation
US
Hello
Thanks for the response. The reason I ask is that we need to FTP the file in serviceExport for print purposes. Since, the word documents are corrupted, the print software is not able to read those .docx files. If I can convert them to pdf and save them in the serviceExport, that would solve my problem. Can you please let me know if you can think of any methods to do that.
Thanks
Abhi
Pegasystems Inc.
US
I have done a search on this. For a case, when user uses the pzGenerateDocument function to generate a word document based on an existing RULE-TEMPLATE-WORD word document there are a couple of issues occuring: eg. document format is corrupted; page tags inserted in the document are not populated correctly.
The root cause of the issue is with the template user is using - a typo. Syntax of pega reference tag is incorrect. Instead of pega:reference it is pega.reference.
Using {pega:reference pyWorkPage.pyID} is making it working fine.
So, please double check your template if it has the correct syntax.
CR England
US
I have actually been in talks with Pega about this and the root cause is a problem in Docx4j. It returns a corrupted file even if it is a blank file.
Pegasystems Inc.
US
Have you raised a SR for it?
CR England
US
I did. I apologize for not mentioning it here. But it has since been resolved without a fix because it has to do with an external library. That's why I came back with a workaround that would work in some scenarios.
-
Guangri Liang
Pegasystems Inc.
US
Okay, thanks.
Areantans
AU
in which scenario it's failing ? did you able to provide the trace for any of those
-
Vikas Agrawal Rushabh Shah