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); //页码}}
}相关文章:
Android使用itextpdf操作PDF文档
1、导入jar包: itext-asian.jaritextpdf-5.5.8.jar Paragraph 和 Phrase 的区别: 在 iTextPDF 库中,Paragraph 和 Phrase 是用于创建和组织文本内容的两个不同的类。 Paragraph(段落): Paragraph 是一个…...
llama_index微调BGE模型
微调模型是为了让模型在特殊领域表现良好,帮助其学习到专业术语等。 本文采用llama_index框架微调BGE模型,跑通整个流程,并学习模型微调的方法。 已开源:https://github.com/stay-leave/enhance_llm 一、环境准备 Linux环境,GPU L20 48G,Python3.8.10。 pip该库即可。…...
什么是限流?常见的限流算法
目录 1. 什么是限流 2. 常见限流算法 3. 固定窗口算法 4. 滑动窗口算法 5. 漏桶算法 6. 令牌桶算法 7. 限流算法选择 1. 什么是限流 限流(Rate Limiting)是一种应用程序或系统资源管理的策略,用于控制对某个服务、接口或功能的访问速…...
ZL-0895小动物活动记录仪可同时检测8只动物的活动量
简单介绍: 小动物活动记录仪是一种多用途、宽范围的小动物活动记录仪器,可用于小鼠、大鼠、豚鼠和兔的实验,小动物活动记录仪具有不需对动物使用特别盛具的特点,可在不改变动物原生活环境的情况下,进行实时监测&…...
注册测绘师的前世今生
本文梳理了 注册测绘师 的前世今生,具体情况如下表: 历史线时间事件诞生2007年1月原人事部、国家测绘局联合印发《注册测绘师制度暂行规定》,注册测绘师制度建立。同时同步发布《注册测绘师资格考试实施办法》、《注册测绘师资格考核认定办法…...
Python中的异常处理:深入探索try-except-finally结构
Python中的异常处理:深入探索try-except-finally结构 一、引言 在Python编程中,异常处理是一个非常重要的部分。当程序遇到错误时,比如尝试除以零、文件读取失败等,Python会抛出一个异常。如果我们不捕获这些异常,程…...
【R语言】边缘概率密度图
边缘概率密度图是一种在多变量数据分析中常用的图形工具,用于显示每个单独变量的概率密度估计。它通常用于散点图的边缘,以便更好地理解单个变量的分布情况,同时保留了散点图的相关性信息。 在边缘概率密度图中,每个变量的概率密度…...
中国结(科普)
中国结是一种手工编织工艺品,它身上所显示的情致与智慧正是汉族古老文明中的一个侧面。 [1]它原本是由旧石器时代的缝衣打结,后推展至汉朝的仪礼记事,再演变成今日的装饰手艺。周朝人随身的佩戴玉常以中国结为装饰,而战国时代的铜…...
使用Android Studio 搭建AOSP FrameWork 源码阅读开发环境
文章目录 概述安装Android Studio编译源码使用Android Studio打开源码制作ipr文件直接编译成功后自动打开Android Studio 修改SystemUI验证开发环境 概述 我们都知道Android的系统源码量非常之大,大致有frameworka层源码,硬件层(HAL)源码,内…...
区块链 | IPFS:CID
🦊原文:Anatomy of a CID 🦊写在前面:本文属于搬运博客,自己留存学习。 1 CID 在分布式网络中与其他节点交换数据时,我们依赖于内容寻址(而不是中心化网络的位置寻址)来安全地定位…...
PostgreSQL(十二)报错:Tried to send an out-of-range integer as a 2-byte value: 51000
目录 一、报错场景二、源码分析三、实际原因(更加复杂)四、解决思路 一、报错场景 今天写了一个历史数据处理程序,在开发环境、测试环境都可以正常执行,但是放到生产环境上就不行,报了一个这样的错误: or…...
Linux守护进程
进程组和会话在 UNIX 系统中是非常重要的概念,特别是在进行作业控制和终端会话管理时。下面是关于进程组和会话的详细解释: 进程组(Process Group) 定义与作用: 进程组是一个或多个进程的集合,这些进程通常…...
HarmonyOS 应用开发——入门
首先当然是华为的官方文档了,要认真学习: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V2/start-overview-0000001478061421-V2 不想花时间看,可以看我下面总结的干货,哈哈 第一个问题:stage架构和fa架构的区…...
开源免费的发票识别OCR应用:Invoice
Invoice:轻松识别,发票电子化扫描烦恼消- 精选真开源,释放新价值。 概览 Invoice 是github社区上一个采用开源许可协议发布的增值税发票光学字符识别(OCR)解决方案项目。该项目不仅集成了预训练的高级模型,…...
关于Docker alpine
1.拉取alpine镜像 docker pull alpine 2.运行镜像成为容器 docker run -it --rm alpine sh (--rm标志确保容器在退出时被自动删除。) 3.容器建立后,运行 docker exec -it <container_id> sh 4.进入容器里的 alpine环境 ①.配置安装源 cat >/etc…...
【Elasticsearch运维系列】Elasticsearch7.12.1启动指定版本JDK:你学废了吗?
一、背景 一套生ES集群,版本为7.12.1,近期频繁告警,频繁出现索引分片异常,索引状态异常,导致应用无法正常写入ES,另外,也经常出现节点掉问题。通过分析相关ES日志,显示和当前JAVA G…...
思通数科大模型在智能数据查询系统中的深度应用:销售数据分析的革新
在企业决策支持系统中,销售数据分析占据着举足轻重的地位。思通数科的大模型技术,结合自然语言处理(NLP)和机器学习,为智能数据查询系统提供了强大的分析能力。本文将详细描述思通数科大模型在销售数据分析中的应用&am…...
上位机图像处理和嵌入式模块部署(树莓派4b和qt应用全屏占有)
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing 163.com】 我们都知道,嵌入式应用一般都是为了某一个特定应用而存在的。也就是说,和pc不同,这个嵌入式板子一般都是为了解…...
QT:QT窗口(一)
文章目录 菜单栏创建菜单栏在菜单栏中添加菜单创建菜单项添加分割线 工具栏创建工具栏设置停靠位置创建工具栏的同时指定停靠位置使用QToolBar类提供的setAllowedAreas函数来设置停靠位置 设置浮动属性设置移动属性 状态栏状态栏的创建在状态栏中显示实时消息在状态栏中显示永久…...
matlab例题大全
1.第1章 MATLAB系统环境 1.1 注:plot函数为画图函数。例plot(x1,y1,:,x2,y2,*); 1.2 注:root为求根函数。p为方程变量前面系数矩阵。 1.3 注: 2*x3y-1*z 2; 8*x2*y3*z 4; 45*x3*y9*z 23 求:x,y,z的…...
AI-调查研究-01-正念冥想有用吗?对健康的影响及科学指南
点一下关注吧!!!非常感谢!!持续更新!!! 🚀 AI篇持续更新中!(长期更新) 目前2025年06月05日更新到: AI炼丹日志-28 - Aud…...
Java 语言特性(面试系列1)
一、面向对象编程 1. 封装(Encapsulation) 定义:将数据(属性)和操作数据的方法绑定在一起,通过访问控制符(private、protected、public)隐藏内部实现细节。示例: public …...
相机Camera日志实例分析之二:相机Camx【专业模式开启直方图拍照】单帧流程日志详解
【关注我,后续持续新增专题博文,谢谢!!!】 上一篇我们讲了: 这一篇我们开始讲: 目录 一、场景操作步骤 二、日志基础关键字分级如下 三、场景日志如下: 一、场景操作步骤 操作步…...
HBuilderX安装(uni-app和小程序开发)
下载HBuilderX 访问官方网站:https://www.dcloud.io/hbuilderx.html 根据您的操作系统选择合适版本: Windows版(推荐下载标准版) Windows系统安装步骤 运行安装程序: 双击下载的.exe安装文件 如果出现安全提示&…...
C++ 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
Web 架构之 CDN 加速原理与落地实践
文章目录 一、思维导图二、正文内容(一)CDN 基础概念1. 定义2. 组成部分 (二)CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 (三)CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 …...
技术栈RabbitMq的介绍和使用
目录 1. 什么是消息队列?2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...
Visual Studio Code 扩展
Visual Studio Code 扩展 change-case 大小写转换EmmyLua for VSCode 调试插件Bookmarks 书签 change-case 大小写转换 https://marketplace.visualstudio.com/items?itemNamewmaurer.change-case 选中单词后,命令 changeCase.commands 可预览转换效果 EmmyLua…...
Django RBAC项目后端实战 - 03 DRF权限控制实现
项目背景 在上一篇文章中,我们完成了JWT认证系统的集成。本篇文章将实现基于Redis的RBAC权限控制系统,为系统提供细粒度的权限控制。 开发目标 实现基于Redis的权限缓存机制开发DRF权限控制类实现权限管理API配置权限白名单 前置配置 在开始开发权限…...
接口 RESTful 中的超媒体:REST 架构的灵魂驱动
在 RESTful 架构中,** 超媒体(Hypermedia)** 是一个核心概念,它体现了 REST 的 “表述性状态转移(Representational State Transfer)” 的本质,也是区分 “真 RESTful API” 与 “伪 RESTful AP…...
