Converting XDP to PDF using Live Cycle replaces question marks(?) with space at multiple places. How can that be fixed?

472 Views Asked by At

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);
    }
}
1

There are 1 best solutions below

2
On

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.