|
@@ -1,47 +1,48 @@
|
|
|
-//package com.shcd.ghjg_pdf.service.impl;
|
|
|
-//
|
|
|
-//import com.spire.pdf.FileFormat;
|
|
|
-//import com.spire.pdf.PdfDocument;
|
|
|
-//import com.spire.pdf.PdfPageBase;
|
|
|
-//import com.spire.pdf.graphics.PdfBrush;
|
|
|
-//import com.spire.pdf.graphics.PdfBrushes;
|
|
|
-//import com.spire.pdf.graphics.PdfFontBase;
|
|
|
-//import com.spire.pdf.graphics.PdfTrueTypeFont;
|
|
|
-//import jakarta.annotation.PostConstruct;
|
|
|
-//import org.springframework.stereotype.Component;
|
|
|
-//
|
|
|
-//import java.awt.*;
|
|
|
-//
|
|
|
-//@Component
|
|
|
-//public class PDFServiceFreeSpire {
|
|
|
-// //不可使用,会自动增加水印
|
|
|
-// @PostConstruct
|
|
|
-// public void pdfFreeSpire(){
|
|
|
-// //创建PdfDocument对象
|
|
|
-// PdfDocument doc = new PdfDocument();
|
|
|
-//
|
|
|
-// //加载一个PDF文档
|
|
|
-// doc.loadFromFile("E:\\pdf\\DM8_DIsql使用手册.pdf");
|
|
|
+package com.shcd.ghjg_pdf.service.impl;
|
|
|
+
|
|
|
+import com.spire.pdf.FileFormat;
|
|
|
+import com.spire.pdf.PdfDocument;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class PDFServiceFreeSpire {
|
|
|
+ //不可使用,会自动增加水印
|
|
|
+ //@PostConstruct
|
|
|
+ public void pdfFreeSpire() {
|
|
|
+ //创建PdfDocument对象
|
|
|
+ PdfDocument pdfDocument = new PdfDocument();
|
|
|
+ //加载一个PDF文档
|
|
|
+ pdfDocument.loadFromFile("E:\\pdf\\DM8_DIsql使用手册_水印.pdf");
|
|
|
+ pdfDocument.saveToFile("E:\\pdf\\DM8_DIsql使用手册_水印2.html", FileFormat.HTML);
|
|
|
// PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体", Font.PLAIN, 50));
|
|
|
-// for (int i = 0; i < doc.getPages().getCount(); i++) {
|
|
|
+// int count = doc.getPages().getCount();
|
|
|
+// //代表是10的倍数
|
|
|
+// int circle = count / 10;
|
|
|
+// int left = count % 10;
|
|
|
+// //递归法做水印
|
|
|
+// for (int i = 0; i < count; i++) {
|
|
|
+// PdfDocument pdfDocument = new PdfDocument();
|
|
|
+// pdfDocument.getPageSettings().setMargins(new PdfMargins(0, 0, 0, 0));
|
|
|
// PdfPageBase pageBase = doc.getPages().get(i);
|
|
|
// pageBase.getCanvas().setTransparency(0.8);
|
|
|
-// pageBase.getCanvas().translateTransform(pageBase.getCanvas().getSize().getWidth()/2,pageBase.getCanvas().getSize().getHeight()/2);
|
|
|
+// pageBase.getCanvas().translateTransform(pageBase.getCanvas().getSize().getWidth() / 2, pageBase.getCanvas().getSize().getHeight() / 2);
|
|
|
// pageBase.getCanvas().rotateTransform(-45);
|
|
|
-// pageBase.getCanvas().drawString("test",font, PdfBrushes.getDarkBlue(),0,0);
|
|
|
+// pageBase.getCanvas().drawString("test", font, PdfBrushes.getDarkBlue(), 0, 0);
|
|
|
// }
|
|
|
-// //通过JavaScript设置过期时间,过期警告信息并关闭文档
|
|
|
-//// String javaScript =
|
|
|
-//// "app.alert('该文档已过期,请联系我们获取新文档',1);"
|
|
|
-//// + "this.closeDoc(); ";
|
|
|
-//
|
|
|
-// //根据JS创建PdfJavaScriptAction
|
|
|
-// //PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);
|
|
|
-//
|
|
|
-// //将PdfJavaScriptAction设置为文档打开后的动作
|
|
|
-// //doc.setAfterOpenAction(js);
|
|
|
-//
|
|
|
-// //保存文档
|
|
|
-// doc.saveToFile("E:\\pdf\\test.pdf", FileFormat.PDF);
|
|
|
-// }
|
|
|
-//}
|
|
|
+ //通过JavaScript设置过期时间,过期警告信息并关闭文档
|
|
|
+// String javaScript =
|
|
|
+// "app.alert('该文档已过期,请联系我们获取新文档',1);"
|
|
|
+// + "this.closeDoc(); ";
|
|
|
+
|
|
|
+ //根据JS创建PdfJavaScriptAction
|
|
|
+ //PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);
|
|
|
+
|
|
|
+ //将PdfJavaScriptAction设置为文档打开后的动作
|
|
|
+ //doc.setAfterOpenAction(js);
|
|
|
+
|
|
|
+ //保存文档
|
|
|
+ }
|
|
|
+
|
|
|
+}
|