|
@@ -5,8 +5,10 @@ import com.itextpdf.text.pdf.PdfReader;
|
|
|
import com.itextpdf.text.pdf.PdfStamper;
|
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
|
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
|
|
+import org.apache.pdfbox.util.Matrix;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
@@ -20,6 +22,12 @@ import java.util.Date;
|
|
|
public class PDFServicePDFBOXImpl {
|
|
|
@PostConstruct
|
|
|
public void PDFEncode() throws IOException, DocumentException {
|
|
|
+ int rowSpace=150;
|
|
|
+ int colSpace=150;
|
|
|
+ Date date = new Date();
|
|
|
+ int year = date.getYear() + 1900;
|
|
|
+ int month = date.getMonth() + 1;
|
|
|
+ int day = date.getDay();
|
|
|
PDDocument load = PDDocument.load(new File("E:\\pdf\\SMU749-050-09JS完整稳性计算报告.pdf"));
|
|
|
for (int i = 0; i < load.getNumberOfPages(); i++) {
|
|
|
PDPageContentStream contentStream = new PDPageContentStream(load, load.getPage(i), PDPageContentStream.AppendMode.APPEND, true, true);
|
|
@@ -29,22 +37,29 @@ public class PDFServicePDFBOXImpl {
|
|
|
contentStream.setNonStrokingColor(200, 200, 200, 150);
|
|
|
|
|
|
contentStream.beginText();
|
|
|
- contentStream.newLineAtOffset(100, 100);
|
|
|
- Date date = new Date();
|
|
|
- int year = date.getYear() + 1900;
|
|
|
- int month = date.getMonth() + 1;
|
|
|
- int day = date.getDay();
|
|
|
- contentStream.showText(year + "-" + month + "-" + day);
|
|
|
+ PDPage page = load.getPage(i);
|
|
|
+ float pageHeight = page.getMediaBox().getHeight();
|
|
|
+ float pageWidth = page.getMediaBox().getWidth();
|
|
|
+
|
|
|
+ for (int h = 10; h < pageHeight; h = h + rowSpace) {
|
|
|
+ for (int w = - 10; w < pageWidth; w = w + colSpace) {
|
|
|
+ contentStream.setTextMatrix(Matrix.getRotateInstance(0.3, w, h));
|
|
|
+ contentStream.showText(year + "-" + month + "-" + day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
contentStream.endText();
|
|
|
contentStream.close();
|
|
|
}
|
|
|
load.save("E:\\pdf\\SMU749-050-09JS完整稳性计算报告水印版.pdf");
|
|
|
load.close();
|
|
|
- PdfReader reader = new PdfReader("E:\\pdf\\SMU749-050-09JS完整稳性计算报告水印版.pdf");
|
|
|
- PdfStamper stamper = new PdfStamper(reader, Files.newOutputStream(Paths.get("E:\\pdf\\SMU749-050-09JS完整稳性计算报告水印密码版.pdf")));
|
|
|
- stamper.setEncryption("123456".getBytes(), "12345".getBytes(), PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_40);
|
|
|
- stamper.flush();
|
|
|
- stamper.close();
|
|
|
- reader.close();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|