@@ -38,7 +38,7 @@ public class FlattenPDF {
3838 * The DPI that should be used when generating images.
3939 * Higher DPI increases the memory requirements and output file sizes, but also produces sharper images.
4040 */
41- public static final int IMAGE_DPI = 200 ;
41+ public static int IMAGE_DPI = 200 ;
4242
4343
4444 public static void main (String [] args ) {
@@ -130,7 +130,25 @@ public static void main(String[] args) {
130130 if (!destinationFile .getName ().toLowerCase ().endsWith (".pdf" )) {
131131 destinationFile = new File (destinationFile .getAbsolutePath () + ".pdf" );
132132 }
133-
133+
134+
135+ /*
136+ * Set the DPI
137+ */
138+
139+
140+ String possibleDPI = JOptionPane .showInputDialog (
141+ "What is your preferred output image DPI?\n " +
142+ "The higher the number, the higher the quality, but also, the higher the output file size. If unsure, 200 gives quite good results." ,
143+ IMAGE_DPI );
144+
145+ try {
146+ IMAGE_DPI = Integer .parseInt (possibleDPI );
147+ }
148+ catch (NumberFormatException e ) {
149+ JOptionPane .showMessageDialog (null , "Invalid DPI. Using " + IMAGE_DPI + "." , "Error" , JOptionPane .ERROR_MESSAGE );
150+ }
151+
134152
135153 /*
136154 * Do the flattening
@@ -139,7 +157,8 @@ public static void main(String[] args) {
139157 JOptionPane .showMessageDialog (null , "You are about to flatten\n " +
140158 sourceFile .getAbsolutePath () + "\n " +
141159 "into the new file\n " +
142- destinationFile .getAbsolutePath () + "\n \n " +
160+ destinationFile .getAbsolutePath () + "\n " +
161+ "at " + IMAGE_DPI + " DPI.\n \n " +
143162 "This will run in the background. Please be patient as it may take some time." ,
144163 "Ready to Start" ,
145164 JOptionPane .INFORMATION_MESSAGE );
0 commit comments