0

我一直在尝试使用 Adob​​e Live Cycle 将 XDP 转换为 PDF。我的大多数表格都很好。但是在转换其中一些时,我很好???代替某些地方的空格。关于如何纠正它的任何建议?

下面是我正在使用的代码片段:

公共字节[] 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);
    }
}
4

1 回答 1

0

我建议尝试两件事:

  1. 检查字体。切换到非常常见的东西,比如 Arial / Times New Roman,看看字符是否仍然丢失
  2. 检查字符编码。它可能不是您使用的简单问号字符,如果是这样,字符编码将很重要。最简单的方法是确保您的问号是 ascii char 63(十进制)。

我希望这会有所帮助。

于 2018-04-23T02:35:52.903 回答