blob: 6b92fcd76a1a33dea90a36dc81ee1c9015050483 (
plain)
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
|
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.kernel.font.*;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.forms.*;
import com.itextpdf.forms.fields.*;
import java.io.*;
import java.util.Map;
public class Main {
public static void main(String args[]) throws IOException {
PdfDocument pdf = new PdfDocument(
new PdfReader("f1040.pdf"),
new PdfWriter("f1040-courier.pdf")
);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, false);
PdfFont courier = PdfFontFactory.createFont(StandardFonts.COURIER);
Map<String, PdfFormField> fields = form.getFormFields();
for (var entry : fields.entrySet()) {
// TODO: Try printing original font family and size on field.
PdfFormField field = entry.getValue();
PdfFont original_font = field.getFont();
// System.out.println("Font: " + original_font);
String original_postscript_name = original_font
.getFontProgram()
.getFontNames()
.getFontName();
if (original_postscript_name.equals("HelveticaLTStd-Bold")) {
field.setFont(courier);
}
}
pdf.close();
}
}
|