📄 pdftool.java
字号:
} else if (opt.equals("--format=png")) { format="PNG"; } else if (opt.equals("--format=jpeg")) { format="JPEG"; } else if (opt.startsWith("--pages=")) { pages = getValue(opt); } else if (opt.startsWith("--output=")) { out = new FileOutputStream(getValue(opt)); } else if (opt.startsWith("--")) { i.previous(); return; } else { pdf = load(opt); } } if (pdf!=null) { RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); PDFParser parser = new PDFParser(pdf); if (format=="tiff") { parser.writeAsTIFF(out, dpi, cm, hints); } else { java.awt.image.BufferedImage image = parser.getPagePainter(0).getImage(dpi, cm); javax.imageio.ImageIO.write(image, format, out); } out.close(); } } private static void view(ListIterator i, final PDF pdf, final String filename) throws IOException { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { PDFViewer viewer = PDFViewer.newPDFViewer(); if (pdf!=null) viewer.loadPDF(pdf, filename); } }); } private static void usage() { System.err.println(APPNAME+" "+PDF.VERSION); System.err.println(" Run "+APPNAME+" to open the viewer"); System.err.println(" Run "+APPNAME+" --help for more information"); System.err.println(); } private static void help() { System.out.println("Usage: "+APPNAME+" [ --output=<outfile> | <infile> | <command> ] *"); System.out.println(); System.out.println(" This program runs a pipeline of one or more operations on a PDF. The initial"); System.out.println(" PDF can be loaded (<infile> in the argument list above) and operations"); System.out.println(" performed on it, after which it is written to standard out or <outfile> if"); System.out.println(" it's specified."); System.out.println(); System.out.println(" General arguments are:"); System.out.println(" --output=<outfile>"); System.out.println(" Set the file to write to. If not specified the default is standard out"); System.out.println(); System.out.println(" --profile=<profile>"); System.out.println(" Set the output profile to use when rendering the PDF. Valid values are"); System.out.println(" 'nocompression', 'acrobat4', 'acrobat5', 'acrobat6', 'acrobat7'"); System.out.println(" or 'recompression' (which recompresses uncompressed files)"); System.out.println(); System.out.println(" <infile>"); System.out.println(" The PDF to work on. Must be specified somewhere in the parameter list"); System.out.println(" unless the <filename> parameter is used with the join command."); System.out.println(); System.out.println(" Command sequences can be one of the following:"); System.out.println(); System.out.println(" --version"); System.out.println(); System.out.println(" Display a short message then exit"); System.out.println(); System.out.println(" --help"); System.out.println(); System.out.println(" Display this message then exit"); System.out.println(); System.out.println(" --join [ [--pages=<list>] [--pagesize=<size>] [--dpi=<dpi>] <filename> ] *"); System.out.println(); System.out.println(" To concatenate a sequence of PDFs: Arguments are:"); System.out.println(); System.out.println(" --pagesize=<size>"); System.out.println(" Set the size of the output pages. Valid values include A4, letter"); System.out.println(" A4-landscape, 8.5x11in, 210x297mm and so on. The pagesize values is"); System.out.println(" kept across input documents"); System.out.println(); System.out.println(" --dpi=<dpi>"); System.out.println(" For input files that are bitmap images, this is an alternative way"); System.out.println(" to set the output page size - by setting the DPI of the input image."); System.out.println(" Valid values are 1 to 600 (or 0 to use the default)"); System.out.println(); System.out.println(" --pages=<list>"); System.out.println(" Set which pages from the next input file to use. List may be the"); System.out.println(" value 'all' for all pages, 'reverse' to reverse the list or a comma-"); System.out.println(" seperated list of values, eg '1,2-5'. The value 'end' means the last"); System.out.println(" page, and sequences may be backwards - eg. 'reverse' is equivalent"); System.out.println(" to 'end-1'."); System.out.println(); System.out.println(" <filename>"); System.out.println(" The file to join to the existing PDF. May be a PDF, TIFF, JPEG, GIF"); System.out.println(" PNG or PNM file"); System.out.println(); System.out.println(" --form [--flatten] [--xfa=<xfafile>] [--fdf=<fdffile>]"); System.out.println(" [ [--properties=<propfile>] [--field=key=value] ] *"); System.out.println(); System.out.println(" To complete a PDF form: Arguments are:"); System.out.println(); System.out.println(" --properties=<propfile>"); System.out.println(" Load the field values from the specified properties file. The keys"); System.out.println(" in the file are the field names, the values the value to use"); System.out.println(); System.out.println(" --field=<key>=<value>"); System.out.println(" Set the specified field to the specified value."); System.out.println(); System.out.println(" --xfa=<xfafile>"); System.out.println(" For a document containing an XFA form, set the form using the"); System.out.println(" \"datasets\" object from the specified file. If this parameter is"); System.out.println(" used any \"fields\" or \"properties\" parameters will be ignored."); System.out.println(); System.out.println(" --fdf=<fdffile>"); System.out.println(" Used to import an FDF or XFDF file into a PDF. If this parameter is"); System.out.println(" used any \"fields\" or \"properties\" parameters will be ignored."); System.out.println(); System.out.println(" --flatten"); System.out.println(" Flatten the form after completion"); System.out.println(""); System.out.println(" --sign --keystore=<keystore> --alias=<alias> --password=<password>"); System.out.println(" [--keypassword=<keypassword>] [--keystoretype=<keystoretype>]"); System.out.println(" [--location=<location>] [--name=<name>] [--reason=<reason>]"); System.out.println(" [--bottom=<bottom>] [--left=<left>] [--right=<right>] [--top=<top>]"); System.out.println(" [--page=<page>] [--field=<field>"); System.out.println(); System.out.println(" Digitally sign a PDF file: Arguments are:"); System.out.println(); System.out.println(" --keystore=<keystore>"); System.out.println(" The filename to load the keystore from. Must be specified."); System.out.println(); System.out.println(" --alias=<alias>"); System.out.println(" The alias to use from the keystore. Must be specified."); System.out.println(); System.out.println(" --password=<password>"); System.out.println(" The password to unlock the keystore. Must be specified."); System.out.println(); System.out.println(" --keystoretype=<keystoretype>"); System.out.println(" The type of keystore. The default is 'JKS', 'pkcs7' is also common"); System.out.println(); System.out.println(" --reason=<reason>"); System.out.println(" The reason for signing"); System.out.println(); System.out.println(" --location=<location>"); System.out.println(" The location the document is signed at"); System.out.println(); System.out.println(" --name=<name>"); System.out.println(" The name of the person who is signing the document"); System.out.println(); System.out.println(" --field=<field>"); System.out.println(" The name of the signature field. If it doesn't already exist in"); System.out.println(" the PDF a new field is created with this name"); System.out.println(); System.out.println(" --page=<page>"); System.out.println(" The page number to put the signature appearance on, if required."); System.out.println(); System.out.println(" --left, top, right, bottom"); System.out.println(" The location on the page to add the new field. The default is not"); System.out.println(" to create a visible appearance for the signature"); System.out.println(); System.out.println(" --toimage [--format=<format>} [--model=<model>] [--dpi=<dpi>]"); System.out.println(); System.out.println(" To convert a PDF to a bitmap image - this must be the last command in"); System.out.println(" the sequence (once a PDF is a TIFF there's nothing more you can do with"); System.out.println(" it). Arguments are:"); System.out.println(); System.out.println(" --format=<format>"); System.out.println(" Set the output file format. Values are 'tiff', 'png', 'jpeg'. The"); System.out.println(" default is 'tiff', which will produce a multi-page document. 'png'"); System.out.println(" and 'jpeg' will result in a single page document only"); System.out.println(); System.out.println(" --model=<model>"); System.out.println(" Set the ColorModel. Values are 'bw', 'gray', 'rgb', 'rgba', 'cmyk'"); System.out.println(" or 'bwNNN', where NNN is a value betwen 1 and 255 and sets how dark"); System.out.println(" a color must be to be converted to black. The default model is 'bw'"); System.out.println(); System.out.println(" --dpi=<dpi>"); System.out.println(" Set the DPI of the final file. Valid values are 1 to 600. The"); System.out.println(" default is 200dpi"); System.out.println(); System.out.println(" --view"); System.out.println(); System.out.println(" Open the viewer. If a PDF has been specified on the command line, it"); System.out.println(" will be opened. This must be the last command in the sequence."); System.out.println(); System.out.println(); System.out.println(" Some examples:"); System.out.println(" 1. To join two files then save them uncompressed"); System.out.println(" "+APPNAME+" --profile=nocompression --join file1.pdf file2.tif > output.pdf"); System.out.println(); System.out.println(" 2. To complete a form then display the result"); System.out.println(" "+APPNAME+" in.pdf --form --field=name=John --field=date='20 May' --view"); System.out.println(); System.out.println(" 3. To reverse a PDF then convert it to a TIFF"); System.out.println(" "+APPNAME+" --join --pages=reverse file.pdf --output=out.tif --toimage"); System.out.println(); System.out.println(" 4. To use only some pages from a source PDF"); System.out.println(" "+APPNAME+" --join --pages=1,3-7,10-end file1.pdf > out.pdf"); System.out.println(); System.out.println(" 5. To open and display a PDF"); System.out.println(" "+APPNAME+" file.pdf"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -