|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.PDFUtils
@ThirdParty(value={"uses itext - see itextpdf.com","JFreeChart - see jfree.org"})
public class PDFUtilsa few utility methods surrounding PDF. This class uses the IText package from lowagie.com: iText Library - Copyright (C) 1999-2005 by Bruno Lowagie and Paulo Soares. All Rights Reserved. This class also uses the JFreeChart library (www.jfree.org). Since November 2015, this implementation has been upgraded to work w/ com.itextpdf instead of the old com.lowagie!
| Field Summary | |
|---|---|
static int |
ALLOW_ASSEMBLY
|
static int |
ALLOW_COPY
|
static int |
ALLOW_DEGRADED_PRINTING
|
static int |
ALLOW_FILL_IN
|
static int |
ALLOW_MODIFY_ANNOTATIONS
|
static int |
ALLOW_MODIFY_CONTENTS
|
static int |
ALLOW_PRINTING
|
static int |
ALLOW_SCREENREADERS
|
| Method Summary | |
|---|---|
static void |
concat(File target,
File... pdfFiles)
|
static void |
concat(OutputStream out,
InputStream... pdfStreams)
|
static void |
concat(OutputStream out,
Iterator<? extends InputStream> pdfStreams)
|
static void |
encryptPDF(InputStream in,
OutputStream out,
String userPassword,
String ownerPassword,
int permissions)
allows to encrypt a PDF-input with a password and write the protected result into the PDF-output |
static void |
exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart)
|
static void |
exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart,
int width,
int height)
|
static void |
exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart,
int width,
int height,
com.itextpdf.awt.FontMapper fontMapper,
float scale)
|
static void |
extract(OutputStream out,
InputStream pdfContent,
int... pages)
first page is 1 |
static AbstractIterator<BufferedImage> |
extractImages(InputStream pdfStream)
only works on a limited subset of PDF documents, unfortunately; happens to work just fine w/ PDFs produced by common scanners :) |
static void |
generatePDF(String text,
File file)
uses the IText package from lowagie.com |
static int |
getNumberOfPages(InputStream pdfContent)
|
static void |
merge(OutputStream out,
InputStream mainPdfContent,
InputStream underPdfContent)
the new document (in regards to its size) is based on the mainPdfContent |
static void |
merge(OutputStream out,
InputStream mainPdfContent,
InputStream underPdfContent,
int mainStartPage)
merges the main content with the other content starting with the given page on the main content; first page is 1 |
static void |
place(OutputStream out,
InputStream pdfSource,
Image image,
boolean ontop,
int pageNumber,
Point position)
uses 300 dpi; see place(OutputStream, InputStream, Image, boolean, int, Point, int) |
static void |
place(OutputStream out,
InputStream pdfSource,
Image image,
boolean ontop,
int pageNumber,
Point position,
int dpi)
places the given image either on top or under the content of the specified page |
static void |
place(OutputStream out,
InputStream pdfSource,
InputStream pdfContent,
boolean ontop,
int pageNumber,
Point position)
calls place(OutputStream, InputStream, InputStream, boolean, int, Point, float)
with a scale of 1 |
static void |
place(OutputStream out,
InputStream pdfSource,
InputStream pdfContent,
boolean ontop,
int pageNumber,
Point position,
float scale)
places the first page of the given pdfContent either on top or under the pdfSource on the specified page(s). |
static void |
placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
boolean ontop,
int pageNumber,
Point position)
|
static void |
placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
int width,
int height,
boolean ontop,
int pageNumber,
Point position)
|
static void |
placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
int width,
int height,
boolean ontop,
int pageNumber,
Point position,
float scale)
|
static Process |
printPDF(File pdfFile)
platform dependent system call to print the given file to the default printer. |
static void |
rotatePages(InputStream pdfSource,
OutputStream target,
double degrees)
rotates all pages by the given degrees |
static void |
rotatePages(InputStream pdfSource,
OutputStream target,
Map<Integer,? extends Number> pageDegrees)
rotates each given page number in the map with the mapped degrees |
static void |
splitIntoPages(File pdfFile,
Monitor mon)
splits the given document into separate files, where each page becomes a file named after the given file plus the page number |
static void |
stamp(OutputStream out,
InputStream pdfSource,
Image image,
int pageNumber)
see place(OutputStream, InputStream, Image, boolean, int, Point) |
static void |
toPDF(Component c,
File file)
|
static void |
toPDF(Component c,
OutputStream pdfStream)
uses 300 dpi |
static void |
toPDF(Component c,
OutputStream pdfStream,
int dpi)
produces a PDF document with the given output stream and places the given component on the page; the orientation of the document follows the width/height ratio of the component. |
static void |
toPDF(String txt,
OutputStream pdfStream)
|
static void |
watermark(OutputStream out,
InputStream pdfSource,
Image image,
int pageNumber)
see place(OutputStream, InputStream, Image, boolean, int, Point) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int ALLOW_ASSEMBLY
public static final int ALLOW_COPY
public static final int ALLOW_DEGRADED_PRINTING
public static final int ALLOW_FILL_IN
public static final int ALLOW_MODIFY_ANNOTATIONS
public static final int ALLOW_MODIFY_CONTENTS
public static final int ALLOW_PRINTING
public static final int ALLOW_SCREENREADERS
| Method Detail |
|---|
public static void exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart)
throws IOException
IOException
public static void exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart,
int width,
int height)
throws IOException
IOException
@ThirdParty(value="jfreechart")
public static void exportChartAsPDF(OutputStream out,
org.jfree.chart.JFreeChart chart,
int width,
int height,
com.itextpdf.awt.FontMapper fontMapper,
float scale)
throws IOException
IOException
public static void placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
boolean ontop,
int pageNumber,
Point position)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentExceptionplaceChartOnPage(OutputStream, InputStream, JFreeChart, int, int, boolean, int, Point)
public static void placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
int width,
int height,
boolean ontop,
int pageNumber,
Point position)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentExceptionplace(OutputStream, InputStream, InputStream, boolean, int, Point),
exportChartAsPDF(OutputStream, JFreeChart, int, int)
public static void placeChartOnPage(OutputStream out,
InputStream pdfSource,
org.jfree.chart.JFreeChart chart,
int width,
int height,
boolean ontop,
int pageNumber,
Point position,
float scale)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentExceptionplace(OutputStream, InputStream, InputStream, boolean, int, Point),
exportChartAsPDF(OutputStream, JFreeChart, int, int, FontMapper, float)
public static void watermark(OutputStream out,
InputStream pdfSource,
Image image,
int pageNumber)
throws IOException,
com.itextpdf.text.DocumentException
place(OutputStream, InputStream, Image, boolean, int, Point)
IOException
com.itextpdf.text.DocumentException
public static void stamp(OutputStream out,
InputStream pdfSource,
Image image,
int pageNumber)
throws IOException,
com.itextpdf.text.DocumentException
place(OutputStream, InputStream, Image, boolean, int, Point)
IOException
com.itextpdf.text.DocumentException
public static void place(OutputStream out,
InputStream pdfSource,
Image image,
boolean ontop,
int pageNumber,
Point position)
throws IOException,
com.itextpdf.text.DocumentException
place(OutputStream, InputStream, Image, boolean, int, Point, int)
IOException
com.itextpdf.text.DocumentException
public static void place(OutputStream out,
InputStream pdfSource,
Image image,
boolean ontop,
int pageNumber,
Point position,
int dpi)
throws IOException,
com.itextpdf.text.DocumentException
out - the stream where the resulting PDF should be writtenpdfSource - the original PDF document sourceimage - the image to be placed on the page(s)pageNumber - specifies the page where the content is to be placed; if negative, the content is written on every pageontop - if true, the image is placed on top like a stamp; if false, the image is place beneath like a watermarkposition - denotes the absolute position of the image; if null, the image is centered on the page
IOException
com.itextpdf.text.DocumentException
public static void place(OutputStream out,
InputStream pdfSource,
InputStream pdfContent,
boolean ontop,
int pageNumber,
Point position)
throws IOException,
com.itextpdf.text.DocumentException
place(OutputStream, InputStream, InputStream, boolean, int, Point, float)
with a scale of 1
IOException
com.itextpdf.text.DocumentException
public static void place(OutputStream out,
InputStream pdfSource,
InputStream pdfContent,
boolean ontop,
int pageNumber,
Point position,
float scale)
throws IOException,
com.itextpdf.text.DocumentException
out - the stream where the resulting PDF should be writtenpdfSource - the original PDF document sourcepdfContent - the content to be placed on the page(s) (only the first page is used)pageNumber - specifies the page where the content is to be placed; if less than 1, the content is written on every pageontop - if true, the image is placed on top like a stamp; if false, the image is place beneath like a watermarkposition - denotes the absolute position of the image; if null, the image is centered on each pagescale - specifies the scale (1 for no scale) that is to be applied to the pdfContent before placing it
IOException
com.itextpdf.text.DocumentException
public static int getNumberOfPages(InputStream pdfContent)
throws IOException
IOException
public static void extract(OutputStream out,
InputStream pdfContent,
int... pages)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void splitIntoPages(File pdfFile,
Monitor mon)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void merge(OutputStream out,
InputStream mainPdfContent,
InputStream underPdfContent)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void merge(OutputStream out,
InputStream mainPdfContent,
InputStream underPdfContent,
int mainStartPage)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void concat(File target,
File... pdfFiles)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void concat(OutputStream out,
InputStream... pdfStreams)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static void concat(OutputStream out,
Iterator<? extends InputStream> pdfStreams)
throws IOException,
com.itextpdf.text.DocumentException
IOException
com.itextpdf.text.DocumentException
public static Process printPDF(File pdfFile)
throws IOException
application.pdfPrintCommand from the Settings.
The switches used for the AcroRd32.exe are "/p /h".
IOExceptionSettings.getProperties()
public static void generatePDF(String text,
File file)
throws IOException,
PrintException
IOException
PrintException
public static void toPDF(Component c,
File file)
throws IOException,
com.itextpdf.text.DocumentException,
PrintException
IOException
com.itextpdf.text.DocumentException
PrintExceptiontoPDF(Component, OutputStream)
public static void toPDF(Component c,
OutputStream pdfStream)
throws IOException,
PrintException
IOException
PrintExceptiontoPDF(Component, OutputStream, int)
public static void toPDF(Component c,
OutputStream pdfStream,
int dpi)
throws IOException,
PrintException
c - the component to be printed on a PDF-pagepdfStream - the stream to where the PDF is to be written; the stream is closed within this method
IOException
PrintException
public static void toPDF(String txt,
OutputStream pdfStream)
throws IOException,
PrintException
IOException
PrintException
public static void rotatePages(InputStream pdfSource,
OutputStream target,
double degrees)
throws com.itextpdf.text.DocumentException,
IOException
com.itextpdf.text.DocumentException
IOException
public static void rotatePages(InputStream pdfSource,
OutputStream target,
Map<Integer,? extends Number> pageDegrees)
throws IOException,
com.itextpdf.text.DocumentException
pageDegrees - maps page numbers to the rotation degrees
IOException
com.itextpdf.text.DocumentException
public static AbstractIterator<BufferedImage> extractImages(InputStream pdfStream)
throws IOException
IOException
@ThirdParty(value="org.bouncycastle")
public static void encryptPDF(InputStream in,
OutputStream out,
String userPassword,
String ownerPassword,
int permissions)
throws IOException,
IllegalArgumentException,
PrintException
in - the PDF-inputout - the PDF-outputuserPassword - the password used to be able to read the encrypted output documentownerPassword - the password that allows not only read the document, but also to change
the permissions of the PDF-file (in order to create an unprotected version)permissions - permissions 'or'-like combined user permissions like ALLOW_PRINTING
IOException
IllegalArgumentException
PrintException
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||