修改国标病历导出图片比例问题

master
linjj 2 years ago
parent a02feee98c
commit 3b539ddd2b

@ -88,34 +88,15 @@ public class BatchExportServiceImpl implements BatchExportService {
} }
public static Boolean imageToPdf(List<ExportDetailsVo> scanPathVos, String fileName, String exportPdfPath) { public static Boolean imageToPdf(List<ExportDetailsVo> scanPathVos, String fileName, String exportPdfPath) {
Document document = new Document(PageSize.A4, 0, 0, 0, 0); //创建文档容器 ByteArrayOutputStream bos = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream(); FileOutputStream fileOutputStream = null;
PdfWriter writer; PdfWriter writer = null;
try { try {
FileOutputStream fileOutputStream = new FileOutputStream(exportPdfPath+fileName+".pdf"); bos = new ByteArrayOutputStream();
Document document = new Document(PageSize.A4, 0, 0, 0, 0); //创建文档容器
fileOutputStream = new FileOutputStream(exportPdfPath + fileName + ".pdf");
writer = PdfWriter.getInstance(document, fileOutputStream);//创建编写器PDF类型 writer = PdfWriter.getInstance(document, fileOutputStream);//创建编写器PDF类型
imgToPdf(document, writer, scanPathVos);
} catch (Exception e) {
ExceptionPrintUtil.printException(e);
e.printStackTrace();
return false;
} finally {
try {
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
document.close();
}
return true;
}
public static void imgToPdf(Document document, PdfWriter writer, List<ExportDetailsVo> scanPathVos) throws Exception {
//上一个目录名称 //上一个目录名称
String lastOutline = null; String lastOutline = null;
//是否增加标签 //是否增加标签
@ -124,6 +105,7 @@ public class BatchExportServiceImpl implements BatchExportService {
Integer outNum = 1; Integer outNum = 1;
// 添加目录 // 添加目录
document.open(); //打开容器 document.open(); //打开容器
float w, h;
PdfContentByte cb = writer.getDirectContent(); PdfContentByte cb = writer.getDirectContent();
cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 12); cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 12);
cb.beginText(); cb.beginText();
@ -147,13 +129,15 @@ public class BatchExportServiceImpl implements BatchExportService {
} }
String imagePath = scanPathVos.get(i).getFilePath(); String imagePath = scanPathVos.get(i).getFilePath();
Image image = Image.getInstance(imagePath); Image image = Image.getInstance(imagePath);
/*处理图片缩放比例*/
image.setAlignment(Image.MIDDLE); w = image.getWidth();
image.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); h = image.getHeight();
// 等比例缩放图片以填满PDF页面 image.setAlignment(com.lowagie.text.Image.ALIGN_CENTER);
image.scaleAbsolute(document.getPageSize()); image.scaleAbsolute(PageSize.A4.getWidth(), PageSize.A4.getWidth() * (h / w));
// 创建新页面并添加图片 // 创建新页面并添加图片
//document.newPage(); if (i != 0) {
document.newPage();
}
document.add(image); document.add(image);
if (outFlag) { if (outFlag) {
//目录跳转页面内容设置。 //目录跳转页面内容设置。
@ -165,6 +149,35 @@ public class BatchExportServiceImpl implements BatchExportService {
} }
} }
document.close(); //关闭容器 document.close(); //关闭容器
} catch (Exception e) {
ExceptionPrintUtil.printException(e);
e.printStackTrace();
return false;
} finally {
try {
if (writer != null) {
writer.close();
}
if (fileOutputStream != null) {
fileOutputStream.close();
}
if (bos != null) {
bos.flush();
bos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
public static void imgToPdf(Document document, PdfWriter writer, List<ExportDetailsVo> scanPathVos) throws Exception {
} }

Loading…
Cancel
Save