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的实现类PdfWriterwriter = 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文档中加入tablereturn 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\assetsif (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.mzph.cn/news/834281.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

static静态成员变量和静态方法

当有new创建一个对象的,里面属性和方法,通过构造函数,能定义多个不同的对象,在我们做面向对象开发的时候,给一个场景,人在一个班级的时候,你的老师可能是固定的。 当我们用构造方法去构造的时候&#xff0c;每次都去传递一个固定的实参去定义个老师。 这样好会显得代码非常的…

SOCKET编程(1):基本概念

基本概念 socket分类 socket提供了**流(stream)和数据报(datagram)**两种通信机制&#xff0c;即流socket和数据报socket 流socket基于TCP协议&#xff0c;是一个有序、可靠、双向字节流的通道&#xff0c;传输数据不会丢失、不会重复、顺序也不会错乱 数据报socket基于UDP…

Powerdesigner导入mysql8之后注释丢失

目录 一、问题描述及解决思路 二、导入的步骤 1.先按正常步骤建立一个物理数据模型 &#xff08;1&#xff09;点击“文件-新建模型” &#xff08;2&#xff09;选择物理模型和数据库 2.从sql文件导入表 &#xff08;1&#xff09;点击“数据库-Update Model from Data…

正则表达式-前瞻和后顾

正则表达式中的前瞻和后顾。 前瞻(Lookahead) 前瞻是一种断言,它会检查在当前位置之后是否存在某种模式,但不会实际匹配该模式。前瞻有两种形式: 正向前瞻 (?pattern) 检查当前位置之后是否存在指定的模式如果存在,则匹配成功,但不会消耗该模式例如 \w(?\d) 将匹配后面跟数…

RAG 场景对Milvus Cloud向量数据库的需求

虽然向量数据库成为了检索的重要方式,但随着 RAG 应用的深入以及人们对高质量回答的需求,检索引擎依旧面临着诸多挑战。这里以一个最基础的 RAG 构建流程为例:检索器的组成包括了语料的预处理如切分、数据清洗、embedding 入库等,然后是索引的构建和管理,最后是通过 vecto…

学习笔记:【QC】Android Q : telephony-phone 模块

一、phone init 流程图 高清的流程图参考&#xff1a;【高清图&#xff0c;保存后可以放大看】 二、phone MO 流程图 高清的流程图参考&#xff1a;【高清图&#xff0c;保存后可以放大看】 三、phone MT 流程图 高清的流程图参考&#xff1a;【高清图&#xff0c;保存后可以…

提升工作效率,用ONLYOFFICE打造高效团队协作环境

作为一名深耕技术领域已有六七年的开发者&#xff0c;同时又是断断续续进行技术创作将近六年的一个小小作者&#xff0c;我在工作和日常生活中&#xff0c;使用过各色各样的软件。 而在最近几年&#xff0c;一款名为ONLYOFFICE的开源办公套件逐渐走进并融入我的工作与生活&…

paraview 处理 fluent 计算结果

paraview 处理 fluent 计算结果 参考链接&#xff1a;https://zhuanlan.zhihu.com/p/598032490 希望先生的主页也很有价值&#xff1a;https://www.cnblogs.com/Xiwang-Sun/p/14943429.html

如何在适用于 Linux 的 Visual Studio Code 中使用 .NET 8 上的 FastReport Avalonia

我们将继续撰写有关在各种操作系统上的 Visual Studio Code 中使用 FastReport Avalonia 的系列文章。在本文中&#xff0c;我们将详细分析如何使用 Visual Studio Code IDE 在 Linux 操作系统上运行 FastReport Avalonia。 Avalonia UI 是一个积极用于开发跨平台用户界面的 .…

Hyper-V 管理器安装的ubutun扩容磁盘空间说明

一、删除检查点 首先把这个想要扩容的虚拟机停止掉&#xff0c;然后找到检查点&#xff0c;全删除掉&#xff0c;否则没法编辑这个虚拟磁盘。 二、编辑虚拟磁盘 下面截图中下一步不能点击的&#xff0c;只要删除检查点之后就可以点击了。点击下一步然后选择扩容&#xff0c;然后…

组合模式(结构型)

目录 一、前言 二、透明组合模式 三、安全组合模式 四、总结 一、前言 组合模式(Composite Pattern)是一种结构型设计模式&#xff0c;将对象组合成树形结构以表示“部分-整体”得层次结构。组合模式使得用户对单个对象和组合对象的使用具有一致性。 组合模式由以下角色组成…

SpringSecurity源码分析(RemeberMe)

RememberMeServices RememberMeServices 记住我的服务的接口 可以重写实现自己的记住我 public interface RememberMeServices { //建议 org. springframework. security. authentication. RememberMeAuthenticationToken 在大多数情况下使用它&#xff0c;因为它具有相应的身份…

词袋法TFIDF

Tf-idf⽂本特征提取 TF-IDF的主要思想是&#xff1a;如果某个词或短语在⼀篇⽂章中出现的概率⾼&#xff0c;并且在其他⽂章中很少出现&#xff0c;则认为此词或者短语具有很好的类别区分能⼒&#xff0c;适合⽤来分类。TF-IDF作⽤&#xff1a;⽤以评估⼀字词对于⼀个⽂件集或…

OpenAI 发布 AI 生成图片检测器;Meta 推出 AI 广告创意工具;Google 正式发布 Pixel 8a,主打 AI

OpenAI 发布 AI 生成图片检测器 OpenAI 昨日官宣推出专用的 AI 监测工具&#xff0c;用于监测图片是否由其旗下 AI 图片生成工具 DALL-E 生成&#xff0c;准确率高达 98.8%。 不过该公司表示&#xff0c;这个检测工具并非旨在检测 Midjourney 和 Stability 等其他流行生成器生…

安卓使用Fiddler抓包 2024

简介 最近试了一下安卓使用fiddler 抓包&#xff0c;发现https包基本都会丢失。原因是Anandroid 7版本针对ssl安全性做了加强&#xff0c;不认可用户的证书。我们要做的就是把fiddler导出的证书进过处理后放置到系统证书目录下面&#xff0c;这样才能抓包https请求。 这里使用…

https介绍,加密解密(举例+必要性,对称/非对称加密介绍),数字摘要/指纹(介绍,应用(session id,网盘的秒传功能))

目录 https 引入 介绍 加密解密层 介绍 没有绝对的安全 使用ssl的弊端 加密解密 概念 加密 解密 秘钥 举例 现实中 网络中 加密的必要性 常见加密方式 对称加密 特点 非对称加密 特点 数字摘要/指纹 介绍 应用 session id 百度网盘的秒传功能 https …

21_Scala集合_可变数组ArrayBuffer

文章目录 ArrayBuffer1.创建可变数组ArrayBuffer2.增加数据3.删除数据4.修改数据5.查询数据Appendix ArrayBuffer ArrayBuffer可变数组–感觉优点类似于Java的ArrayList 1.创建可变数组ArrayBuffer –请注意下面的mutable import scala.collection.mutable.ArrayBuffer //m…

DuDuTalk:4G桌面拾音设备在银行网点服务场景的应用价值

随着科技的飞速发展&#xff0c;银行业也在不断地寻求创新以提高服务质量和效率。在这个过程中&#xff0c;4G桌面拾音设备作为一种新型的智能设备&#xff0c;其在银行网点服务场景中的应用价值逐渐凸显出来。本文将从多个角度探讨4G桌面拾音设备在银行网点服务场景的应用价值…

英语学习笔记6——What make is it?

What make is it? 它是什么牌子的&#xff1f; make n.&#xff08;产品的&#xff09;品牌名称    v. 制作 区别&#xff1a;model n.&#xff08;产品的&#xff09;型号       n. 模型       n. 模特 make 指的是大的品牌名称&#xff0c; model 是旗下产品…

OpenHarmony 实战开发——南向统一编译的docker镜像来了

由于我自己的南向设备开发平台的需求&#xff0c;我将当前几个不同的 docker 镜像版本进行了整合&#xff0c;经过一段时间的攻关和验证&#xff0c;目前整合已完成&#xff0c;新版本的 Dockerfile 如下&#xff0c;这个不是公共需求&#xff0c;所以没有提交主干&#xff0c;…