1 Reader

Class Ax.pdf.Reader


Classed used for retrieving elements from PDF documents and doing some operations on PDF pages (split, rotate, remove). Wrapper for iText PDF reader functions. TODO: replace by https://github.com/LibrePDF/OpenPDF compile group: 'com.github.librepdf', name: 'openpdf', version: '1.2.10'

Constructor Summary

Method
Description
JSPDFReader(Object object)
Creates a new PDF reader from a source file.
JSPDFReader(Object object, Ax.text.String password)
Creates a new PDF reader instance from a source protected file

Method Summary

Modifier and Type
Method
Description
byte[] 
Adds a watermark to the PDF document with the specified configuration
byte[] 
Returns the PDF file as a byte array.
Ax.text.String 
getBitmapFromPage(int page)
Extracts the bit map from a PDF page.
Ax.text.String 
getBitmapFromPage(int page,boolean debug)
Extracts the bitmap from a PDF page.
Extracts the text from a PDF page (starts at 1) and returns the computed dimensions.
getDimensionsFromPage(int page,boolean debug)
Extracts the text from a PDF page (starts at 1) and returns the computed dimensions.
Returns the array of images from the PDF document.
int 
Gets the number of images in the PDF document.
int 
Gets the number of pages in the PDF document (starts at 1).
float 
getPageHeight(int page)
float 
getPageWidth(int page)
byte[] 
getPreviewFromPage(int pageNum)
Returns a preview of the specified page.
Extracts the text from the PDF document.
getTextFromDocument(boolean debug)
Extracts the text from the PDF document.
Ax.text.String 
getTextFromPage(int page)
Extracts the text from a PDF page (starts at 1).
Ax.text.String 
getTextFromPage(int page,boolean debug)
Extracts the text from a PDF page (starts at 1).
Ax.pdf.Reader 
insertPage(int position)
Insert a blank page at given position.
boolean 
Returns true if the PDF is only composed by images, without test layers.
Ax.pdf.Reader 
join(Ax.pdf.Reader other)
Joins two pdfs, the one this function is called on and the passed as parameter.
Ax.pdf.Reader 
remove(int[] pagesToRemove)
Removes the specified pages from the PDF.
Ax.pdf.Reader 
rotate(int page, double angle)
Rotates the page to the specified angle
byte[] 
Adds a watermark to the PDF document with the specified configuration
Ax.pdf.Reader 
slice(int startPage, int endPage)
Returns a fragment of the PDF.
List 
split(int size)
Splits the PDF into a multiple fragments of given size.
toBlob()
Returns the PDF as a BLOB file

Constructor Detail

Ax.pdf.Reader.JSPDFReader

Ax.pdf.Reader.JSPDFReader(
	object object
						)
Info:
Creates a new PDF reader from a source file.
Parameters:
object - any object convertible to an InputStream: byte[], Blob, File URl, CharSequence, Node, JSSOAPResponse

Ax.pdf.Reader.JSPDFReader

Ax.pdf.Reader.JSPDFReader(
	object object,
	string password
						)
Info:
Creates a new PDF reader instance from a source protected file
Parameters:
object - any object convertible to an InputStream: byte[], Blob, File URl, CharSequence, Node, JSSOAPResponse
password - the password to unlock the PDF file

Method Detail

Ax.pdf.Reader.addWatermark

byte[] Ax.pdf.Reader.addWatermark(
	object configurator
)
Info:
Adds a watermark to the PDF document with the specified configuration
Parameters:
configurator - watermark configuration options
Returns:
byte[]

Ax.pdf.Reader.asBytes

byte[] Ax.pdf.Reader.asBytes()
Info:
Returns the PDF file as a byte array.
Returns:
byte[]

Ax.pdf.Reader.getBitmapFromPage

string Ax.pdf.Reader.getBitmapFromPage(
	smallint page
)
Info:
Extracts the bit map from a PDF page.
Parameters:
page - the mnumber of the page to extract
Returns:
string

Ax.pdf.Reader.getBitmapFromPage

string Ax.pdf.Reader.getBitmapFromPage(
	smallint page,
	boolean debug
)
Info:
Extracts the bitmap from a PDF page. The bitmap is a JSON style array with the coordinates of the text chunks.
Parameters:
page - the number of the page to get the bitmap from
debug - whether debug mode is enabled
Returns:
string

Example
Copy
[
		[57,722,12.239525,10,0," Simple PDF File 2 ",233,19],
		[69,689,4.4004154,12,3," ...continued from page 1. Yet more text. And more text. And more text. ",317,7],
		[69,677,4.5735703,12,4," And more text. And more text. And more text. And more text. And more ",320,7],
		[69,665,4.2432384,12,5," text. Oh, how boring typing this stuff. But not as boring as watching ",301,7],
		[69,653,4.4156933,12,6," paint dry. And more text. And more text. And more text. And more text. ",318,7],
		[69,641,4.137618,12,8," Boring.  More, a little more text. The end, and just as well. ",261,7]
	]

Ax.pdf.Reader.getDimensionsFromPage

object Ax.pdf.Reader.getDimensionsFromPage(
	smallint page
)
Info:
Extracts the text from a PDF page (starts at 1) and returns the computed dimensions.
Parameters:
page - the number of the page to extract
Returns:
object

Ax.pdf.Reader.getDimensionsFromPage

object Ax.pdf.Reader.getDimensionsFromPage(
	smallint page,
	boolean debug
)
Info:
Extracts the text from a PDF page (starts at 1) and returns the computed dimensions.
Parameters:
page - the number of the page to extract
debug - 
Returns:
object

Ax.pdf.Reader.getImages

array Ax.pdf.Reader.getImages()
Info:
Returns the array of images from the PDF document.
Returns:
array

Ax.pdf.Reader.getNumberOfImages

smallint Ax.pdf.Reader.getNumberOfImages()
Info:
Gets the number of images in the PDF document.
Returns:
smallint

Ax.pdf.Reader.getNumberOfPages

smallint Ax.pdf.Reader.getNumberOfPages()
Info:
Gets the number of pages in the PDF document (starts at 1).
Returns:
smallint

Ax.pdf.Reader.getPageHeight

object Ax.pdf.Reader.getPageHeight(
	smallint page
)
Parameters:
page - 
Returns:
object

Ax.pdf.Reader.getPageWidth

object Ax.pdf.Reader.getPageWidth(
	smallint page
)
Parameters:
page - 
Returns:
object

Ax.pdf.Reader.getPreviewFromPage

byte[] Ax.pdf.Reader.getPreviewFromPage(
	smallint pageNum
)
Info:
Returns a preview of the specified page. iText it's a PDF generator, it can not do generate a PDF preview. So we use Apache PDFBox
Parameters:
pageNum - the page number to render as image 1 to N
Returns:
byte[]

Ax.pdf.Reader.getTextFromDocument

array Ax.pdf.Reader.getTextFromDocument()
Info:
Extracts the text from the PDF document.
Returns:
array

Ax.pdf.Reader.getTextFromDocument

array Ax.pdf.Reader.getTextFromDocument(
	boolean debug
)
Info:
Extracts the text from the PDF document.
Parameters:
debug - 
Returns:
array

Ax.pdf.Reader.getTextFromPage

string Ax.pdf.Reader.getTextFromPage(
	smallint page
)
Info:
Extracts the text from a PDF page (starts at 1). Loop is:
Parameters:
page - the number of the page to extract
Returns:
string

Example
Copy
for (var page = 1; page <= pdf.getNumberOfPages(); page++) {
		console.log("===== PAGE " + page);
		console.log(pdf.getTextFromPage(page));
 }

Ax.pdf.Reader.getTextFromPage

string Ax.pdf.Reader.getTextFromPage(
	smallint page,
	boolean debug
)
Info:
Extracts the text from a PDF page (starts at 1).
Parameters:
page - the number of the page to extract
debug - 
Returns:
string

Ax.pdf.Reader.insertPage

object Ax.pdf.Reader.insertPage(
	smallint position
)
Info:
Insert a blank page at given position.
Parameters:
position - the page number position where the new page will be inserted
Returns:
object

Ax.pdf.Reader.isImageOnly

boolean Ax.pdf.Reader.isImageOnly()
Info:
Returns true if the PDF is only composed by images, without test layers. Useful to check if PDF is a scanned document.
Returns:
boolean

Ax.pdf.Reader.join

object Ax.pdf.Reader.join(
	object other
)
Info:
Joins two pdfs, the one this function is called on and the passed as parameter.
Parameters:
other - the other PDF reader to join
Returns:
object

Ax.pdf.Reader.remove

object Ax.pdf.Reader.remove(
	object pagesToRemove
)
Info:
Removes the specified pages from the PDF.
Parameters:
pagesToRemove - the pages to remove
Returns:
object

Ax.pdf.Reader.rotate

object Ax.pdf.Reader.rotate(
	smallint page,
	double angle
)
Info:
Rotates the page to the specified angle
Parameters:
page - the number of the page to rotate
angle - the rotation angle
Returns:
object

Ax.pdf.Reader.setWatermark

byte[] Ax.pdf.Reader.setWatermark(
	object configurator
)
Info:
Adds a watermark to the PDF document with the specified configuration
Parameters:
configurator - watermark configuration options
Returns:
byte[]

Ax.pdf.Reader.slice

object Ax.pdf.Reader.slice(
	smallint startPage,
	smallint endPage
)
Info:
Returns a fragment of the PDF.
Parameters:
startPage - the first page of the fragment
endPage - the last page of the fragment (included)
Returns:
object

Ax.pdf.Reader.split

array Ax.pdf.Reader.split(
	smallint size
)
Info:
Splits the PDF into a multiple fragments of given size.
Parameters:
size - the size in pages of each fragment
Returns:
array

Ax.pdf.Reader.toBlob

object Ax.pdf.Reader.toBlob()
Info:
Returns the PDF as a BLOB file
Returns:
object

2 Writer

Class Ax.pdf.Writer


Wrapper for iText PDF writer functions. TODO:

Constructor Summary

Method
Description
Creates a new JSPDFWriter instance.

Method Summary

Modifier and Type
Method
Description
void 
close()
Closes the document.
toBlob()
Returns the document as a BLOB object.

Constructor Detail

Ax.pdf.Writer.JSPDFWriter

Ax.pdf.Writer.JSPDFWriter()
Info:
Creates a new JSPDFWriter instance.

Method Detail

Ax.pdf.Writer.close

null Ax.pdf.Writer.close()
Info:
Closes the document.
Returns:
null

Ax.pdf.Writer.toBlob

object Ax.pdf.Writer.toBlob()
Info:
Returns the document as a BLOB object.
Returns:
object

3 Signer

Class Ax.pdf.Signer


This class lets you work with signs, certificates and other security-related issues in PDF documents. Wrapper for iText PDF reader functions TODO: replace by https://github.com/LibrePDF/OpenPDF compile group: 'com.github.librepdf', name: 'openpdf', version: '1.2.10'

Constructor Summary

Method
Description
JSPDFSigner(Object object)
Creates a new JSPDFSigner nstance from a source document.

Method Summary

Modifier and Type
Method
Description
byte[] 
addLtvNoTS(com.itextpdf.text.pdf.security.OcspClient ocsp, com.itextpdf.text.pdf.security.CrlClient crl)
https://stackoverflow.
boolean 
Checks 2 things: 1.
boolean 
checkRevocation(com.itextpdf.text.pdf.security.PdfPKCS7 pkcs7, X509Certificate signCert, X509Certificate issuerCert, Date date)
Checks whether the signature should be revoked, as certificates may no longer be valid.
Gets the certificate chain from he signature.
Date 
Gets the date of the signature.
byte[] 
sign(KeyStore ks,Ax.text.String alias,Ax.text.String password,Consumer<PDFSignOptions> configurator)
Signs the PDF document.
verify()
Verifies the signature to ensure it is safe.

Constructor Detail

Ax.pdf.Signer.JSPDFSigner

Ax.pdf.Signer.JSPDFSigner(
	object object
						)
Info:
Creates a new JSPDFSigner nstance from a source document.
Parameters:
object - the object containing the PDF document, can be of any type convertible to input stream: file, byte[], blob...

Method Detail

Ax.pdf.Signer.addLtvNoTS

byte[] Ax.pdf.Signer.addLtvNoTS(
	object ocsp,
	object crl
)
Info:
https://stackoverflow.com/questions/27892960/how-to-enable-ltv-for-a-timestamp-signature/27906587#27906587 This code identifies the most recently filled signature field of the PDF and checks whether it is a document time stamp or an usual signature. If it is a document time stamp, the code adds validation information only for this document timestamp. Otherwise the code adds validation information for all signatures. (The assumed work flow behind this is that the document is signed (for certification and/or approval) a number of times first, and then the document enters LTV cycles adding validation information and document time stamps but no usual signatures anymore. Your work flow may vary and, therefore, your program logic, too.) Only after all this is done, a new document time stamp is added. For this finally added time stamp no validation information are explicitly added to the PDF (if document time stamps from the same TSA have been applied in short succession, validation information included for a prior time stamp may be applicable). And this is why Adobe Reader/Acrobat usually does not consider this document time stamp LTV enabled.
Parameters:
ocsp - Interface for the OCSP Client
crl - Interface that needs to be implemented if you want to embed Certificate Revocation Lists into your PDF.
Returns:
byte[]

Ax.pdf.Signer.checkCertificateValidity

boolean Ax.pdf.Signer.checkCertificateValidity(
	object cert,
	date signDate
)
Info:
Checks 2 things: 1. Whether the certificate was valid on the signDate. 2. Whether the certificate is still valid. TODO: move to crypto ??? TODO: move to crypto ??? TODO: move to crypto ???
Parameters:
cert - the certificate to check
signDate - the sign date
Returns:
boolean

Ax.pdf.Signer.checkRevocation

boolean Ax.pdf.Signer.checkRevocation(
	object pkcs7,
	object signCert,
	object issuerCert,
	date date
)
Info:
Checks whether the signature should be revoked, as certificates may no longer be valid.
Parameters:
pkcs7 - the signature algorithm
signCert - the signing certificate to check
issuerCert - the issuer certificate
date - the signature date
Returns:
boolean

Ax.pdf.Signer.getCertificateChain

object Ax.pdf.Signer.getCertificateChain()
Info:
Gets the certificate chain from he signature.
Returns:
object

Ax.pdf.Signer.getSignDate

date Ax.pdf.Signer.getSignDate()
Info:
Gets the date of the signature.
Returns:
date

Ax.pdf.Signer.sign

byte[] Ax.pdf.Signer.sign(
	object ks,
	string alias,
	string password,
	object configurator
)
Info:
Signs the PDF document.
Parameters:
ks - the keystore containing the necessary key
alias - the key alias in the keystore
password - the password for the key in the keystore
configurator - the pdf signature configuration function
Returns:
byte[]

Ax.pdf.Signer.verify

object Ax.pdf.Signer.verify()
Info:
Verifies the signature to ensure it is safe. Retrieves information about the signature.
Returns:
object

4 Form

Class Ax.pdf.Form


This classs is used to fill fill or update fields in a PDF. Specifically, gives access to AcroFields in a PDF. Fields can be text, lists, checkbox, buttons, signatures, etc. https://daedtech.com/programatically-filling-out-pdfs-in-java/ There are two posibilities: 1) You have a dynamic XFA form (from Livecycle Designer). You'll have to use the XfaForm object from AcroFields to inspect the fields. 2) In rare forms, fields are added to the pages, but not to the document-level field array that AcroFields checks. It would appear that this is "syntactically valid", just wildly unhelpful... "rude" even. iText doesn't currently go looking for missing fields on a page-by-page basis, though it could be modified to do so.

Constructor Summary

Method
Description
JSPDFForm(Object object)
Creates a new JSPDFForm instance from a source PF object
JSPDFForm(com.itextpdf.text.pdf.PdfReader doc, ByteArrayOutputStream out)
Creates a new JSPDFForm from a source pdf reader and with a ByteArrayOutputStream.

Method Summary

Modifier and Type
Method
Description
int 
getFieldType(Ax.text.String fieldName)
Gets the type of the field.
Ax.text.String 
getFieldValue(Ax.text.String fieldName)
Gets the value of the specified field.
Returns the fields in the PDF.
void 
setFieldProperty(Ax.text.String fieldName,Ax.text.String key,Object value)
Sets the value of the specified property of the given field.
void 
setFieldValue(Ax.text.String fieldName, Ax.text.String value)
Sets the value of a specified field.
toBlob()
Converts the PDF form to a BLOB object.
Ax.pdf.Reader 
toPDF()
Converts the PDF form to a PDFReader.

Constructor Detail

Ax.pdf.Form.JSPDFForm

Ax.pdf.Form.JSPDFForm(
	object object
						)
Info:
Creates a new JSPDFForm instance from a source PF object
Parameters:
object - the source pdf(byte[], File, Blob, URL...)

Ax.pdf.Form.JSPDFForm

Ax.pdf.Form.JSPDFForm(
	object doc,
	object out
						)
Info:
Creates a new JSPDFForm from a source pdf reader and with a ByteArrayOutputStream.
Parameters:
doc - the souce pdf reader
out - the output byte stream

Method Detail

Ax.pdf.Form.getFieldType

smallint Ax.pdf.Form.getFieldType(
	string fieldName
)
Info:
Gets the type of the field.
Parameters:
fieldName - the field name
Returns:
smallint

Ax.pdf.Form.getFieldValue

string Ax.pdf.Form.getFieldValue(
	string fieldName
)
Info:
Gets the value of the specified field.
Parameters:
fieldName - the field name
Returns:
string

Ax.pdf.Form.getFields

string[] Ax.pdf.Form.getFields()
Info:
Returns the fields in the PDF.
Returns:
string[]

Ax.pdf.Form.setFieldProperty

null Ax.pdf.Form.setFieldProperty(
	string fieldName,
	string key,
	object value
)
Info:
Sets the value of the specified property of the given field.
Parameters:
fieldName - the name of the field with the property to set
key - the name of the property to set
value - the value to set
Returns:
null

Ax.pdf.Form.setFieldValue

null Ax.pdf.Form.setFieldValue(
	string fieldName,
	string value
)
Info:
Sets the value of a specified field.
Parameters:
fieldName - the field name
value - the value to set
Returns:
null

Ax.pdf.Form.toBlob

object Ax.pdf.Form.toBlob()
Info:
Converts the PDF form to a BLOB object.
Returns:
object

Ax.pdf.Form.toPDF

object Ax.pdf.Form.toPDF()
Info:
Converts the PDF form to a PDFReader.
Returns:
object