public class PDFUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
RANGE_DELIMITER |
Constructor and Description |
---|
PDFUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addAutoPrint(java.io.InputStream pdfStream,
java.io.OutputStream outputStream)
Adds a piece of javascript to the PDF, that will cause it to print when
opened in a browser's viewer.
|
static void |
addPdfToOutput(com.itextpdf.text.pdf.PdfReader pdfReader,
com.itextpdf.text.pdf.PdfCopy writer)
Add an entire pdf to an existing pdf writer
|
static org.apache.commons.io.output.ByteArrayOutputStream |
appendPDFSigPage(com.itextpdf.text.pdf.PdfReader content,
com.itextpdf.text.pdf.PdfReader sigPage,
int legacyNumOfSigPages)
Static method that appends a signature page to a document.
|
static boolean |
canBeRead(java.lang.String ticket,
java.lang.String objectId)
Checks if the content of a pdf can be read.
|
static void |
concatPDFs(java.util.List<com.itextpdf.text.pdf.PdfReader> pdfFileReaders,
java.io.OutputStream baos,
java.util.Map<java.lang.String,java.lang.String> headers)
Static method that combines PDFS into a new file.
|
static java.io.ByteArrayOutputStream |
encryptPdf(java.io.ByteArrayOutputStream os)
Encrypts a pdf output stream
This function defaults the encrypted document to print permissions and AESx256 encryption.
|
static java.io.ByteArrayOutputStream |
encryptPdf(java.io.ByteArrayOutputStream os,
java.lang.String password,
int permissions,
int algorithm)
Encrypts a ByteArrayOutputStream representation of a pdf
Sets the encryption password, permissions, and algorithm to the parameter values.
|
static java.io.InputStream |
encryptPdf(java.io.InputStream originalPdf)
Encrypts a pdf input stream
This function defaults the encrypted document to print permissions and AESx256 encryption.
|
static void |
encryptPdf(java.io.InputStream originalPdf,
java.io.OutputStream resp)
Encrypts a pdf input stream, and saves content to an output stream
Defaults the encrypted document to print permissions and AESx256 encryption.
|
static java.io.InputStream |
encryptPdf(java.io.InputStream originalPdf,
java.lang.String password,
int permissions,
int algorithm)
Encrypts a pdf input stream
Sets the encryption password, permissions, and algorithm to the parameter values.
|
static byte[] |
flateFilterDecode(byte[] decodedAttachment)
Decodes the data with a Flate filter.
|
static byte[] |
flateFilterEncode(byte[] fileContent)
Encodes the data with a Flate filter.
|
static org.apache.commons.io.output.ByteArrayOutputStream |
generateTimelinePdf(float duration)
Generates a new vertical timeline PDF using the 'one minute per-page' rules.
|
static com.aspose.pdf.Document |
getAsposeDocument(java.lang.String ticket,
java.lang.String objectId)
Generates an Aspose Document.
|
static int |
getPageCount(java.io.InputStream is)
Get the number of pages for a pdf
|
static org.apache.pdfbox.pdmodel.PDDocument |
getPDDcoument(java.lang.String ticket,
java.lang.String objectId,
long lastModified)
Generates a PDDocument for PDFBox operations.
|
static com.itextpdf.text.pdf.PdfReader |
getPdfReader(java.lang.String ticket,
java.lang.String objectId,
long lastModified)
Generates a PDFReader for iText operations.
|
static org.apache.commons.io.output.ByteArrayOutputStream |
getPDFSection(java.io.InputStream is,
org.apache.commons.io.output.ByteArrayOutputStream baos,
java.lang.String pageRangeString)
Splits the pdf given by the input stream according to the page ranges passed in.
|
static java.util.ArrayList<java.lang.Integer> |
getSelectedPageNumbersList(java.lang.String selectedPageNumbers)
Build and return a list of page numbers based on the user input.
|
static org.apache.commons.io.output.ByteArrayOutputStream |
getSelectedPagesFromPdf(java.io.InputStream is,
java.util.ArrayList<java.lang.Integer> selectedPages)
Create a new pdf based off of the selected pages of the passed in pdf
|
static java.lang.String |
getTextByArea(java.lang.String ticket,
java.lang.String objectId,
int pageNumber,
float[][] selectionAreas)
A method that will modify the pdf, first by rotating pages, and second by reordering them
|
byte[] |
manipulatePDF(java.lang.String ticket,
byte[] ba,
EnhancedCompleteObject eco,
java.util.Map<java.lang.String,java.lang.Object> params)
Hotspot method that allows a user to overwrite and manipulate the PDF as needed.
|
java.io.InputStream |
manipulatePDF(java.lang.String ticket,
java.io.InputStream is,
EnhancedCompleteObject eco,
java.util.Map<java.lang.String,java.lang.Object> params)
Hotspot method that allows a user to overwrite and manipulate the PDF as needed.
|
static java.lang.String |
modifyPdf(java.lang.String ticket,
java.lang.String objectId,
java.util.ArrayList<java.lang.Integer> pageOrder,
java.util.ArrayList<java.lang.Integer> pageRotations,
java.lang.Boolean newVersion,
java.lang.Boolean majorVersion,
java.lang.String documentVersion,
java.lang.Long lastModified)
A method that will modify the pdf, first by rotating pages, and second by reordering them
|
static org.apache.commons.io.output.ByteArrayOutputStream |
removePDFPages(com.itextpdf.text.pdf.PdfReader pdfFileReader,
org.apache.commons.io.output.ByteArrayOutputStream result,
int startPage,
int endPage)
Remove pages from pdf within the start and endPages
|
static void |
reorderPages(com.itextpdf.text.pdf.PdfReader reader,
java.util.ArrayList<java.lang.Integer> pageOrder)
Method to reorder pages in a pdf
|
static boolean |
reorderPdfPages(java.lang.String ticket,
java.lang.String objectId,
java.util.ArrayList<java.lang.Integer> pages,
java.lang.Boolean newVersion,
java.lang.Boolean majorVersion,
java.lang.Long lastModified)
A method that will reorder the pages in a pdf.
|
static void |
rotatePdfPages(com.itextpdf.text.pdf.PdfReader reader,
java.util.ArrayList<java.lang.Integer> pageRotations)
A method that will rotate some, or all, of the pages of a given pdf
|
static boolean |
rotatePdfPages(java.lang.String ticket,
java.lang.String objectId,
java.util.ArrayList<java.lang.Integer> pageRotations,
java.lang.Boolean newVersion,
java.lang.Boolean majorVersion,
long lastModified)
A method that will rotate some, or all of the pages of an object with PDF
content.
|
static boolean |
writeOutput(com.itextpdf.text.pdf.PdfReader reader,
java.lang.String ticket,
java.lang.String objectId,
boolean newVersion,
boolean majorVersion)
Takes in a PdfReader, and writes the output to the a document in the repository
|
protected static final java.lang.String RANGE_DELIMITER
public static void concatPDFs(java.util.List<com.itextpdf.text.pdf.PdfReader> pdfFileReaders, java.io.OutputStream baos, java.util.Map<java.lang.String,java.lang.String> headers)
pdfFileReaders
- - The pdfreaders containing pdf files to combine.baos
- - The outputStream of the new PDFheaders
- - a map of optional headers to addpublic static org.apache.commons.io.output.ByteArrayOutputStream removePDFPages(com.itextpdf.text.pdf.PdfReader pdfFileReader, org.apache.commons.io.output.ByteArrayOutputStream result, int startPage, int endPage) throws java.lang.Exception
pdfFileReader
- - The pdfReader with pdf file to remove pages from.result
- - The outputStream of the new PDFstartPage
- - The page to start removing pages.endPage
- - The page to end removing pagesjava.lang.Exception
public java.io.InputStream manipulatePDF(java.lang.String ticket, java.io.InputStream is, EnhancedCompleteObject eco, java.util.Map<java.lang.String,java.lang.Object> params)
ticket
- is
- eco
- params
- public byte[] manipulatePDF(java.lang.String ticket, byte[] ba, EnhancedCompleteObject eco, java.util.Map<java.lang.String,java.lang.Object> params) throws java.io.IOException
manipulatePDF(String, InputStream, EnhancedCompleteObject, Map)
and returns the byte[] unchanged.
This method should not normally be overwritten by client impls,
manipulatePDF(String, InputStream, EnhancedCompleteObject, Map)
should be the method to overwrite.ticket
- ba
- eco
- params
- java.io.IOException
public static org.apache.commons.io.output.ByteArrayOutputStream getPDFSection(java.io.InputStream is, org.apache.commons.io.output.ByteArrayOutputStream baos, java.lang.String pageRangeString)
is
- InputStream of the base pdf to get pages frombaos
- Output stream to write pages topageRangeString
- Range of pages to readpublic static org.apache.commons.io.output.ByteArrayOutputStream appendPDFSigPage(com.itextpdf.text.pdf.PdfReader content, com.itextpdf.text.pdf.PdfReader sigPage, int legacyNumOfSigPages)
content
- - The pdfreader containing the pdf file of the document.sigPage
- - The pdfreader containing the pdf file of the signature pagelegacyNumOfSigPages
- - number of signature pages that already exist grabbed from the docInfo (legacy). Pass
in 0 if this is not legacy or the doc has no legacy sig page.public static int getPageCount(java.io.InputStream is)
is
- pdf input streampublic static org.apache.commons.io.output.ByteArrayOutputStream getSelectedPagesFromPdf(java.io.InputStream is, java.util.ArrayList<java.lang.Integer> selectedPages)
is
- - Input stream of the pdfselectedPages
- - list of page numbers to get from the pdfpublic static java.util.ArrayList<java.lang.Integer> getSelectedPageNumbersList(java.lang.String selectedPageNumbers)
selectedPageNumbers
- - user input for selected pagespublic static void addPdfToOutput(com.itextpdf.text.pdf.PdfReader pdfReader, com.itextpdf.text.pdf.PdfCopy writer)
pdfReader
- writer
- public static org.apache.commons.io.output.ByteArrayOutputStream generateTimelinePdf(float duration)
duration
- - The total amount of time to generate a PDF forpublic static com.itextpdf.text.pdf.PdfReader getPdfReader(java.lang.String ticket, java.lang.String objectId, long lastModified)
ticket
- A valid OC ticket.objectId
- The id of the repo object we want a PDFReader for.lastModified
- The last modified date of the content we're fetching. Used for caching purposes.public static boolean writeOutput(com.itextpdf.text.pdf.PdfReader reader, java.lang.String ticket, java.lang.String objectId, boolean newVersion, boolean majorVersion)
reader
- - PdfReader a PdfReader for the document to be modifiedticket
- - String a valid OC ticketobjectId
- - String the id of the object to be modifiednewVersion
- - boolean when true, the object will be updated to a new, minor versionmajorVersion
- - boolean when true, the object will be updated to a major versionpublic static boolean rotatePdfPages(java.lang.String ticket, java.lang.String objectId, java.util.ArrayList<java.lang.Integer> pageRotations, java.lang.Boolean newVersion, java.lang.Boolean majorVersion, long lastModified)
ticket
- - A valid OC ticket.objectId
- - The object id of the object whose pages we want to rotate. Must have PDF content.pageRotations
- - An array of integers, one per page of the PDF, specifying how many degrees clockwise to rotate it.newVersion
- -true if the a new version of the document will be created when the document is modified. if false, the document in the repository will remain the same version when modifiedmajorVersion
- - true if the a major version of the document will be created when the document is modified. if false, the document in the repository will default to a minor version when modifiedcom.itextpdf.text.DocumentException
public static void rotatePdfPages(com.itextpdf.text.pdf.PdfReader reader, java.util.ArrayList<java.lang.Integer> pageRotations)
reader
- - a pdfreader that will be used to rotate the pagepageRotations
- - An array of integers, one per page of the PDF, specifying how many degrees clockwise to rotate it.public static boolean reorderPdfPages(java.lang.String ticket, java.lang.String objectId, java.util.ArrayList<java.lang.Integer> pages, java.lang.Boolean newVersion, java.lang.Boolean majorVersion, java.lang.Long lastModified)
ticket
- - A valid OC ticket.objectId
- - The object id of the object whose pages we want to rotate. Must have PDF content.pages
- newVersion
- -true if the a new version of the document will be created when the document is modified. if false, the document in the repository will remain the same version when modifiedmajorVersion
- - true if the a major version of the document will be created when the document is modified. if false, the document in the repository will default to a minor version when modifiedlastModified
- public static void reorderPages(com.itextpdf.text.pdf.PdfReader reader, java.util.ArrayList<java.lang.Integer> pageOrder)
reader
- - A PdfReader that will change the order of our pagespageOrder
- - An arraylist containing the new pdf orderpublic static java.lang.String modifyPdf(java.lang.String ticket, java.lang.String objectId, java.util.ArrayList<java.lang.Integer> pageOrder, java.util.ArrayList<java.lang.Integer> pageRotations, java.lang.Boolean newVersion, java.lang.Boolean majorVersion, java.lang.String documentVersion, java.lang.Long lastModified)
ticket
- - A valid OC ticketobjectId
- - The object id for the object we will be modifyingpageOrder
- - An arraylist of all the pages of the document in their new orderpageRotations
- - An arraylist with a value for each page that indicates how much that page will be rotatednewVersion
- - true if the a new version of the document will be created when the document is modified. if false, the document in the repository will remain the same version when modifiedmajorVersion
- - true if the a major version of the document will be created when the document is modified. if false, the document in the repository will default to a minor version when modifiedpublic static java.lang.String getTextByArea(java.lang.String ticket, java.lang.String objectId, int pageNumber, float[][] selectionAreas)
ticket
- - A valid OC ticketobjectId
- - The object id for the object we will be modifyingpageNumber
- - The page number that the text we are looking to get is onselectionAreas
- - A multidimensional array that contains sets of rectanglespublic static void addAutoPrint(java.io.InputStream pdfStream, java.io.OutputStream outputStream)
pdfStream
- - The byte stream containing the PDF Data.outputStream
- - The byte stream that the new PDF will be written to.public static org.apache.pdfbox.pdmodel.PDDocument getPDDcoument(java.lang.String ticket, java.lang.String objectId, long lastModified)
ticket
- A valid OC ticket.objectId
- The id of the repo object we want a PDDocument for.lastModified
- The last modified date of the content we're fetching. Used for caching purposes.public static com.aspose.pdf.Document getAsposeDocument(java.lang.String ticket, java.lang.String objectId)
ticket
- A valid OC ticket.objectId
- The id of the repo object we want an Aspose Document for.public static boolean canBeRead(java.lang.String ticket, java.lang.String objectId) throws OCObjectLockedException, OCContentFormatException, OCRuntimeException
ticket,
- a valid OC ticketobjectId,
- the id of the pdf we want to readOCObjectLockedException,
- if the pdf is password protectedOCContentFormatException,
- if the pdf is corruptOCRuntimeException,
- if there were other errors when trying to read the pdfOCObjectLockedException
OCContentFormatException
OCRuntimeException
public static java.io.InputStream encryptPdf(java.io.InputStream originalPdf)
originalPdf
- - the stream containing the pdf to be considered for encryptionpublic static java.io.InputStream encryptPdf(java.io.InputStream originalPdf, java.lang.String password, int permissions, int algorithm)
originalPdf
- - the InputStream of the pdf to be encryptedpassword
- - password used to lock/unlock the documentpermissions
- - document permissions for user without a passwordalgorithm
- - algorithm to be used for encryptionpublic static java.io.ByteArrayOutputStream encryptPdf(java.io.ByteArrayOutputStream os)
os
- - the stream containing the pdf to be considered for encryptionpublic static java.io.ByteArrayOutputStream encryptPdf(java.io.ByteArrayOutputStream os, java.lang.String password, int permissions, int algorithm)
os
- - a ByteArrayOutputStream containing the pdf contentpassword
- - password used to unlock the documentpermissions
- - document permissions for user without a passwordalgorithm
- - algorithm to be used for encryptionpublic static void encryptPdf(java.io.InputStream originalPdf, java.io.OutputStream resp)
originalPdf
- - byte array stream containing pdf dataresp
- - the stream where the encrypted data will be writtenpublic static byte[] flateFilterEncode(byte[] fileContent)
fileContent
- Byte[] that needs to be encoded.public static byte[] flateFilterDecode(byte[] decodedAttachment)
decodedAttachment
- Byte[] that is decoded.