使用iText pdfHTML的PDF中的图像对齐问题

时间:2017-12-27 10:10:41

标签: java itext itext7

我正在尝试使用iText7.1.0和pdfHTML2.0.0将HTML页面导出为PDF。由于某种原因,页面具有饼图图像的格式问题(在HTML中水平对齐,而在PDF中垂直对齐),左侧的表格(标题为“功能”)垂直向下推。 PDF渲染器正在使用的jsFiddle link到我的HTML代码。

以下是用于呈现PDF的Java代码(Page1.html与小提琴中的HTML代码相同):

/*
 * Copyright 2016-2017, iText Group NV.
 * This example was created by Bruno Lowagie.
 * It was written in the context of the following book:
 * https://leanpub.com/itext7_pdfHTML
 * Go to http://developers.itextpdf.com for more info.
 */
package com.itextpdf.htmlsamples.chapter01;

import java.io.File;
import java.io.IOException;

import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.licensekey.LicenseKey;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Converts a simple HTML file to PDF using File objects
 * as arguments for the convertToPdf() method.
 */
public class C01E03_HelloWorld {

    /** The Base URI of the HTML page. */
    public static final String BASEURI = "src/main/resources/html/";
    /** The path to the source HTML file. */
    public static final String SRC = String.format("%sPage1.html", BASEURI);
    /** The target folder for the result. */
    public static final String TARGET = "target/results/ch01/";
    /** The path to the resulting PDF file. */
    public static final String DEST = String.format("%stest-03.pdf", TARGET);

    /**
     * The main method of this example.
     *
     * @param args no arguments are needed to run this example.
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public static void main(String[] args) throws IOException {
        LicenseKey.loadLicenseFile("C://Users//Sparks//Desktop//itextkey-0.xml");
        File file = new File(TARGET);
        file.mkdirs();
        new C01E03_HelloWorld().createPdf(BASEURI, SRC, DEST);
    }

    /**
     * Creates the PDF file.
     *
     * @param baseUri the base URI
     * @param src the path to the source HTML file
     * @param dest the path to the resulting PDF
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public void createPdf(String baseUri, String src, String dest) throws IOException {
        HtmlConverter.convertToPdf(new File(src), new File(dest));
    }
}

输出PDF文件为here。它应该具有类似于HTML页面中的格式。

任何建议都会有所帮助。

0 个答案:

没有答案