0

I have been trying to convert XDP to PDF using Adobe Live Cycle. Most of my forms turn up good. But while converting some of them, I fine ??? replaced in place of blank spaces at certain places. Any suggestions to how can I rectify that?

Below is the code snippet that I am using:

public byte[] generatePDF(TextDocument xdpDocument) {

    try {
        Assert.notNull(xdpDocument, "XDP Document must be passed.");
        Assert.hasLength(xdpDocument.getContent(), "XDPDocument content cannot be null");
        // Create a ServiceClientFactory object
        ServiceClientFactory myFactory = ServiceClientFactory.createInstance(createConnectionProperties());
        // Create an OutputClient object
        FormsServiceClient formsClient = new FormsServiceClient(myFactory);
        formsClient.resetCache();
        String text = xdpDocument.getContent();

        String charSet = xdpDocument.getCharsetName();
        if (charSet == null || charSet.trim().length() == 0) {
            charSet = StandardCharsets.UTF_8.name();
        }
        byte[] bytes = text.getBytes();

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        Document inTemplate = new Document(byteArrayInputStream);
        // Set PDF run-time options
        // Set rendering run-time options
        RenderOptionsSpec renderOptionsSpec = new RenderOptionsSpec();
        renderOptionsSpec.setLinearizedPDF(true);
        renderOptionsSpec.setAcrobatVersion(AcrobatVersion.Acrobat_9);

        PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();
        pdfFormRenderSpec.setGenerateServerAppearance(true);
        pdfFormRenderSpec.setCharset("UTF8");
        FormsResult formOut = formsClient.renderPDFForm2(inTemplate, null, pdfFormRenderSpec, null, null);
        Document xfaPdfOutput = formOut.getOutputContent();
        //If the input file is already static PDF, then below method will throw an exception - handle it
        OutputClient outClient = new OutputClient(myFactory);
        outClient.resetCache();
        Document staticPdfOutput = outClient.transformPDF(xfaPdfOutput, TransformationFormat.PDF, null, null, null);
        byte[] data = StreamIO.toBytes(staticPdfOutput.getInputStream());

        return data;
    } catch(IllegalArgumentException ex) {
        logger.error("Input validation failed for generatePDF request " + ex.getMessage());
        throw new EformsException(ErrorExceptionCode.INPUT_REQUIRED  + " - " + ex.getMessage(), ErrorExceptionCode.INPUT_REQUIRED);
    } catch (Exception e) {
        logger.error("Exception occurred in Adobe Services while generating PDF from xdpDocument..", e);
        throw new EformsException(ErrorExceptionCode.PDF_XDP_CONVERSION_EXCEPTION, e);
    }
}
  • Could you maybe post the code you are using to convert the XDP to PDF? Usually the ?? appear because an XML format (either XDP or XML data file) has been mishandled with respect to the character encoding scheme. The ?? you see may be Unicode non-breaking spaces. If the XML is being transcoded improperly, that can lead to the symptoms you are seeing. – Rob McDougall Apr 22 '18 at 21:15
  • Thanks Rob. Can you got through my comment below for some added info and share your views on that? – Sambhav Malhotra Apr 24 '18 at 07:00
  • I still believe that this is likely a character encoding issue. Can you describe (or post) your code that reads in the XML and calls LiveCycle? – Rob McDougall Apr 24 '18 at 11:45
  • I went through the code where i was reading xml and sending call ti love cycle, and found that the encoding was missing. pdfFormRenderSpec.setCharset("UTF8"); I added this line to set the encoding, and things seem to work fine now. Thanks for the help. – Sambhav Malhotra Apr 25 '18 at 13:45
  • Glad I could help. – Rob McDougall Apr 25 '18 at 17:19
  • Also Rob, I have placed a sign field in my xdp. I need its position(x and y coordinates) in document from the top of the page. I am able to find y coordinate but its relative to the parent subform tag. Can you help me with this? – Sambhav Malhotra Apr 26 '18 at 11:45
  • I'm afraid that you can only get the x, y co-ordinates relative to the parent contains (see Designer Scripting Referene under layoutPseudomodel x and y methods). In order to get the absolute location you'll have to climb up the object tree (using the parent property) and add up all the x and y coordinates. – Rob McDougall Apr 28 '18 at 15:56
  • Okay. Thanks! That helps. Also, I am using this LiveCycle for conversion, but the performance is getting impacted. Are there any other libraries like iText that support this conversion of XDP to PDF and such scenarios? – Sambhav Malhotra May 02 '18 at 06:40
  • And for the actual problem, it did work sometime back.. but I am back to same issue again. I have attached the code snippet I am using. – Sambhav Malhotra May 02 '18 at 09:57
  • AFAIK - There aren't really any other ways to convert XDP to PDF. iText has some limited XFA capabilities however I don't think it will render to PDF (although I am not an iText expert). LiveCycle/AEM would certainly produce the best result. – Rob McDougall May 03 '18 at 20:57
  • The code you provided has a number of red flags that I would do differently: 1) You don't indicate what kind of object xdpDocument variable is, however the fact that you are converting it to String and then into bytes seems like a potential source of the encoding issue. Can you treat the xdpDocument as bytes only? – Rob McDougall May 03 '18 at 21:09
  • 2) You don't need to render the PDF as an interactive form and then flatten it (unless you have steps in the middle that involve a human filling in the form, however it's not indicated in your snippet). You really only need to call OutputClient.generatePDFOutput() or generatePDFOutput2() in order to convert an XDP to a flat PDF. It is very similar to the FormsClient.renderPDFForm() however it generates a flat PDF so you won't need to call transformPDF(). – Rob McDougall May 03 '18 at 21:11
  • 3) You probably don't need to call resetCache(). I've been developing code in LiveCycle/AEM for over a decade and I've never had to make that particular call. I'm doubting that you do either. – Rob McDougall May 03 '18 at 21:13
  • Adobe has an extensive set of example code under their "API Quickstarts". https://help.adobe.com/en_US/livecycle/11.0/ProgramLC/WS624e3cba99b79e12-171c1d181336a34f42f-8000.2.html Check out the OutputService quickstart examples for Creating PDF Documents. – Rob McDougall May 03 '18 at 21:14
  • Got back to this same problem again. Still not working. And another problem, I am converting XDP to pdf, and the actual document is of size Letter than A4, so after conversion, the data is being cropped and also the data mapping with sample values is distorted. Can you help in that? – Sambhav Malhotra Jul 02 '18 at 07:28
  • Have you made the change to OutputClient? If you're using OutputClient, then the size of the output should be based on the size of the master page in the XDP. It may be time to post a new code snippet and/or start a new question. – Rob McDougall Jul 03 '18 at 15:06
  • The code is same as I have posted above and I have started a new thread here. https://stackoverflow.com/questions/51166954/xdp-to-pdf-with-page-size – Sambhav Malhotra Jul 04 '18 at 06:19
  • Before answering your question, I think you should make the changes I indicated above. That may eliminate your page size issue. – Rob McDougall Jul 06 '18 at 17:48

1 Answers1

0

I suggest trying 2 things:

  1. Check the font. Switch to something very common like Arial / Times New Roman and see if the characters are still lost
  2. Check the character encoding. It might not be a simple question mark character you are using and if so the character encoding will be important. The easiest way is to make sure your question mark is ascii char 63 (decimal).

I hope that helps.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
  • Thanks for the options. I looked through my code and went through some research found that ' ' this syntax had been added with multiple spaces in between the span tag which is actually producing the ? in the static pdf. One more point to see it that I am converting it to static pdf and not dynamic pdf. Any views on how to get through this? – Sambhav Malhotra Apr 24 '18 at 06:59
  • Also, If I replace each of the space within the tag, with  (character for non-breaking space), I get the desired output. – Sambhav Malhotra Apr 24 '18 at 09:30