Android使用itextpdf操作PDF文档

1、导入jar包:

  • itext-asian.jar
  • itextpdf-5.5.8.jar

Paragraph 和 Phrase 的区别:

在 iTextPDF 库中,Paragraph 和 Phrase 是用于创建和组织文本内容的两个不同的类。

Paragraph(段落):
Paragraph 是一个块级元素,用于创建一个段落,并可以包含多个短语(Phrase)。它是一个有自己的对齐方式、缩进和间距的独立文本块。Paragraph 类提供了更高级的文本布局和格式化功能。

Paragraph paragraph = new Paragraph("这是一个段落");
paragraph.setAlignment(Element.ALIGN_CENTER); // 设置对齐方式
paragraph.setIndentationLeft(20); // 设置左缩进
paragraph.setSpacingAfter(10); // 设置段后间距

Phrase(短语):
Phrase 是一个内联元素,用于创建一个短语,它可以包含文本、字体样式和 Chunk(文本块)。Phrase 是 Paragraph 的组成部分,可以被添加到 Paragraph 中。

Phrase phrase = new Phrase("这是一个短语");
Font boldFont = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
Chunk chunk = new Chunk("加粗文本", boldFont);
phrase.add(chunk);

总结:

  • Paragraph 用于创建段落,是一个独立的文本块,可以设置对齐方式、缩进和间距等。
  • Phrase 用于创建短语,是一个内联元素,可以包含文本、字体样式和 Chunk。Phrase 可以被添加到 Paragraph
    中,用于组织和格式化文本内容。

2、使用示例:


    private void createPdf(RecordEntity recordEntity, String hospitalNameStr, String numberStr, String resultStr) {
        FileUtils.copyFileIfNeed(getContext());//复制字体文件

        Executors.newSingleThreadExecutor().execute(new Runnable() {
            
            public void run() {

                long createTime = DateUtils.formatTimeToLong(recordEntity.getCreateTime(), Constants.TIME_FORMAT_UTC);
                PdfUtil pdfUtil = new PdfUtil();
                try {
                    pdfUtil.buildPdf(recordEntity, hospitalNameStr, numberStr, resultStr).build();

                    getActivity().runOnUiThread(new Runnable() {
                        
                        public void run() {
                            ToastUtil.showShortToast("生成成功");
                            File lastFile = FileUtils.getLastPdfFile(createTime);
                            }
                        }
                    });
                } catch (Exception e) {
                    Log.w("caowj", "生成PDF报告异常:" + e.getMessage());
                } finally {
                    disProgressDialog();
                    try {
                        pdfUtil.dispose();
                    } catch (Exception e) {
                        Log.w("caowj", "pdf流关闭异常:" + e.getMessage());
                    }
                }
            }
        });
    }

3、pdf工具类:

package com.kl.common_base.utils;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.UiThread;
import android.util.Log;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
import com.kl.common_base.R;
import com.kl.common_base.base.BaseApplication;
import com.kl.common_base.bean.NoteEntity;
import com.kl.common_base.bean.RecordEntity;
import com.kl.common_base.constants.Constants;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Objects;

public class PdfUtil {
    private File file;
    private Font fontTitle1;
    private Font fontTitle2;
    private Font fontTitle3;
    //    private Font fontText;
//    private Font fontText2;
//    private Font fontText3;
    private Document doc;
    private PdfWriter writer;
    private FileOutputStream fos;
//    public static final String PDF_ROTE_PATH = BaseApplication.getApplication().getExternalFilesDir("pdf").getAbsolutePath();
//    public final String MS = "ms";
//    public final String BPM = "bpm";
//    public final String MS_2 = "ms²";
//    private int minValue = 0;
//    private int cellHeight = 25;

    /**
     * 创建和分享pdf
     * 要在子线程执行
     */
    
    public PdfUtil buildPdf(RecordEntity recordEntity, String hospitalNameStr, String numberStr, String resultStr) throws Exception {
        long createTime = DateUtils.formatTimeToLong(recordEntity.getCreateTime(), Constants.TIME_FORMAT_UTC);
        file = FileUtils.createPdfFile(createTime);
        //1创建document实例,无参默认A4纸
        doc = new Document(PageSize.A4, 5f, 5f, 25f, 15f);//创建一个document对象
        fos = new FileOutputStream(file); //pdf_address为Pdf文件保存到sd卡的路径
        //2创建Writer实例,pdf直接使用的DocWriter的实现类PdfWriter
        writer = PdfWriter.getInstance(doc, fos);
        writer.setPageEvent(new HeaderAndFooter());
        doc.open();
//        doc.setPageCount(1);
        fontTitle1 = setChineseFont(26, Font.BOLD, Constants.FILE_PATH_FONT);
//        fontTitle1.setColor(76, 199, 191);
        fontTitle2 = setChineseFont(16, Font.BOLD, Constants.FILE_PATH_FONT);
//        fontTitle2.setColor(76, 199, 191);
        fontTitle3 = setChineseFont(12, Font.NORMAL, Constants.FILE_PATH_FONT);
        fontTitle3.setColor(76, 199, 191);
//        fontText = setChineseFont(12, Font.NORMAL, fontPath);
//        fontText2 = setChineseFont(8, Font.NORMAL, fontPath);
//        fontText3 = setChineseFont2(12, Font.NORMAL, fontPath);
        Paragraph paragraph = new Paragraph(hospitalNameStr, fontTitle1);
        paragraph.setLeading(paragraph.getLeading() - 10);//行距
        paragraph.setAlignment(Element.TITLE);//设置文字水平居中
        paragraph.setSpacingBefore(26);
        doc.add(paragraph);
        paragraph = new Paragraph("心音图报告", fontTitle2);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.TITLE);//设置文字水平居中
        paragraph.setSpacingBefore(20);
        doc.add(paragraph);
        doc.add(Chunk.NEWLINE);//换行
        doc.add(Chunk.NEWLINE);
        NoteEntity mNoteEntity = JsonUtils.formJsonString(recordEntity.getNote(), NoteEntity.class);
        paragraph = new Paragraph("姓名:" + mNoteEntity.getName(), fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);//行距
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        paragraph = new Paragraph("年龄:" + mNoteEntity.getAge(), fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        Resources resource = BaseApplication.getApplication().getResources();
        String gender = mNoteEntity.getGender() == 1 ? resource.getString(R.string.gender_female) : resource.getString(R.string.gender_male);
        paragraph = new Paragraph("性别:" + gender, fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        paragraph = new Paragraph("门诊/住院号:" + numberStr, fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        paragraph = new Paragraph("备注信息:" + mNoteEntity.getComment(), fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        // 图片
//        Image image2 = Image.getInstance(new URL("http://c.hiphotos.baidu.com/image/pic/item/9c16fdfaaf51f3de1e296fa390eef01f3b29795a.jpg"));
//        //将图片2添加到pdf文件中
//        doc.add(image2);
        doc.add(Chunk.NEWLINE);
        String fileDir = Constants.FILE_PATH_DATA + "/" + DateUtils.getFormatDate(createTime, Constants.TIME_FORMAT_FILE) + "/wave_view/";
        Log.d("caowj", "截图目录:" + fileDir);
        File file = new File(fileDir);
        if (file.exists() && file.isDirectory()) {
//            doc.newPage();
            float scale = (SizeUtils.getScreenWidth() * 1.0f - SizeUtils.dp2px(20)) / SizeUtils.dp2px(175f);
            float imgWidth = PageSize.A4.getWidth() - 10f;
            float imgHeight = imgWidth / scale;
            File flist[] = file.listFiles();
            for (File f : flist) {
                Log.d("caowj", "截图=" + f.getName());
                Image image = Image.getInstance(f.getAbsolutePath());
//                image.scaleAbsolute(120, 45);
//                image.scaleAbsoluteHeight(100f); // 将图像缩放到绝对高度。
//                image.scaleAbsoluteWidth(pageWidth); // 将图像缩放到绝对宽度。
//                image.scalePercent(30f);
                image.scaleAbsolute(imgWidth, imgHeight);
                image.setAlignment(Element.ALIGN_LEFT);
                image.setIndentationLeft(2);
                doc.add(image);
                doc.add(Chunk.NEWLINE);
            }
        }
        doc.add(Chunk.NEWLINE);
        paragraph = new Paragraph("听诊总时长:" + DateUtils.getFormatAudioMinSec(recordEntity.getTotalTime()), fontTitle3);
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        paragraph = new Paragraph("结论:" + resultStr, fontTitle3);
//        paragraph.setLeading(paragraph.getLeading() - 10);
//        paragraph.setLeading(1.5f);
        paragraph.setMultipliedLeading(1.2f);
        paragraph.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
        paragraph.setSpacingBefore(14);
        paragraph.setIndentationLeft(14);
        doc.add(paragraph);
        doc.add(Chunk.NEWLINE);//换行
        doc.add(Chunk.NEWLINE);//换行
        doc.add(Chunk.NEWLINE);//换行
        doc.add(new Paragraph("\n"));
        doc.add(new Paragraph("\n"));
        doc.add(new Paragraph("\n"));
        doc.add(new Paragraph("\n"));
        Image image = Image.getInstance(getSignImage());
        image.scaleAbsolute(50, 50); // 设置图像的大小
        paragraph = new Paragraph("医生签字:", fontTitle3);
        Log.d("caowj", "行间距:" + paragraph.getLeading());
        paragraph.add(new Chunk(image, 10, -20)); // 将图像添加到短语中
        paragraph.setLeading(paragraph.getLeading() - 10);
        paragraph.setAlignment(Element.ALIGN_CENTER);//设置文字水平居中
//        paragraph2.setSpacingBefore(20);// 前间距
//        paragraph2.setSpacingAfter(80);// 后间距
        paragraph.setIndentationLeft(200f);// 右缩进
        doc.add(paragraph);
        doc.add(Chunk.NEWLINE);//换行
        doc.add(Chunk.NEWLINE);//换行
        doc.add(Chunk.NEWLINE);//换行
//        //设置属性
//        //标题
//        doc.addTitle("this is a title");
//        //作者
//        doc.addAuthor("H__D");
//        //主题
//        doc.addSubject("this is subject");
//        //关键字
//        doc.addKeywords("Keywords");
//        //创建时间
//        doc.addCreationDate();
//        //应用程序
//        doc.addCreator("hd.com");
//        //表格
//        float[] widths = {144, 113, 191};
//        PdfPTable table = new PdfPTable(widths);
//        table.setTotalWidth(458);
//        table.setHorizontalAlignment(Element.ALIGN_LEFT);
//        Object[][] datas = {{"区域", "总销售额(万元)", "总利润(万元)简单的表格"}, {"江苏省", 9045, 2256}, {"广东省", 3000, 690}};
//
//        for (int i = 0; i < datas.length; i++) {
//            for (int j = 0; j < datas[i].length; j++) {
//                PdfPCell pdfCell = new PdfPCell(); //表格的单元格
//                Paragraph paragraph3 = new Paragraph("" + datas[i][j], fontTitle1);
//                pdfCell.setPhrase(paragraph3);
//                table.addCell(pdfCell);
//            }
//        }
//
//        doc.add(table); //pdf文档中加入table
        return this;
    }

    private byte[] getSignImage() {
        Resources resource = BaseApplication.getApplication().getResources();
        Bitmap bitmap = BitmapFactory.decodeResource(resource, R.drawable.icon_collected);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
        byte[] bytes = outputStream.toByteArray();
//        outputStream.close();
        return bytes;
    }

    //
//    public PdfUtil createUserInfo(RecordBean patient, String hotName, boolean isNewPage, String pdfLogo) throws Exception {
//        if (isNewPage) {
//            doc.newPage();
            Image image = Image.getInstance(pdfLogo);
            image.scaleAbsolute(120, 45);
            image.setAlignment(Element.ALIGN_LEFT);
            image.setIndentationLeft(20);

            doc.add(image);
            doc.add(Chunk.NEWLINE);
//            Paragraph paragraph = new Paragraph("糖尿病心脏自主神经病变分析报告", fontTitle1);
//            paragraph.setLeading(paragraph.getLeading() - 10);
//            paragraph.setAlignment(Element.TITLE);//设置文字水平居中
//            paragraph.setSpacingBefore(20);
//            doc.add(paragraph);
//
//        }
//        doc.add(Chunk.NEWLINE);//换行
//        PdfPTable table = new PdfPTable(3);
//        String name = patient.getPatientName();
//        String gender = patient.getGender() == 0 ? "女" : "男";
//        String age = patient.getAge() + "岁";
//        String department = patient.getDepartment();
//        String admissionNo = patient.getAdmissionNo();
//        String bedNo = patient.getBedNo();
//        String[] type = {
//                "医院:" + hotName,
//                "姓名:" + name,
//                "性别:" + gender,
//                "年龄:" + age,
//                "科室:" + department,
//                "住院号:" + admissionNo,
//                "床号:" + bedNo
//        };
//        // 设置表格默认为无边框
//        table.getDefaultCell().setBorder(0);
//        for (int i = 0; i < type.length; i++) {
//            Paragraph userInfo = new Paragraph(type[i], fontText);
//            PdfPCell cell = new PdfPCell(userInfo);
//            if (i == 0) {
//                cell.setColspan(3);
//            }
//            cell.setBorder(Rectangle.NO_BORDER);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(cellHeight);
//            // 设置垂直居中
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.A);
//            table.addCell(cell);
//        }
//        table.setWidthPercentage(85);
        if(!isNewPage)
        table.setSpacingBefore(20);
//        doc.add(table);
//        return this;
//    }
//
//
//    /**
//     * 添加神经反射表格
//     */
//    public PdfUtil createReflectTable(double[] result0, double[] result1, double[] result2, float hrDiff) throws DocumentException {
//        doc.add(Chunk.NEWLINE);//换行
//        Paragraph paragraph = new Paragraph("心脏自主神经反射实验", fontTitle2);
//        paragraph.setLeading(paragraph.getLeading() - 15);
//        paragraph.setSpacingBefore(20);
//        paragraph.setAlignment(Element.TITLE);//设置文字水平居中
//        doc.add(paragraph);
//        doc.add(Chunk.NEWLINE);//换行
//        int[] width = {20, 14, 14, 21, 11, 14, 12};
//        PdfPTable table2 = new PdfPTable(7);
//        table2.setWidths(width);
//        String[] type1 = {" ", "最长RR(s)", "最短RR(s)", "比值/心率差", "正常", "临界", "异常"};
//        //创建表格第一行
//        for (int i = 0; i < type1.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type1[i], fontText), cellHeight);
//            table2.addCell(index);
//        }
//        //------------------------------------------------------------------
//        DecimalFormat decimalFormat = new DecimalFormat("0.000#");
//        String result0_0 = result0[0] <= minValue ? "--" : decimalFormat.format(result0[0]);
//        String result0_1 = result0[1] <= minValue ? "--" : decimalFormat.format(result0[1]);
//        String result0_2 = result0[2] <= minValue ? "--" : decimalFormat.format(result0[2]);
//
//        String[] type2 = new String[]{"卧立位心率变化", result0_0,
//                result0_1, result0_2, "≥1.04", "1.01-1.03", "≤1.00"};
//        //创建表格第二行
//        for (int i = 0; i < type2.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type2[i], fontText), cellHeight);
//            table2.addCell(index);
//        }
//        //------------------------------------------------------------------
//        double[] result1_copy = result1.clone();
//        Arrays.sort(result1_copy);
//        String result1_max1, result1_max2, result1_max3;
//        String result1_min1, result1_min2, result1_min3;
//
//        if (result1.length < 3) {
//            result1_max1 = "--";
//            result1_max2 = "--";
//            result1_max3 = "--";
//            result1_min1 = "--";
//            result1_min2 = "--";
//            result1_min3 = "--";
//        } else {
//            result1_max1 = result1_copy[result1.length - 1] <= minValue ? "--" : result1_copy[result1.length - 1] + "";
//            result1_max2 = result1_copy[result1.length - 2] <= minValue ? "--" : result1_copy[result1.length - 2] + "";
//            result1_max3 = result1_copy[result1.length - 3] <= minValue ? "--" : result1_copy[result1.length - 3] + "";
//            result1_min1 = result1_copy[0] <= minValue ? "--" : result1_copy[0] + "";
//            result1_min2 = result1_copy[1] <= minValue ? "--" : result1_copy[1] + "";
//            result1_min3 = result1_copy[2] <= minValue ? "--" : result1_copy[2] + "";
//        }
//        String[] type3 = new String[]{"深呼吸心率差", result1_max1,
//                result1_min1, hrDiff + "", "≥15", "11-14", "≤10", result1_max2, result1_min2, result1_max3, result1_min3};
//        //创建表格第三行
//        for (int i = 0; i < type3.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type3[i], fontText), cellHeight);
//            if (i == 0 || i == 3 || i == 4 || i == 5 || i == 6) {
//                index.setRowspan(3);
//            }
//            table2.addCell(index);
//        }
//        //------------------------------------------------------------------
//        double[] result2_copy = result2.clone();
//        Arrays.sort(result2_copy);
//        String result2_max1, result2_max2, result2_max3;
//        String result2_min1, result2_min2, result2_min3;
//        double avg2_max, avg2_min;
//        String avg2;
//
//        if (result2.length < 3) {
//            result2_max1 = "--";
//            result2_max2 = "--";
//            result2_max3 = "--";
//            result2_min1 = "--";
//            result2_min2 = "--";
//            result2_min3 = "--";
//            avg2 = "--";
//        } else {
//            result2_max1 = result2_copy[result2.length - 1] <= minValue ? "--" : result2_copy[result2.length - 1] + "";
//            result2_max2 = result2_copy[result2.length - 2] <= minValue ? "--" : result2_copy[result2.length - 2] + "";
//            result2_max3 = result2_copy[result2.length - 3] <= minValue ? "--" : result2_copy[result2.length - 3] + "";
//            result2_min1 = result2_copy[0] <= minValue ? "--" : result2_copy[0] + "";
//            result2_min2 = result2_copy[1] <= minValue ? "--" : result2_copy[1] + "";
//            result2_min3 = result2_copy[2] <= minValue ? "--" : result2_copy[2] + "";
//            avg2_max = (result2_copy[result2.length - 1] + result2_copy[result2.length - 2] + result2_copy[result2.length - 3]) / 3;
//            avg2_min = (result2_copy[0] + result2_copy[1] + result2_copy[2]) / 3;
//            avg2 = String.format("%.3f", avg2_max / avg2_min);
//        }
//
//        String[] type4 = new String[]{"Valsalva动作指数", result2_max1,
//                result2_min1, avg2, "≥1.21", "1.11-1.20", "≤1.10", result2_max2, result2_min2, result2_max3, result2_min3};
//        //创建表格第四行
//        for (int i = 0; i < type4.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type4[i], fontText), cellHeight);
//            if (i == 0 || i == 3 || i == 4 || i == 5 || i == 6) {
//                index.setRowspan(3);
//            }
//            table2.addCell(index);
//        }
//        table2.setWidthPercentage(85);
//        doc.add(table2);
//        return this;
//    }
//
//    /**
//     * 添加神经反射表格
//     */
//    public PdfUtil createBPChangeTable(BloodPressure[] result) throws DocumentException {
//        if (result == null || result.length == 0) {
//            Log.e("PdfUtil", "为空");
//            result = new BloodPressure[]{new BloodPressure(), new BloodPressure(), new BloodPressure(), new BloodPressure(), new BloodPressure()};
            return this;
//        }
//
//        doc.add(Chunk.NEWLINE);
//        int[] width = {36, 12, 12, 12, 12, 12, 12};
//        PdfPTable table2 = new PdfPTable(7);
//        table2.setWidths(width);
//
//        String[] type1 = {" ", "卧位平均", "立位", "差值", "正常", "临界", "异常"};
//        //创建表格第一行
//        for (int i = 0; i < type1.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type1[i], fontText), cellHeight);
//            table2.addCell(index);
//        }
//        float avgSystolic = 0;//两次平均卧位收缩压
//        float avgDiastolic = 0;//两次平均平卧位舒张压
//        int systolic0 = 0;
//        int systolic1 = 0;
//        int systolic2 = 0;
//
//
//        int diastolic0 = 0;
//        int diastolic1 = 0;
//        int diastolic2 = 0;
//
//        int minSystolic0 = 0;
//        int minSystolic1 = 0;
//        int minSystolic2 = 0;
//        int minDiastolic0 = 0;
//        int minDiastolic1 = 0;
//        int minDiastolic2 = 0;
//        float diffS = 0F;
//        float diffD = 0F;
//        if (result.length == 1) {
//            avgSystolic = result[0].getSystolic();
//            systolic0 = result[0].getSystolic();
//            avgDiastolic = result[0].getDiastolic();
//            diastolic0 = result[0].getDiastolic();
//        }
//        if (result.length == 2) {
//            systolic0 = result[0].getSystolic();
//            systolic1 = result[1].getSystolic();
//            diastolic0 = result[0].getDiastolic();
//            diastolic1 = result[1].getDiastolic();
//            avgSystolic = (result[0].getSystolic() + result[1].getSystolic()) / 2F;
//            avgDiastolic = (result[0].getDiastolic() + result[1].getDiastolic()) / 2F;
//
//        }
//        if (result.length == 3) {
//            systolic0 = result[0].getSystolic();
//            systolic1 = result[1].getSystolic();
//            diastolic0 = result[0].getDiastolic();
//            diastolic1 = result[1].getDiastolic();
//            avgSystolic = (result[0].getSystolic() + result[1].getSystolic()) / 2F;
//            avgDiastolic = (result[0].getDiastolic() + result[1].getDiastolic()) / 2F;
//            minSystolic0 = result[2].getSystolic();
//            minDiastolic0 = result[2].getDiastolic();
//
//        }
//        if (result.length == 4) {
//            systolic0 = result[0].getSystolic();
//            systolic1 = result[1].getSystolic();
//            diastolic0 = result[0].getDiastolic();
//            diastolic1 = result[1].getDiastolic();
//            avgSystolic = (result[0].getSystolic() + result[1].getSystolic()) / 2F;
//            avgDiastolic = (result[0].getDiastolic() + result[1].getDiastolic()) / 2F;
//            minSystolic0 = result[2].getSystolic();
//            minSystolic1 = result[3].getSystolic();
//            minDiastolic0 = result[2].getDiastolic();
//            minDiastolic1 = result[3].getDiastolic();
//
//        }
//        if (result.length == 5) {
//            systolic0 = result[0].getSystolic();
//            systolic1 = result[1].getSystolic();
//            diastolic0 = result[0].getDiastolic();
//            diastolic1 = result[1].getDiastolic();
//            avgSystolic = (result[0].getSystolic() + result[1].getSystolic()) / 2F;
//            avgDiastolic = (result[0].getDiastolic() + result[1].getDiastolic()) / 2F;
//            int minS = Math.min(result[2].getSystolic(), result[3].getSystolic());
//            minSystolic0 = result[2].getSystolic();
//            minSystolic1 = result[3].getSystolic();
//            minSystolic2 = result[4].getSystolic();
//            minDiastolic0 = result[2].getDiastolic();
//            minDiastolic1 = result[3].getDiastolic();
//            minDiastolic2 = result[4].getDiastolic();
//        }
//        int minS = Math.min(Math.min(minSystolic0, minSystolic1), minSystolic2);
//        diffS = avgSystolic - minS;
//        int minD = Math.min(Math.min(minDiastolic0, minDiastolic1), minDiastolic2);
//        diffD = avgDiastolic - minD;
//        String avgS = avgSystolic <= minValue ? "--" : avgSystolic + "";
//        String avgD = avgDiastolic <= minValue ? "--" : avgDiastolic + "";
//        String difS = diffS + "";
//        String difD = diffD + "";
        String[] type2 = new String[]{"卧立位收缩压变化", avgSys,
                minSys, dif, "≤10", "11-29", "≥30"};
//        String[] type2 = new String[]{"卧立位收缩压变化(mmHg)", systolic0<=minValue?"--":systolic0+"",
//                minSystolic0 <= minValue ? "--" : minSystolic0 + "", difS, "≤10", "11-29", "≥30",systolic1<=minValue?"--":systolic1+"", minSystolic1 <= minValue ? "--" : minSystolic1 + "",systolic2<=minValue?"":systolic2+"", minSystolic2 <= minValue ? "--" : minSystolic2 + "", "卧立位舒张压变化(mmHg)", diastolic0<=minValue?"--":diastolic0+"",
//                minDiastolic0 <= minValue ? "--" : minDiastolic0 + "", difD, "--", "--", "≥10",diastolic1<=minValue?"--":diastolic1+"", minDiastolic1 <= minValue ? "--" : minDiastolic1 + "", diastolic2<=minValue?"":diastolic2+"",minDiastolic2 <= minValue ? "--" : minDiastolic2 + ""};
//        //创建表格第二行
//        for (int i = 0; i < type2.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type2[i], fontText), cellHeight);
//
//            if (i!=1 && i != 2 && i != 7 && i != 8 && i!=9 && i!=10&& i != 12&&i!=13 && i != 18 && i != 19 && i!=20&& i!=21) {
//                index = getChatCell(new Paragraph(type2[i], fontText), cellHeight);
//                index.setRowspan(3);
//            }
//            table2.addCell(index);
//        }
//
//
//        table2.setWidthPercentage(85);
//
//        doc.add(table2);
//        return this;
//    }
//
//    /**
//     * 添加心率变异性table
//     */
//    public PdfUtil createHrvTable(HrvResult hrvResult, String doctor, String time) throws DocumentException {
//        if (hrvResult == null) {
//            Log.d("TAG", "createHrvTable: 空");
            return this;
//            hrvResult = new HrvResult();
//        }
        doc.add(Chunk.NEWLINE);//换行
//        doc.add(Chunk.NEWLINE);//换行
//        Paragraph paragraph = new Paragraph("心率变异性时域与频域分析", fontTitle2);
//        //设置行间距
//        paragraph.setLeading(paragraph.getLeading() - 15);
//        paragraph.setSpacingBefore(20);
        paragraph.setExtraParagraphSpace(30);
//        paragraph.setAlignment(Element.TITLE);//设置文字水平居中
//        doc.add(paragraph);
//        doc.add(Chunk.NEWLINE);//换行
//        String hrv = hrvResult.getAvrHR() <= minValue ? "--" : hrvResult.getAvrHR() + BPM;
        Paragraph avgHrv = new Paragraph("平均静息心率:" + hrv, fontText);
//        paragraph.setLeading(paragraph.getLeading()-15);
//        paragraph.setExtraParagraphSpace(30);
        avgHrv.setAlignment(Element.ALIGN_LEFT);//设置文字水平居中
//        avgHrv.setLeading(avgHrv.getLeading()-30);
        //设置下方间距
        avgHrv.setSpacingAfter(5.0f);
        avgHrv.setIndentationLeft(43);
        doc.add(avgHrv);
//
        doc.add(Chunk.NEWLINE);//换行
//
//        //表格
//        PdfPTable table = new PdfPTable(4);
//        PdfPTable table1 = new PdfPTable(4);
//        //表格
//        PdfPTable table2 = new PdfPTable(4);
//
//        String NNVGR = hrvResult.getNNVGR() <= minValue ? "--" : hrvResult.getNNVGR() + MS;
//        String STDHR = hrvResult.getSTD_HR() + BPM;
//        String SDNN = hrvResult.getSDNN() <= minValue ? "--" : hrvResult.getSDNN() + MS;
//        String MAX_HR = hrvResult.getMaxHR() <= minValue ? "--" : hrvResult.getMaxHR() + BPM;
//        String SDANN = hrvResult.getSDANN() <= minValue ? "--" : hrvResult.getSDANN() + MS;
//        String MIN_HR = hrvResult.getMinHR() <= minValue ? "--" : hrvResult.getMinHR() + BPM;
//        String rMSSD = hrvResult.getrMSSD() <= minValue ? "--" : hrvResult.getrMSSD() + MS;
//        String SDSD = hrvResult.getSDSD() <= minValue ? "--" : hrvResult.getSDSD() + MS;
//        String SDNN_Index = hrvResult.getSDNN_Index() <= minValue ? "--" : hrvResult.getSDNN_Index() + MS;
//        String PNN50 = hrvResult.getpNN50() < minValue ? "--" : hrvResult.getpNN50() + "%";
//        String TP = hrvResult.getTP() <= minValue ? "--" : hrvResult.getTP() + MS_2;
//        String VLF = hrvResult.getVLF() <= minValue ? "--" : hrvResult.getVLF() + MS_2;
//        String LF = hrvResult.getLF() <= minValue ? "--" : hrvResult.getLF() + MS_2;
//        String HF = hrvResult.getHF() <= minValue ? "--" : hrvResult.getHF() + MS_2;
//        String LF_HF = hrvResult.getLF_HF_RATIO() <= minValue ? "--" : hrvResult.getLF_HF_RATIO() + "";
//        String VLF_HF = hrvResult.getVLF_HF_RATIO() <= minValue ? "--" : hrvResult.getVLF_HF_RATIO() + "";
//
//        String[] type = {"基本参数", "平均静息心率", hrv, "MAX HR", MAX_HR,
//                "STD HR", STDHR, "MIN HR", MIN_HR,
//                 "NNVGR", NNVGR, "", ""};
//        String[] type1 = {"时域分析",
//                "SDNN", SDNN, "RMSSD", rMSSD,
//                "SDANN", SDANN, "SDSD", SDSD,
//                "SDNN index", SDNN_Index, "pNN50", PNN50};
//        String[] type2 = {"频域分析", "TP", TP, "VLF", VLF,
//                "LF", LF, "HF", HF,
//                "LF/HF", LF_HF + "", "VLF/HF", VLF_HF};
//        for (int i = 0; i < type.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type[i], fontText),cellHeight);
//            if (i % 2 == 0) {
//                index = getChatCell(new Paragraph(type[i], fontText),cellHeight);
//            }
//            if (i == 0) {
//                index = getChatCell(new Paragraph(type[i], fontTitle3),cellHeight);
//                index.setColspan(4);
//            }
//            table.addCell(index);
//        }
//        for (int i = 0; i < type1.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type1[i], fontText), cellHeight);
//            if (i % 2 == 0) {
//                index = getChatCell(new Paragraph(type1[i], fontText), cellHeight);
//            }
//            if (i == 0) {
//                index = getChatCell(new Paragraph(type1[i], fontTitle3), cellHeight);
//                index.setColspan(4);
//            }
//            table1.addCell(index);
//        }
//        for (int i = 0; i < type2.length; i++) {
//            PdfPCell index = getChatCell(new Paragraph(type2[i], fontText3), cellHeight);
//            if (i % 2 == 0) {
//                index = getChatCell(new Paragraph(type2[i], fontText3), cellHeight);
//            }
//            if (i == 0) {
//                index = getChatCell(new Paragraph(type2[i], fontTitle3), cellHeight);
//                index.setColspan(4);
//            }
//            table2.addCell(index);
//        }
//        table.setWidthPercentage(85);
//        table1.setWidthPercentage(85);
//        table2.setWidthPercentage(85);
//        doc.add(table);
//        doc.add(table1);
//
        doc.add(Chunk.NEWLINE);//换行
//        doc.add(table2);
//        createDoctorInfo(doctor, time);
//        return this;
//    }
//
//    public PdfUtil createAllRR(int lieStandSelectMaxRRPos, int lieStandSelectMinRRPos, double[] allLieStandRR, double[] allDeepRR, double[] allValsalvaRR) throws DocumentException {
//        String[] rrType = {"卧立位所有RR间期", "深呼吸所有RR间期", "Valsalva所有RR间期"};
//        Log.d("PdfUtil", "allLieStandRR长度=" + allLieStandRR.length + "allDeepRR长度=" + allDeepRR.length + "allValsalvaRR长度=" + allValsalvaRR.length);
//        double[] allLieStandRRCopy = allLieStandRR.clone();
//        Arrays.sort(allLieStandRRCopy);
//        double[] allDeepCopy = allDeepRR.clone();
//        Arrays.sort(allDeepCopy);
//        double[] allValsalvaRRCopy = allValsalvaRR.clone();
//        Arrays.sort(allValsalvaRRCopy);
//        double[][] allRR = {allLieStandRR, allDeepRR, allValsalvaRR};
//        double[][] allRRCopy = {allLieStandRRCopy, allDeepCopy, allValsalvaRRCopy};
//        for (int i = 0; i < rrType.length; i++) {
//            if (allRR[i].length == 0) {
//                continue;
//            }
//            doc.newPage();
//            Paragraph avgHrv = new Paragraph(rrType[i], fontTitle2);
//            avgHrv.setAlignment(Element.TITLE);//设置文字水平居中
//            //设置下方间距
//            avgHrv.setSpacingAfter(15.0f);
//            doc.add(avgHrv);
//            PdfPTable table = new PdfPTable(3);
//            String[] type = {
//                    "",
//                    "RR间期(s)",
//                    "备注"
//
//            };
//            for (int j = 0; j < 3; j++) {
//                PdfPCell index = getChatCell(new Paragraph(type[j], fontTitle3));
//                table.addCell(index);
//            }
//            boolean rrMax1 = false, rrMax2 = false, rrMax3 = false, rrMin1 = false, rrMin2 = false, rrMin3 = false;
//
//            for (int k = 0; k < allRR[i].length; k++) {
//
//                PdfPCell index1 = getChatCell(new Paragraph((k + 1) + "", fontText));
//                table.addCell(index1);
//                PdfPCell index2 = getChatCell(new Paragraph(allRR[i][k] + "", fontText));
//                table.addCell(index2);
//                if (i == 0) {
//                    if (lieStandSelectMaxRRPos == k) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最长", fontText));
//                        table.addCell(index3);
                      rrMax1 = true;
//                    } else if (lieStandSelectMinRRPos == k) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最短", fontText));
//                        table.addCell(index3);
                        rrMin1 = true;
//                    } else {
//                        PdfPCell index3 = getChatCell(new Paragraph("", fontText));
//                        table.addCell(index3);
//
//                    }
//
//                } else {
//                    if (allRR[i].length < 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("", fontText));
//                        table.addCell(index3);
//                        continue;
//                    }
//                    if (allRRCopy[i][allRRCopy[i].length - 1] == allRR[i][k] && !rrMax1 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最长1", fontText));
//                        table.addCell(index3);
//                        rrMax1 = true;
//                    } else if (allRRCopy[i][allRRCopy[i].length - 2] == allRR[i][k] && !rrMax2 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最长2", fontText));
//                        table.addCell(index3);
//                        rrMax2 = true;
//                    } else if (allRRCopy[i][allRRCopy[i].length - 3] == allRR[i][k] && !rrMax3 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最长3", fontText));
//                        table.addCell(index3);
//                        rrMax3 = true;
//                    } else if (allRRCopy[i][0] == allRR[i][k] && !rrMin1 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最短1", fontText));
//                        table.addCell(index3);
//                        rrMin1 = true;
//                    } else if (allRRCopy[i][1] == allRR[i][k] && !rrMin2 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最短2", fontText));
//                        table.addCell(index3);
//                        rrMin2 = true;
//                    } else if (allRRCopy[i][2] == allRR[i][k] && !rrMin3 && allRR[i].length >= 6) {
//                        PdfPCell index3 = getChatCell(new Paragraph("最短3", fontText));
//                        table.addCell(index3);
//                        rrMin3 = true;
//                    } else {
//                        PdfPCell index3 = getChatCell(new Paragraph("", fontText));
//                        table.addCell(index3);
//                    }
//                }
//
//
//            }
//
//
//            table.setWidthPercentage(85);
//            doc.add(table);
//
//
//        }
//
//        return this;
//    }
//
//    /**
//     * 结论
//     */
//    public PdfUtil createConclusion(String conclusion, String doctor, String time) throws DocumentException {
//        PdfPTable table = new PdfPTable(4);
//        String[] type = {
//                "结论:",
//                conclusion,
//                "检查医生:",
//                doctor,
//                "检查时间:",
//                time,
//                "注:输出的临床结果仅用于辅助医生诊断糖尿病心脏自主神经病变,最终结果由医生结合临床综合判断并签字确认后生效。"
//        };
//
//        // 设置表格默认为无边框
//        table.getDefaultCell().setBorder(0);
//        for (int i = 0; i < type.length; i++) {
//            Paragraph userInfo = new Paragraph(type[i], fontTitle3);
//            if (i == 1 || i == 3 || i == 5) {
//                userInfo = new Paragraph(type[i], fontText);
//            }
//            if (i == 6) {
//                userInfo = new Paragraph(type[i], fontText2);
//            }
//
//            PdfPCell cell = new PdfPCell(userInfo);
//            cell.setBorder(Rectangle.NO_BORDER);
//            if (i == 0 || i == 1 || i == 6) {
//                cell.setColspan(4);
//            }
//            if (i == 1) {
//                cell.setFixedHeight(50);
//            } else {
//                cell.setFixedHeight(45);
//            }
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//
//            // 设置垂直居中
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            table.addCell(cell);
//        }
//
//        table.setWidthPercentage(85);
//        doc.add(table);
//        return this;
//    }
//
//    /**
//     * 医生信息
//     */
//    private PdfUtil createDoctorInfo(String doctor, String time) throws DocumentException {
//        PdfPTable table = new PdfPTable(4);
//        String[] type = {
//                "检查医生:",
//                doctor,
//                "检查时间:",
//                time
//        };
//
//        // 设置表格默认为无边框
//        table.getDefaultCell().setBorder(0);
//        for (int i = 0; i < type.length; i++) {
//            Paragraph userInfo = new Paragraph(type[i], fontTitle3);
//            if (i == 1 || i == 3) {
//                userInfo = new Paragraph(type[i], fontText);
//            }
//
//
//            PdfPCell cell = new PdfPCell(userInfo);
//            cell.setBorder(Rectangle.NO_BORDER);
//
//            cell.setFixedHeight(25);
//
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//
//            // 设置垂直居中
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            table.addCell(cell);
//        }
//
//        table.setWidthPercentage(85);
//        table.setSpacingBefore(250);
//        doc.add(table);
//        return this;
//    }
//
    String imgPath;

    //
//    public PdfUtil createEcgImg(int[] page, int[] time, int[] gain, String path, float scale) throws Exception {
//        imgPath = path;
//        String[] ecgType = {"卧立位心电图", "深呼吸心电图", "Valsalva心电图"};
//        for (int i = 0; i < page.length; i++) {
//            Log.e("PdfUtil", "page0size=" + page[i]);
//            if (page[i] == 0) {
//                continue;
//            }
//            doc.newPage();
//            Paragraph paragraph = new Paragraph(ecgType[i], fontTitle2);
//            paragraph.setLeading(paragraph.getLeading() - 15);
//            paragraph.setAlignment(Element.TITLE);//设置文字水平居中
//            doc.add(paragraph);
//            doc.add(Chunk.NEWLINE);//换行
//            Paragraph paragraph2 = new Paragraph("增益:" + gain[i] + "mm/mV 走速:25mm/s 时长:" + DateUtils.INSTANCE.formatEcgDuration(time[i]), fontText2);
//            paragraph2.setAlignment(Element.ALIGN_RIGHT);//设置文字水平居中
            paragraph2.setLeading(paragraph.getLeading() - 15);
//            paragraph2.setIndentationRight(30);
//            doc.add(paragraph2);
//            float imgWidth = PageSize.A4.getWidth() - 60f;
//            float imgHeight = imgWidth / scale;
//            doc.add(Chunk.NEWLINE);//换行
//            for (int k = 0; k < page[i]; k++) {
//                Image image1 = Image.getInstance(path + "/img" + i + "_" + k + ".png");
//                // 按百分比缩放
//                //image1.scalePercent(30);
//                image1.scaleAbsolute(imgWidth, imgHeight);
//                Log.d("PdfUtil", "createEcgImg: " + PageSize.A4.getWidth());
//                image1.setAlignment(Image.MIDDLE);
//                doc.add(image1);
//            }
//            doc.newPage();
//        }
//
        fos.flush();
        if (doc != null) {
            doc.close();
        }
//
//        return this;
//
//    }
    public void build() throws Exception {
        dispose();
    }

    private void deleteAllImgs() {
        File file = new File(imgPath);
        File[] imgs = file.listFiles();
        for (int i = 0; i < Objects.requireNonNull(imgs).length; i++) {
            imgs[i].delete();
        }
    }

    public void dispose() throws Exception {
        if (doc != null && doc.isOpen()) {
            doc.close();
        }
        if (fos == null)
            return;
        fos.flush();
        fos.close();
        if (imgPath != null) {
            deleteAllImgs();
        }
    }
//
//    /**
//     * 获取每个单元格
//     *
//     * @param paragraph
//     * @return
//     */
//    private PdfPCell getChatCell(Paragraph paragraph, int height) {
//        PdfPCell cell2 = new PdfPCell(paragraph);
//        // 设置高度
//        cell2.setFixedHeight(height);
//        // 设置内容水平居中显示
//        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
//        // 设置垂直居中
//        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
//        cell2.setBorderColor(new BaseColor(0, 0, 0, 125));
//
//        return cell2;
//    }
//
//    /**
//     * 获取每个单元格
//     *
//     * @param paragraph
//     * @return
//     */
//    private PdfPCell getChatCell(Paragraph paragraph) {
//        return getChatCell(paragraph, 20);
//    }
//
//    private static PdfPCell getChatCell(Paragraph paragraph, int height, boolean showBack, boolean isCenter) {
//        PdfPCell cell2 = new PdfPCell(paragraph);
//        // 设置高度
//        cell2.setFixedHeight(height);
//        // 设置内容水平居中显示
//        if (isCenter) {
//            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
//        } else {
//            cell2.setPaddingLeft(5);
//        }
//        // 设置垂直居中
//        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
//        cell2.setBorderColor(new BaseColor(0, 0, 0, 125));
//        if (showBack)
//            cell2.setBackgroundColor(new BaseColor(0, 0, 0, 35));
//        return cell2;
//    }

    /**
     * 设置PDF字体(较为耗时)
     */
    public Font setChineseFont(int size, int style, String fontPath) {
        BaseFont bf = null;
        Font fontChinese = null;
        try {
            // STSong-Light : Adobe的字体
            // UniGB-UCS2-H : pdf 字体
            //G:\AndroidProject\dcan-android\app\src\main\assets
            if (fontPath != null && new File(fontPath).exists()) {
                bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H,
                        BaseFont.NOT_EMBEDDED);
            } else {
                bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
                        BaseFont.NOT_EMBEDDED);
            }
            fontChinese = new Font(bf, size, style);
        } catch (Exception e) {
            e.printStackTrace();
            return new Font();
        }
        return fontChinese;
    }

    /**
     * 设置PDF字体(较为耗时)
     */
    public Font setChineseFont2(int size, int style, String fontPath) {
        BaseFont bf = null;
        Font fontChinese = null;
        try {
            // STSong-Light : Adobe的字体
            // UniGB-UCS2-H : pdf 字体
            if (fontPath != null) {
                bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H,
                        BaseFont.NOT_EMBEDDED);
            } else {
                bf = BaseFont.createFont("wusheng", BaseFont.IDENTITY_H,
                        BaseFont.NOT_EMBEDDED);
            }
            fontChinese = new Font(bf, size, style);
        } catch (Exception e) {
            e.printStackTrace();
            return new Font();
        }
        return fontChinese;
    }

    /*
     * HeaderAndFooter class
     */
    public class HeaderAndFooter extends PdfPageEventHelper {
        
        public void onEndPage(PdfWriter writer, Document document) {
            Font headFont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED, 9, Font.NORMAL, BaseColor.BLACK);
            //添加标题文本
            StringBuffer underline = new StringBuffer();
            for (int i = 0; i < 116; i++) {
                underline.append("_");
            }
//            Phrase contentPh = new Phrase("深圳市跃瑞医疗科技有限公司", headFont);
//            Phrase underlinePh = new Phrase(underline.toString(), headFont);
            Phrase pageNumberPh = new Phrase(String.valueOf(writer.getPageNumber()), headFont);
            float center = doc.getPageSize().getRight() / 2;//页面的水平中点
//            float top = doc.getPageSize().getTop() - 15;
            float bottom = doc.getPageSize().getBottom();
            /** 参数xy是指文本显示的页面上的哪个店。alignment指文本在坐标点的对齐方式 */
//            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, contentPh, center, top, 0); //页眉
//            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, underlinePh, center, top - 3, 0); //页眉
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, pageNumberPh, center, bottom, 0); //页码
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/605420.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

09 - 数据清洗案例

流程图 kettle 面板图片 操作步骤 1、订阅数据源&#xff08;kafka consumer&#xff09; 2、抽取字段并转换key&#xff08;JSON input&#xff09; 3、判断img字段是否有值&#xff0c;有的话进行url转base64&#xff08;JavaScript 代码&#xff09; // 获取输入字段的值 v…

中金:如何把握不断轮动的资产“风口”

从比特币到日股&#xff0c;到黄金与铜再到当前的港股&#xff0c;每次超预期大涨后都透支回调。 今年以来资产的“风口”不断轮动&#xff0c;从比特币到日股&#xff0c;到黄金与铜&#xff0c;再到当前的港股&#xff0c;资产仿佛“接力”般交替领先&#xff0c;同时“风口”…

JavaScript 垃圾回收机制深度解析:内存管理的艺术

&#x1f525; 个人主页&#xff1a;空白诗 文章目录 &#x1f3ad; 引言一、JavaScript内存模型与生命周期的深度解析&#x1f4cc; 基本数据类型与栈内存的精妙运作&#x1f4cc; 复杂数据类型与堆内存的广袤世界&#x1f4cc; 生命周期管理的智慧与实践策略&#x1f4cc; We…

uniapp开发小程序使用vue的v-html解析富文本图片过大过宽显示超过屏幕解决办法

如果没有设置的话&#xff0c;就会导致图片溢出&#xff0c;过宽显示或者错位显示&#xff0c;显示效果非常的丑陋&#xff1a; 修改后显示的效果&#xff1a; 网上比较low的解决办法&#xff1a;网上各种解决方法核心思想就是在数据层把数据模板上的img数据加上style样式&…

嵌入式Linux学习第四天启动方式学习

嵌入式Linux学习第四天 今天学习I.MX6U 启动方式详解。I.MX6U有多种启动方式&#xff0c;可以从 SD/EMMC、NAND Flash、QSPI Flash等启动。 启动方式选择 BOOT 的处理过程是发生在 I.MX6U 芯片上电以后&#xff0c;芯片会根据 BOOT_MODE[1:0]的设置来选择 BOOT 方式。BOOT_M…

windows11获取笔记本电脑电池健康报告

笔记本电脑的电池关系到我们外出时使用的安全&#xff0c;如果电池健康有问题需要及时更换&#xff0c;windows系统提供了检查电池健康度的方法。 1、打开命令行 1&#xff09;键入 winR 2&#xff09;键入 cmd 打开命令行。 2、在命令行运行如下指令&#xff0c;生成电池健…

Maven+Junit5 + Allure +Jenkins 搭建 UI 自动化测试实战

文章目录 效果展示Junit 5Junit 5 介绍Junit 5 与 Junit 4 对比PageFactory 模式编写自动化代码公共方法提取测试用例参数化Jenkins 搭建及配置参数化执行生成 Allure 报告Maven 常用命令介绍POM 文件效果展示 本 chat 介绍 UI 自动化测试框架的搭建: 运用 page factory 模式…

TCP三次握手四次挥手 UDP

TCP是面向链接的协议&#xff0c;而UDP是无连接的协议 TCP的三次握手 三次传输过程是纯粹的不涉及数据&#xff0c;三次握手的几个数据包中不包含数据内容。它的应用层&#xff0c;数据部分是空的&#xff0c;只是TCP实现会话建立&#xff0c;点到点的连接 TCP的四次挥手 第四…

介绍 ffmpeg.dll 文件以及ffmpeg.dll丢失怎么办的五种修复方法

ffmpeg.dll 是一个动态链接库文件&#xff0c;属于 FFmpeg运行库。它在计算机上扮演着非常重要的角色&#xff0c;因为它提供了许多应用程序和操作系统所需的功能和组件。当 ffmpeg.dll 文件丢失或损坏时&#xff0c;可能会导致程序无法正常运行&#xff0c;甚至系统崩溃。下面…

基于opencv的车辆统计

车辆统计&#xff09; 一、项目背景二、整体流程三、常用滤波器的特点四、背景减除五、形态学开运算闭运算 六、项目完整代码七、参考资料 一、项目背景 检测并识别视频中来往车辆的数量 最终效果图&#xff1a; 二、整体流程 加载视频图像预处理&#xff08;去噪、背景减除…

航空电子FC节点卡, FC交换机,主要采用LC或MPO光纤接口形式

FC节点卡主要采用LC或MPO光纤接口形式&#xff0c;可以作为4/2个独立端口使用&#xff0c;也可以作为2对/1对冗余端口使用&#xff0c;支持1.0625Gbps、2.125Gbps、4.25Gbps、8.5Gbps通信速率。节点卡完全遵循FC-LS&#xff0c;FC-FS&#xff0c;FC-AE-ASM、FC-AE-1553B等FC光纤…

springboot+vue+mybatis家教管理系统的设计与实现+PPT+论文+讲解+售后

家教管理系统是为了方便用户能够在网站上查看教师信息进行家教预约等&#xff0c;于是开发了基于springboot框架设计与实现了一款简洁、轻便的家教管理系统。本系统解决了家教管理事务中的主要问题&#xff0c;包括以下多个功能模块&#xff1a;公告信息、留言信息、预约家教老…

Isaac Sim 4 键盘控制小车前进方向(学习笔记5.8.2)

写的乱糟糟&#xff0c;主要是这两周忘了记录了...吭哧吭哧往下搞&#xff0c;突然想起来要留档&#xff0c;先大致写一个&#xff0c;后面再往里添加和修改吧&#xff0c;再不写就全忘了 有一个一直没解决的问题&#xff1a; 在保存文件时出现问题&#xff1a;isaac sim mism…

【OceanBase诊断调优】—— 磁盘性能问题导致卡合并和磁盘写入拒绝排查

适用版本 OceanBase 数据库 V3.x、V4.x 版本。 问题现象 OceanBase 集群合并一直未完成&#xff0c;同时 tsar 和 iostat 显示从凌晨 2:30 开始磁盘使用率一直是 100%。怀疑合并导致 IO 上升&#xff0c;IO 可能存在问题&#xff0c;observer.log 的确有大量报错 disk is hu…

概述篇——计算机网络学习笔记(基于谢希仁教材与PPT)

教材用的是谢希仁的教材&#xff0c;图片来源于谢希仁老师配套的PPT 计算机网络课程PPT&#xff08;通过这个链接&#xff0c;你可以找到课程配套的ppt&#xff09; 计算机网络的定义及其特点 定义 网络 过去大众熟知的三种网络分别是提供电话、电报及传真等服务的电信网络&am…

Linux主机排查工具-GScan

0x01 简介 本程序旨在为安全应急响应人员对Linux主机排查时提供便利&#xff0c;实现主机侧Checklist的自动全面化检测&#xff0c;根据检测结果自动数据聚合&#xff0c;进行黑客攻击路径溯源。 0x02 项目地址 https://github.com/grayddq/GScan 0x03 CheckList检测项 自…

每日一题——力扣面试题 17.04. 消失的数字

题目链接&#xff1a;https://leetcode.cn/problems/missing-number-lcci/description/ 菜鸡做法&#xff1a; #include <stdlib.h> // 包含标准库头文件&#xff0c;用于内存分配等功能// 函数定义&#xff1a;寻找缺失的数字 int missingNumber(int* nums, int numsSi…

从离线到实时:无锡锡商银行基于 Apache Doris 的数据仓库演进实践

作者&#xff1a;武基鹏&#xff0c;无锡锡商银行 大数据技术经理 编辑整理&#xff1a;SelectDB 技术团队 导读&#xff1a;为实现数据资产的价值转化以及全面数字化、智能化的风险管理&#xff0c;无锡锡商银行大数据平台经历从 Hive 离线数据仓库到 Apache Doris 实时数据仓…

Hive SQL-DQL-Select查询语句用法详解

HQL Select用法详解 1.基础语法 &#xff08;1&#xff09;select_exp &#xff08;2&#xff09;ALL、DISTINCT &#xff08;3&#xff09;WHERE &#xff08;4&#xff09;分区查询、分区裁剪 &#xff08;5&#xff09;GROUP BY &#xff08;6&#xff09;HAVING &#xff0…

hadoop学习---基于Hive的教育平台数据仓库分析案例(三)

衔接第一部分&#xff0c;第一部分请点击&#xff1a;基于Hive的教育平台数据仓库分析案例&#xff08;一) 衔接第二部分&#xff0c;第二部分请点击&#xff1a;基于Hive的教育平台数据仓库分析案例&#xff08;二) 学生出勤模块&#xff08;全量分析&#xff09;&#xff1a…
最新文章