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

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) {
Document document = new Document(PageSize.A4, 0, 0, 0, 0); //创建文档容器
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PdfWriter writer;
ByteArrayOutputStream bos = null;
FileOutputStream fileOutputStream = null;
PdfWriter writer = null;
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类型
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;
//是否增加标签
@ -124,6 +105,7 @@ public class BatchExportServiceImpl implements BatchExportService {
Integer outNum = 1;
// 添加目录
document.open(); //打开容器
float w, h;
PdfContentByte cb = writer.getDirectContent();
cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 12);
cb.beginText();
@ -147,13 +129,15 @@ public class BatchExportServiceImpl implements BatchExportService {
}
String imagePath = scanPathVos.get(i).getFilePath();
Image image = Image.getInstance(imagePath);
image.setAlignment(Image.MIDDLE);
image.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
// 等比例缩放图片以填满PDF页面
image.scaleAbsolute(document.getPageSize());
/*处理图片缩放比例*/
w = image.getWidth();
h = image.getHeight();
image.setAlignment(com.lowagie.text.Image.ALIGN_CENTER);
image.scaleAbsolute(PageSize.A4.getWidth(), PageSize.A4.getWidth() * (h / w));
// 创建新页面并添加图片
//document.newPage();
if (i != 0) {
document.newPage();
}
document.add(image);
if (outFlag) {
//目录跳转页面内容设置。
@ -165,6 +149,35 @@ public class BatchExportServiceImpl implements BatchExportService {
}
}
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