aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-04-23 20:29:16 +0200
committerTeddy Wing2023-04-23 20:29:58 +0200
commitaebf437ae68eeb443af19847521c904821958b5d (patch)
treecde84e65f89a20e00512bd0980810a50f3cc77a6
parent79635ab1ab59129b90b9c4be95322492770ac45d (diff)
downloadpdf-form-replace-font2-aebf437ae68eeb443af19847521c904821958b5d.tar.bz2
App.java: Extract font replacement code to function
Move this to a new function to make room in `main()` for command line argument parsing.
-rw-r--r--src/main/java/com/teddywing/pdf_form_replace_font2/App.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/com/teddywing/pdf_form_replace_font2/App.java b/src/main/java/com/teddywing/pdf_form_replace_font2/App.java
index 711c78f..3c23ba6 100644
--- a/src/main/java/com/teddywing/pdf_form_replace_font2/App.java
+++ b/src/main/java/com/teddywing/pdf_form_replace_font2/App.java
@@ -18,10 +18,21 @@ import java.util.Map;
public class App {
public static void main(String[] args) throws IOException {
- PdfDocument pdf = new PdfDocument(
+ App.replacePdfFieldFont(
new PdfReader("f1040.pdf"),
- new PdfWriter("f1040-courier.pdf")
+ new PdfWriter("f1040-courier.pdf"),
+ "HelveticaLTStd-Bold",
+ "CourierNewPSMT"
);
+ }
+
+ private static void replacePdfFieldFont(
+ PdfReader reader,
+ PdfWriter writer,
+ String original_font_postscript_name,
+ String replacement_font_postscript_name
+ ) throws IOException {
+ PdfDocument pdf = new PdfDocument(reader, writer);
FontProgramFactory
.registerFontDirectory("/System/Library/Fonts/Supplemental/");
@@ -30,7 +41,7 @@ public class App {
System.out.println(FontProgramFactory.getRegisteredFontFamilies());
FontProgram courier_program = FontProgramFactory
- .createRegisteredFont("CourierNewPSMT");
+ .createRegisteredFont(replacement_font_postscript_name);
PdfFont courier = PdfFontFactory.createFont(
courier_program,
PdfEncodings.UTF8,
@@ -49,11 +60,12 @@ public class App {
.getFontNames()
.getFontName();
- if (original_postscript_name.equals("HelveticaLTStd-Bold")) {
+ if (original_postscript_name.equals(original_font_postscript_name)) {
field.setFont(courier);
}
}
pdf.close();
}
+
}