-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStamptext.java
More file actions
59 lines (39 loc) · 1.44 KB
/
Stamptext.java
File metadata and controls
59 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package part2.chapter06;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
public class Stamptext {
public static final String myPdfSheets
= "myPdfSheets.pdf";
public static final String myPdfSheets_stamped
= "myPdfSheets_stamped.pdf";
// The legend file with the watermark You need.
public static final String leyend
= "leyend.pdf";
public static void main(String[] args)
throws DocumentException, IOException {
PdfReader reader = new PdfReader(myPdfSheets);
manipulateWithStamper(reader);
}
private static void manipulateWithStamper(PdfReader reader)
throws IOException, DocumentException {
// Legend or Watermark coming from the pdf file
PdfReader s_reader = new PdfReader(leyend);
// stamper
PdfStamper stamper =
new PdfStamper(reader, new FileOutputStream(myPdfSheets_stamped));
PdfImportedPage pageLeyend = stamper.getImportedPage(s_reader, 1);
stamper.setRotateContents(false);
// Canvas to write text and then add to the page
PdfContentByte background;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
background = stamper.getUnderContent(i);
background.addTemplate(pageLeyend, 0, 0);
}
stamper.close();
}
}