国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java中Itext生成Pdf,并給PdfCell添加圖片

這篇具有很好參考價(jià)值的文章主要介紹了Java中Itext生成Pdf,并給PdfCell添加圖片。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Java中Itext生成Pdf,并給PdfCell添加圖片

1. 頁眉頁腳類 _ 根據(jù)實(shí)際情況使用,如不需要可忽略此步

package com.mediinfo.test;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.Date;

@Slf4j
public class PdfHeaderFooter extends PdfPageEventHelper {

    private final static String FONT_PATH = "c:\\windows\\fonts\\SIMSUN.TTC,1";
    private final static String logoPath = "D:\\1.jpg";

    //總頁碼使用的模板對(duì)象
    public PdfTemplate totalNumTemplate = null;

    /**
     * 重寫頁面結(jié)束時(shí)間  分別添加頁眉、頁腳
     */
    public void onEndPage(PdfWriter writer, Document docment){
        try{
            this.addPageHeader(writer, docment);
        }catch(Exception e){
            log.error("添加頁眉出錯(cuò)", e);
        }

        try{
            this.addPageFooter(writer, docment);
        }catch(Exception e){
            log.error("添加頁腳出錯(cuò)", e);
        }
    }

    /**
     * 頁眉
     */
    private void addPageHeader(PdfWriter writer, Document docment) throws IOException, DocumentException {
        BaseFont BASE_FONT = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);

        //創(chuàng)建字體
        Font textFont = new Font(BASE_FONT, 10f);

        //兩列  一列l(wèi)ogo  一列項(xiàng)目簡(jiǎn)稱   有Logo時(shí)添加圖片,沒有時(shí)添加個(gè)空值,避免報(bào)錯(cuò)
        PdfPTable table = new PdfPTable(2);
        //設(shè)置表格寬度 A4紙寬度減去兩個(gè)邊距  比如我一邊30  所以減去60
        table.setTotalWidth(PageSize.A4.getWidth()-60);

        //logo
        //創(chuàng)建圖片對(duì)象
        try {
            Image logo = Image.getInstance(logoPath);
            //創(chuàng)建一個(gè)Phrase對(duì)象 再添加一個(gè)Chunk對(duì)象進(jìn)去  Chunk里邊是圖片
            Phrase logoP = new Phrase("", textFont);
            //自己調(diào)整偏移值 主要是y軸值
            logoP.add(new Chunk(logo, 0, -5));
            PdfPCell logoCell = new PdfPCell(logoP);
            //只保留底部邊框和設(shè)置高度
            logoCell.disableBorderSide(13);
            logoCell.setFixedHeight(20);
            table.addCell(logoCell);
        }catch (IOException e){
            Phrase nameP = new Phrase("", textFont);
            PdfPCell nameCell = new PdfPCell(nameP);
            nameCell.disableBorderSide(13);
            nameCell.setFixedHeight(20);
            table.addCell(nameCell);
        }

        Phrase nameP = new Phrase("頁眉右上角顯示的內(nèi)容", textFont);
        PdfPCell nameCell = new PdfPCell(nameP);
        //只保留底部邊框和設(shè)置高度 設(shè)置水平居右和垂直居中
        nameCell.disableBorderSide(13);
        nameCell.setFixedHeight(20);
        nameCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(nameCell);

        //再把表格寫到頁眉處  使用絕對(duì)定位
        table.writeSelectedRows(0, -1, 30, PageSize.A4.getHeight()-5, writer.getDirectContent());
    }

    /**
     * 頁腳
     */
    private void addPageFooter(PdfWriter writer, Document docment) throws DocumentException, IOException {

        BaseFont BASE_FONT = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);
        //創(chuàng)建字體
        Font textFont = new Font(BASE_FONT, 10f);

        //三列  一列導(dǎo)出人  一列頁碼   一列時(shí)間
        PdfPTable table = new PdfPTable(3);
        //設(shè)置表格寬度 A4紙寬度減去兩個(gè)邊距  比如我一邊30  所以減去60
        table.setTotalWidth(PageSize.A4.getWidth()-60);
        //僅保留頂部邊框
        table.getDefaultCell().disableBorderSide(14);
        table.getDefaultCell().setFixedHeight(40);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

        //導(dǎo)出人
        table.addCell(new Phrase("admin", textFont));

        //頁碼
        //初始化總頁碼模板
        if(null == totalNumTemplate){
            totalNumTemplate = writer.getDirectContent().createTemplate(30, 16);
        }
        //再嵌套一個(gè)表格 一左一右  左邊當(dāng)前頁碼 右邊總頁碼 
        PdfPTable pageNumTable = new PdfPTable(2);
        pageNumTable.setTotalWidth(new float[]{80f, 80f});
        pageNumTable.setLockedWidth(true);
        pageNumTable.setPaddingTop(-5f);
        //第一列居右
        pageNumTable.getDefaultCell().disableBorderSide(15);
        pageNumTable.getDefaultCell().setFixedHeight(16);
        pageNumTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        pageNumTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM);
        pageNumTable.addCell(new Phrase(writer.getPageNumber()+" / ", textFont));
        //第二列居左
        Image totalNumImg = Image.getInstance(totalNumTemplate);
        totalNumImg.setPaddingTop(-5f);
        pageNumTable.getDefaultCell().setPaddingTop(-18f);
        pageNumTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        pageNumTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
        pageNumTable.addCell(totalNumImg);
        //把頁碼表格添加到頁腳表格
        table.addCell(pageNumTable);

        //日期
        table.addCell(new Phrase(String.valueOf(new Date()), textFont));

        //再把表格寫到頁腳處  使用絕對(duì)定位
        table.writeSelectedRows(0, -1, 30, 40, writer.getDirectContent());
    }

    /**
     * 文檔關(guān)閉事件
     */
    @SneakyThrows
    @Override
    public void onCloseDocument(PdfWriter writer, Document docment){
        BaseFont BASE_FONT = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);
        //創(chuàng)建字體
        Font textFont = new Font(BASE_FONT, 10f);
        //將最后的頁碼寫入到總頁碼模板
        String totalNum = writer.getPageNumber() + "頁";
        totalNumTemplate.beginText();
        totalNumTemplate.setFontAndSize(BASE_FONT, 5f);
        totalNumTemplate.showText(totalNum);
        totalNumTemplate.setHeight(16f);
        totalNumTemplate.endText();
        totalNumTemplate.closePath();
    }
}

2. Pdf生成 [ PdfCell添加圖片參考createHardwarePDF方法的第九行nineRowTalbe ]

package com.mediinfo.test;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.*;

public class PdfUtils {

    //使用例子
    public static void main(String[] args) throws Exception {
        createHardwarePDF("d:/test.pdf");
    }

    /**
     * 新建以下兩個(gè)方法,創(chuàng)建表格內(nèi)的字體和樣式的方法
     *
     * @param str  內(nèi)容
     * @param font 字體對(duì)象
     * @param high 表格高度
     * @return
     * @Param alignCenter 是否水平居中
     * @Param alignMidde  是否垂直居中
     */
    private static PdfPCell mircoSoftFont(String str, Font font, int high, boolean alignCenter, boolean alignMidde) {
        PdfPCell pdfPCell = new PdfPCell(new Phrase(str, font));
        pdfPCell.setMinimumHeight(high);
        pdfPCell.setUseAscender(true); // 設(shè)置可以居中
        if (alignCenter) {
            pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 設(shè)置水平居中
        }
        if (alignMidde) {
            pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 設(shè)置垂直居中
        }
        return pdfPCell;
    }

    /**
     * @param str  字符串
     * @param font 字體
     * @param high 表格高度
     * @return
     * @Param alignCenter 是否水平居中
     * @Param alignMidde  是否垂直居中
     * @Param haveColor 是否有背景色(灰色)
     */
    private static PdfPCell mircoSoftFont(String str, Font font, int high, boolean alignCenter, boolean alignMidde, boolean haveColor) {
        PdfPCell pdfPCell = new PdfPCell(new Phrase(str, font));
        pdfPCell.setMinimumHeight(high);
        pdfPCell.setUseAscender(true); // 設(shè)置可以居中
        if (alignCenter) {
            pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 設(shè)置水平居中
        }
        if (alignMidde) {
            pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 設(shè)置垂直居中
        }
        if (haveColor) {
            //顏色代碼 RGB
            pdfPCell.setBackgroundColor(new BaseColor(217, 217, 217));
        }
        return pdfPCell;
    }

    /*
    將圖片插入到PdfCell
     */
//    private static PdfPCell mircoSoftFont(byte[] iamgeBytes, int high) throws Exception {
    private static PdfPCell ImageSet(int high) throws Exception {
        byte[] fileByte = toByteArray("D:\\2.jpg");
        Jpeg jpeg = new Jpeg(fileByte);
        jpeg.scaleAbsolute(70, 50);

        PdfPCell pdfPCell = new PdfPCell(jpeg);
        pdfPCell.setMinimumHeight(high);
        pdfPCell.setUseAscender(true); // 設(shè)置可以居中
        pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 設(shè)置水平居中
        pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 設(shè)置垂直居中
        return pdfPCell;
    }


    /*
    生成Pdf文檔
     */
    public static void createHardwarePDF(String outputPath) throws Exception {
        //新建文檔對(duì)象,頁大小為A4紙,然后設(shè)置4個(gè)邊距
        Document document = new Document(PageSize.A4, 20, 20, 30, 30);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputPath));

        //創(chuàng)建字體
        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        //字體對(duì)象
        Font size14font = new Font(baseFont, 14, Font.NORMAL);  //大小為14的正常字體
        Font size10font = new Font(baseFont, 10, Font.BOLD); //大小為10的粗體
        document.open();

        // 添加頁眉和頁碼  Add By Zhaof 2022-11-16 實(shí)測(cè)可用
        // 要修改頁眉頁腳顯示的內(nèi)容,直接修改PdfHeaderFooterEvent對(duì)象的頁眉頁腳內(nèi)容即可;
        PdfHeaderFooter event = new PdfHeaderFooter();
        writer.setPageEvent(event);

        //添加標(biāo)題
        PdfPTable tableName = new PdfPTable(1);
        tableName.setWidthPercentage(90);  //設(shè)置標(biāo)題長(zhǎng)度占紙張比例

        PdfPCell titleCell = mircoSoftFont("個(gè)人信息", size14font, 80, true, true);
        titleCell.disableBorderSide(15);
        tableName.addCell(titleCell);
        document.add(tableName);
        //添加第二行的數(shù)據(jù)
        PdfPTable secondRowTable = new PdfPTable(3); //三列的意思
        secondRowTable.setWidthPercentage(90);
        //這里的數(shù)組長(zhǎng)度是上面創(chuàng)建的列數(shù),數(shù)組的總和為1,就是按比例劃分的意思
        secondRowTable.setTotalWidth(new float[]{0.18f, 0.32f, 0.5f});
        secondRowTable.addCell(mircoSoftFont(" 姓名: ", size10font, 50, false, true));
        secondRowTable.addCell(mircoSoftFont("李曉明", size10font, 50, false, true));
        secondRowTable.addCell(mircoSoftFont(" 出生日期: 1994年3月14日", size10font, 50, false, true));
        document.add(secondRowTable);
        //第三行數(shù)據(jù)
        PdfPTable thirdRowTable = new PdfPTable(3);
        thirdRowTable.setWidthPercentage(90);
        thirdRowTable.setTotalWidth(new float[]{0.18f, 0.32f, 0.5f});
        thirdRowTable.addCell(mircoSoftFont(" 名族:", size10font, 50, false, true));
        thirdRowTable.addCell(mircoSoftFont("漢族", size10font, 50, false, true));
        thirdRowTable.addCell(mircoSoftFont(" 聯(lián)系電話: 13888880000", size10font, 50, false, true));
        document.add(thirdRowTable);
        //第四行數(shù)據(jù)
        PdfPTable fourthRowTable = new PdfPTable(2);
        fourthRowTable.setWidthPercentage(90);
        fourthRowTable.setTotalWidth(new float[]{0.66f, 0.34f});
        fourthRowTable.addCell(mircoSoftFont(" 個(gè)人描述 :", size10font, 175, false, false));
        fourthRowTable.addCell(mircoSoftFont("個(gè)人特長(zhǎng) :", size10font, 175, false, false));
        document.add(fourthRowTable);
        //第五行
        PdfPTable fifthDetailName = new PdfPTable(1);
        fifthDetailName.setWidthPercentage(90);
        fifthDetailName.addCell(mircoSoftFont("獲獎(jiǎng)記錄 :", size14font, 50, true, true));
        document.add(fifthDetailName);
        //第六行
        PdfPTable sisthRowTalbe = new PdfPTable(1);
        sisthRowTalbe.setWidthPercentage(90);
        sisthRowTalbe.addCell(mircoSoftFont(" 聯(lián)系地址: " + "廣東省廣州市天河區(qū)XXXXXXXXXXXXXXXXXX", size10font, 50, false, true));
        document.add(sisthRowTalbe);
        PdfPTable seventhRowTalbe = new PdfPTable(1);
        seventhRowTalbe.setWidthPercentage(90);
        seventhRowTalbe.addCell(mircoSoftFont(" 畢業(yè)院校 ", size14font, 60, true, true));
        document.add(seventhRowTalbe);
        //第八行
        PdfPTable eiththRowTalbe = new PdfPTable(3);
        eiththRowTalbe.setWidthPercentage(90);
        eiththRowTalbe.setTotalWidth(new float[]{0.3f, 0.5f, 0.2f});
        eiththRowTalbe.addCell(mircoSoftFont(" 畢業(yè)學(xué)校", size10font, 50, true, true, true));
        eiththRowTalbe.addCell(mircoSoftFont(" 就讀日期", size10font, 50, true, true, true));
        eiththRowTalbe.addCell(mircoSoftFont(" 聯(lián)系人", size10font, 50, true, true, true));
        document.add(eiththRowTalbe);
        //接下來加List
        String school = "XXX學(xué)校";
        String time = "201909  -  2022-06";
        String name = "陳某";
        for (int i = 0; i < 2; i++) {
            PdfPTable tempTable = new PdfPTable(3);
            tempTable.setWidthPercentage(90);
            tempTable.setTotalWidth(new float[]{0.3f, 0.5f, 0.2f});
            tempTable.addCell(mircoSoftFont(school, size10font, 50, true, true));
            tempTable.addCell(mircoSoftFont(time, size10font, 50, true, true));
            tempTable.addCell(mircoSoftFont(name, size10font, 50, true, true));
            document.add(tempTable);
        }

        // 第九行,添加圖片
        PdfPTable nineRowTalbe = new PdfPTable(3);
        nineRowTalbe.setWidthPercentage(90);
        nineRowTalbe.setTotalWidth(new float[]{0.3f, 0.5f, 0.2f});
        nineRowTalbe.addCell(mircoSoftFont(" test1", size10font, 50, true, true));
        nineRowTalbe.addCell(mircoSoftFont(" test222", size10font, 50, true, true));
        nineRowTalbe.addCell(ImageSet(50));   // 給PdfCell添加圖片
        document.add(nineRowTalbe);

        document.close();
        writer.close();
    }



    public static byte[] toByteArray(String filename) throws IOException {

        File f = new File(filename);
        if (!f.exists()) {
            throw new FileNotFoundException(filename);
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length());
        BufferedInputStream in = null;
        try {
            in = new BufferedInputStream(new FileInputStream(f));
            int buf_size = 1024;
            byte[] buffer = new byte[buf_size];
            int len = 0;
            while (-1 != (len = in.read(buffer, 0, buf_size))) {
                bos.write(buffer, 0, len);
            }
            return bos.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            bos.close();
        }
    }




}

3. 實(shí)現(xiàn)效果如下圖

java生成pdf文件添加圖片,Java相關(guān),java,pdf文章來源地址http://www.zghlxwxcb.cn/news/detail-571175.html

到了這里,關(guān)于Java中Itext生成Pdf,并給PdfCell添加圖片的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【生成PDF】【JAVA】純后臺(tái)生成Echarts圖片,并將圖片生成到PDF文檔

    【生成PDF】【JAVA】純后臺(tái)生成Echarts圖片,并將圖片生成到PDF文檔

    目錄 前言 一、如何后臺(tái)生成Echarts圖片? 1.PhantomJS 2.PhantomJS的下載 ?3.用phantomjs調(diào)用echarts-converts.js生成圖片 二、Java如何將Echarts圖生成到PDF 1.生成PDF依賴 2.Java代碼測(cè)試?yán)樱??3.測(cè)試結(jié)果? ?三、下載生成的PDF ReportFormUtil 提示:本文僅用于記錄日常,多有不足,僅供參考。

    2024年02月09日
    瀏覽(30)
  • JAVA PDF 給PDF添加文字/圖片水?。ㄖ付▋?nèi)容),并且設(shè)置位置

    JAVA PDF 給PDF添加文字/圖片水印(指定內(nèi)容),并且設(shè)置位置

    提示:看完這個(gè)簡(jiǎn)單的demo 后就知道怎樣去操作一個(gè)PDF了 文章目錄 前言 一、前提準(zhǔn)備 二、使用步驟 1.引入庫 2.以下是部分代碼的作用 總結(jié) 提示:操作PDF其實(shí)是一件很簡(jiǎn)單的事情,比一般的CRUD都簡(jiǎn)單 例如:我們拿到了一個(gè)需求,我需要給這個(gè)PDF設(shè)置一個(gè) 電子簽名 ( 就是一

    2024年04月23日
    瀏覽(29)
  • 【itext7】itext7操作PDF文檔之創(chuàng)建PDF文檔、加載PDF文檔、添加空白頁、操作PDF頁面、itext中的常見類及其方法

    這篇文章,主要介紹itext7操作PDF文檔之創(chuàng)建PDF文檔、加載PDF文檔、添加空白頁、操作PDF頁面、itext中的常見類及其方法。 目錄 一、itext7操作PDF 1.1、itext7介紹 1.2、引入itext-core依賴 1.3、創(chuàng)建PDF文檔 1.4、加載PDF文檔 1.5、操作PDF頁面 1.6、添加空白頁面 二、itext常見類和方法 2.1、

    2024年02月16日
    瀏覽(20)
  • Java 生成各種 PDF 實(shí)戰(zhàn)方案(圖片、模板、表格)

    Java 生成各種 PDF 實(shí)戰(zhàn)方案(圖片、模板、表格)

    本篇文章的重點(diǎn)還是在講通過java生成pdf,其實(shí)如果是單純的模板填充挺簡(jiǎn)單的,但是又要填充模板還要?jiǎng)討B(tài)生成表格就比較麻煩了,因?yàn)槿绻谀0逯挟嫳砀竦目蛉ド傻脑?,超過模板框的位置就會(huì)隱藏,我剛接到需求的時(shí)候也是有點(diǎn)難受,在網(wǎng)上也是找了大量的資料,研究

    2024年02月02日
    瀏覽(23)
  • 【Java】制作pdf模板使用后端程序填充字段生成pdf或者圖片

    【Java】制作pdf模板使用后端程序填充字段生成pdf或者圖片

    自行下載安裝; 打開pdf文件,表單-添加或編輯域 添加文本域,調(diào)整大小,可以編輯域的名字,默認(rèn)fill_1這種名字。域鼠標(biāo)右鍵-屬性,可以調(diào)整字體大小等樣式,編輯好還可以鎖定; 編輯好保存,這個(gè)pdf文件就可以當(dāng)模板使用了; 防止中文亂碼,需要在網(wǎng)上下載字體ttf文件

    2024年01月21日
    瀏覽(26)
  • 【Java】OpenPDF、iText、PDFBox 是三種常用的 PDF 處理庫

    OpenPDF、iText、PDFBox 是三種常用的 PDF 處理庫,它們各自具有獨(dú)特的優(yōu)勢(shì)和特點(diǎn),同時(shí)也存在一些局限性和差異。本文將對(duì)這四種庫進(jìn)行詳細(xì)的比較,并通過代碼示例來展示它們的使用。 1、OpenPDF OpenPDF 是一個(gè)用于創(chuàng)建和編輯 PDF 文檔的 Java 庫,它基于 iText 庫的一個(gè)分支,提供

    2024年02月09日
    瀏覽(34)
  • java中使用Jsoup和Itext實(shí)現(xiàn)將html轉(zhuǎn)換為PDF

    java中使用Jsoup和Itext實(shí)現(xiàn)將html轉(zhuǎn)換為PDF

    1.在build.gradle中安裝所需依賴: 2.創(chuàng)建工具類,實(shí)現(xiàn)轉(zhuǎn)換方法 3.base64過濾類: 4.字體類代碼,window用戶可在C:windowsfont中尋找自己所需字體即可。我這里用的為黑體: simhei.ttf 效果如下: html頁面預(yù)覽: pdf頁面預(yù)覽: ? ?

    2024年02月14日
    瀏覽(23)
  • 使用itext7為pdf文檔添加水印

    iText7是一款功能強(qiáng)大的開源PDF處理庫,用于創(chuàng)建、編輯和處理PDF文檔。相比于iTextSharp,iText7具有更先進(jìn)的功能和更好的性能。 添加水印是iText7的一個(gè)常見應(yīng)用場(chǎng)景。水印可以用于保護(hù)文檔的版權(quán),標(biāo)識(shí)文檔的狀態(tài)或來源等。使用iText7添加水印可以通過以下步驟實(shí)現(xiàn): 導(dǎo)入

    2024年04月22日
    瀏覽(27)
  • Itext生成pdf文件,html轉(zhuǎn)pdf時(shí)中文一直顯示不出來

    Itext生成pdf文件,html轉(zhuǎn)pdf時(shí)中文一直顯示不出來

    嘗試好多種方式,最后可能是跟字體有關(guān)系 字體設(shè)置為C:/Windows/Fonts/simhei.ttf? 黑體,同時(shí)html頁面上樣式要添加 pdf生成方式參考項(xiàng)目:E:myfilesprojectgithubdemo-html2pdf 字體問題參考文章:https://blog.51cto.com/u_15127651/4527950 最后完美解決字體問題!!

    2024年02月20日
    瀏覽(19)
  • Java使用ftl模板文件生成Word,以及Word轉(zhuǎn)換圖片或Pdf工具類

    Java使用ftl模板文件生成Word,以及Word轉(zhuǎn)換圖片或Pdf工具類

    一、寫在前面 最近在項(xiàng)目中使用打印功能,發(fā)現(xiàn)這個(gè)功能我已經(jīng)寫過多次了,下面這個(gè)文章的發(fā)步日期在2020年,不得不感慨時(shí)間之快啊。 https://blog.csdn.net/weixin_43238452/article/details/109636200?spm=1001.2014.3001.5501 下面介紹一下應(yīng)用場(chǎng)景:這次項(xiàng)目依舊是springboot項(xiàng)目,使用ftl模版生

    2024年02月15日
    瀏覽(38)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包