|
|
|
@ -82,7 +82,6 @@ public class Jpg2PdfUtil {
|
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
|
// pdf合并工具类
|
|
|
|
|
Document document = null;
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
PdfCopy copy = null;
|
|
|
|
|
try {
|
|
|
|
|
response.reset();
|
|
|
|
@ -90,24 +89,34 @@ public class Jpg2PdfUtil {
|
|
|
|
|
copy = new PdfCopy(document, response.getOutputStream());
|
|
|
|
|
document.open();
|
|
|
|
|
for (PdfReader reader : list) {
|
|
|
|
|
bos.flush();
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
PdfReader pdfReader = null;
|
|
|
|
|
//判断是否加水印
|
|
|
|
|
if (StringUtils.isNotBlank(waterMarkName)) {
|
|
|
|
|
setWatermark(bos, reader, waterMarkName, null);
|
|
|
|
|
reader = new PdfReader(bos.toByteArray());
|
|
|
|
|
pdfReader = new PdfReader(bos.toByteArray());
|
|
|
|
|
}
|
|
|
|
|
int n = reader.getNumberOfPages();
|
|
|
|
|
for (int j = 1; j <= n; j++) {
|
|
|
|
|
document.newPage();
|
|
|
|
|
PdfImportedPage page = null;
|
|
|
|
|
if (StringUtils.isNotBlank(waterMarkName)) {
|
|
|
|
|
page = copy.getImportedPage(reader, j);
|
|
|
|
|
page = copy.getImportedPage(pdfReader, j);
|
|
|
|
|
} else {
|
|
|
|
|
page = copy.getImportedPage(reader, j);
|
|
|
|
|
}
|
|
|
|
|
copy.addPage(page);
|
|
|
|
|
}
|
|
|
|
|
if(null != pdfReader){
|
|
|
|
|
pdfReader.close();
|
|
|
|
|
}
|
|
|
|
|
reader.close();
|
|
|
|
|
try {
|
|
|
|
|
bos.flush();
|
|
|
|
|
bos.close();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
@ -115,12 +124,6 @@ public class Jpg2PdfUtil {
|
|
|
|
|
if (null != copy) {
|
|
|
|
|
copy.close();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
bos.flush();
|
|
|
|
|
bos.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (null != document) {
|
|
|
|
|
document.close();
|
|
|
|
|
}
|
|
|
|
@ -150,15 +153,27 @@ public class Jpg2PdfUtil {
|
|
|
|
|
content.setColorFill(Color.LIGHT_GRAY);
|
|
|
|
|
content.setFontAndSize(base, 50);
|
|
|
|
|
content.setTextMatrix(70, 200);
|
|
|
|
|
String[] waterMarks = waterMarkName.split("&");
|
|
|
|
|
//v:距左 v1:距下 v2:
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 300, 600, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 300, 200, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 800, 600, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 800, 200, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 300, 1100, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 300, 1500, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 800, 1100, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarkName, 800, 1500, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 250, 600, 40);
|
|
|
|
|
/*content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 250, 200, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 800, 600, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 800, 200, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 250, 1100, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 250, 1500, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 800, 1100, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[0], 800, 1500, 40);*/
|
|
|
|
|
if(waterMarks.length > 1){
|
|
|
|
|
//v:距左 v1:距下 v2:
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 310, 400, 40);
|
|
|
|
|
/* content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 310, 150, 40);*/
|
|
|
|
|
/*content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 860, 550, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 860, 150, 40);*/
|
|
|
|
|
/* content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 300, 900, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 300, 1300, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 800, 900, 40);
|
|
|
|
|
content.showTextAligned(Element.ALIGN_CENTER, waterMarks[1], 800, 1300, 40);*/
|
|
|
|
|
}
|
|
|
|
|
content.endText();
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|