欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

HTML轉(zhuǎn)成pdf

HTML轉(zhuǎn)成pdf:
<!-- pdf 相關(guān)jar包 -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.5.13</version>
</dependency>

欒城網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)自2013年創(chuàng)立以來到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。

public class PdfUtil2 {
//根據(jù)html文件生成pdf
public static void parseHtml2PdfByFilePath(String pdfFilePath, String htmlFilePath, String fontPath) {
Document document = new Document();
PdfWriter writer = null;
FileOutputStream fileOutputStream = null;
FileInputStream fileInputStream = null;
try {
fileOutputStream = new FileOutputStream(pdfFilePath);
writer = PdfWriter.getInstance(document, fileOutputStream);
// 設(shè)置底部距離60,解決重疊問題
document.setPageSize(PageSize.A4);
document.setMargins(50, 45, 50, 60);
document.setMarginMirroring(false);
document.open();
StringBuffer sb = new StringBuffer();
fileInputStream = new FileInputStream(htmlFilePath);
BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream, "UTF-8"));
String readStr = "";
while ((readStr = br.readLine()) != null) {
sb.append(readStr);
}
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(sb.toString().getBytes("Utf-8")), null, Charset.forName("UTF-8"), new MyFontProvider(fontPath));
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != document) {
document.close();
}
if (null != writer) {
writer.close();
}
if (null != fileInputStream) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != fileOutputStream) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

/**
 * 根據(jù)html內(nèi)容生成pdf
 *
 * @param pdfFilePath pdf文件存儲位置
 * @param htmlcontent html內(nèi)容
 * @param fontPath 字體路徑
 * @throws DocumentException
 * @throws IOException
 */

public static void parseHtml2PdfByString(String pdfFilePath, String htmlcontent, String fontPath) {
    Document document = new Document();
    PdfWriter writer = null;
    try {
        writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
        // 設(shè)置底部距離60,解決重疊問題
        document.setPageSize(PageSize.A4);
        document.setMargins(50, 45, 50, 60);
        document.setMarginMirroring(false);

        document.open();
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("Utf-8")), null, Charset.forName("UTF-8"), new MyFontProvider(fontPath));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (null != document) {
            document.close();
        }
        if (null != writer) {
            writer.close();
        }
    }
}

public static void main(String[] args) {
    try {
        // 本地
        String htmlFile = "D:\\1.html";
        String pdfFile = "D:\\test2.pdf";
        String fontPath = "D:\\simsun.ttf";
        String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋體\">" + "<h2>Test</h2><p>測試中文Hello World</p></body></html>";
        //parseHtml2PdfByString(pdfFile,htmlContent,fontPath);
        parseHtml2PdfByFilePath(pdfFile,htmlFile,fontPath);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

/**

  • html中文字體設(shè)置類
  • @ClassName MyFontProvider
  • @Description
    */
    public class MyFontProvider extends XMLWorkerFontProvider {

    private String fontPath;

    public MyFontProvider(String filePath) {
    this.fontPath = filePath;
    }

    @Override
    public Font getFont(final String fontname, final String encoding, final boolean embedded, final float size, final int style, final BaseColor color) {
    BaseFont bf = null;
    try {
    bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    } catch (DocumentException | IOException e) {
    e.printStackTrace();
    }
    Font font = new Font(bf, size, style, color);
    font.setColor(color);
    return font;
    }
    }

分享文章:HTML轉(zhuǎn)成pdf
當(dāng)前鏈接:http://aaarwkj.com/article42/pdpjhc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、全網(wǎng)營銷推廣、網(wǎng)站設(shè)計、網(wǎng)站改版、網(wǎng)站內(nèi)鏈、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
韩国黄色三级一区二区| 麻豆片免费观看在线看| 一区二区中文字幕精品| 另类激情综合在线观看| 色婷婷丝袜一区网站| 蜜桃臀内射一区二区三区| 熟妇人妻精品一区二区| 在线看黄视频网站永久免费| 99精品国产中文字幕| 久久综合热这里只有精品| 欧美大片免费高清观看| 日韩大片一区二区三区在线观看| 亚洲第六页亚洲第一页| 抱着操才爽的免费视频观看| 成人性生活毛片免费视频| 亚洲少妇插进去综合网| 国产一级特黄大片特爽| 天堂在线av免费观看| 尤物视频在线观看羞羞| 国产青草视频免观看视频| 亚洲第一狼人天堂在线| 熟女另类视频在线观看| 国产精品久久久久精品综合| 日本高清精品视频在线| 性生活自制视频网站麻豆| dy888午夜福利精品国产97| 亚洲一区日本一区二区| 亚洲精品成人久久网| 韩国午夜福利视频网站| 日韩精品在线观看电影| 日本一区二区高清在线观看| 成人在线午夜你懂的视频| 亚洲三级成人一区在线| 亚洲一区免费在线视频| 国产三级精品在线免费| 蜜臀av人妻一区二区三区| av亚洲天堂免费观看| 亚洲久久精品中文字幕| 国产成人亚洲精品乱码| 九九热精品视频美谷朱里| 蜜桃视频在线视频免费观看|