public final class PdfFileEditor extends Object implements IPdfFileEditor
Implements operations with PDF file: concatenation, splitting, extracting pages, making booklet, etc.
Modifier and Type | Class and Description |
---|---|
static class |
PdfFileEditor.ConcatenateCorruptedFileAction
Action performed when corrupted file was met in concatenation process.
|
static class |
PdfFileEditor.ConcatenationProgressHandler
Represents class with abstract method that usually supplied by calling side and handles
progress events that comes from concatenation.
|
static class |
PdfFileEditor.CorruptedItem
Class which provides information about corrupted files in time of concatenation.
|
static class |
PdfFileEditor.PageBreak
Data of page break position.
|
static class |
PdfFileEditor.ProgressEventHandlerInfo
This class represents information about concatenation progress that can be used in external
application.
|
static class |
PdfFileEditor.ProgressEventType
This enum describes possible progress event types that can occure during concatenation
|
IPdfFileEditor.ContentsResizeParameters, IPdfFileEditor.ContentsResizeValue
Modifier and Type | Field and Description |
---|---|
PdfFileEditor.ConcatenationProgressHandler |
customProgressConcatenationHandler
Representation of internal progress events processor that works during concatenation and
translates concatenation events of internal concatenation stages into external customer's
code.
|
boolean |
TryMergeAdjacentSameBackgroundImages
Sometimes PDFs contain background images (of pages or table cells) constructed from several
same tiling background images put one near other.
|
Constructor and Description |
---|
PdfFileEditor()
PdfFileEditor constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addMargins(InputStream source,
OutputStream destination,
int[] pages,
double leftMargin,
double rightMargin,
double topMargin,
double bottomMargin)
Resizes page contents and add specifed margins.
|
boolean |
addMargins(String source,
String destination,
int[] pages,
double leftMargin,
double rightMargin,
double topMargin,
double bottomMargin)
Resizes page contents and add specifed margins.
|
boolean |
addMarginsPct(InputStream source,
OutputStream destination,
int[] pages,
double leftMargin,
double rightMargin,
double topMargin,
double bottomMargin)
Resizes page contents and add specified margins.
|
boolean |
addMarginsPct(String source,
String destination,
int[] pages,
double leftMargin,
double rightMargin,
double topMargin,
double bottomMargin)
Resizes page contents and add specified margins.
|
void |
addPageBreak(IDocument src,
IDocument dest,
PdfFileEditor.PageBreak[] pageBreaks)
Adds page breaks into document pages.
|
void |
addPageBreak(InputStream src,
OutputStream dest,
PdfFileEditor.PageBreak[] pageBreaks) |
void |
addPageBreak(String src,
String dest,
PdfFileEditor.PageBreak[] pageBreaks)
Adds page breaks into document pages.
|
boolean |
append(InputStream inputStream,
InputStream[] portStreams,
int startPage,
int endPage,
OutputStream outputStream)
Appends pages, which are chosen from array of documents in portStreams.
|
boolean |
append(InputStream inputStream,
InputStream portStream,
int startPage,
int endPage,
OutputStream outputStream)
Appends pages,which are chosen from portStream within the range from startPage to endPage, in
portStream at the end of firstInputStream.
|
boolean |
append(String inputFile,
String[] portFiles,
int startPage,
int endPage,
String outputFile)
Appends pages, which are chosen from portFiles documents.
|
boolean |
append(String inputFile,
String portFile,
int startPage,
int endPage,
String outputFile)
Appends pages, which are chosen from portFile within the range from startPage to endPage, in
portFile at the end of firstInputFile.
|
boolean |
concatenate(IDocument[] src,
IDocument dest)
Concatenates documents.
|
boolean |
concatenate(InputStream[] inputStream,
OutputStream outputStream)
Concatenates files
PdfFileEditor fileEditor = new PdfFileEditor();
InputStream stream1 = new FileInputStream("file1.pdf");
InputStream stream2 = new FileInputStream("file2.pdf");
OutputStream outstream = new FileOutputStream("outfile.pdf");
fileEditor.concatenate(new Stream[] { stream1, stream2 } , outstream);
|
boolean |
concatenate(InputStream firstInputStream,
InputStream secInputStream,
InputStream blankPageStream,
OutputStream outputStream)
Merges two Pdf documents into a new Pdf document with pages in alternate ways and fill the
blank places with blank pages. e.g.: document1 has 5 pages: p1, p2, p3, p4, p5. document2 has
3 pages: p1', p2', p3'.
|
boolean |
concatenate(InputStream firstInputStream,
InputStream secInputStream,
OutputStream outputStream)
Concatenates two files.
|
boolean |
concatenate(String[] inputFiles,
String outputFile)
Concatenates files into one file.
|
boolean |
concatenate(String firstInputFile,
String secInputFile,
String outputFile)
Concatentates two files.
|
boolean |
concatenate(String firstInputFile,
String secInputFile,
String blankPageFile,
String outputFile)
Merges two Pdf documents into a new Pdf document with pages in alternate ways and fill the
blank places with blank pages. e.g.: document1 has 5 pages: p1, p2, p3, p4, p5. document2 has
3 pages: p1', p2', p3'.
|
boolean |
delete(InputStream inputStream,
int[] pageNumber,
OutputStream outputStream)
Deletes pages specified by number array from input file, saves as a new Pdf file.
|
boolean |
delete(String inputFile,
int[] pageNumber,
String outputFile)
Deletes pages specified by number array from input file, saves as a new Pdf file.
|
boolean |
extract(InputStream inputStream,
int[] pageNumber,
OutputStream outputStream)
Extracts pages specified by number array, saves as a new Pdf file.
|
boolean |
extract(InputStream inputStream,
int startPage,
int endPage,
OutputStream outputStream)
Extracts pages from input file,saves as a new Pdf file.
|
boolean |
extract(String inputFile,
int[] pageNumber,
String outputFile)
Extracts pages specified by number array, saves as a new PDF file.
|
boolean |
extract(String inputFile,
int startPage,
int endPage,
String outputFile)
Extracts pages from input file,saves as a new Pdf file.
|
boolean |
getAllowConcatenateExceptions()
If set to true, exceptions are thrown if error occured.
|
String |
getAttachmentName()
Gets name of attachment when result of operation is stored into HttpServletResponse objects
as attachment.
|
boolean |
getCloseConcatenatedStreams()
If set to true, streams are closed after operation.
|
int |
getConcatenationPacketSize()
Number of documents concatenated before new incremental update was made during concatenation
when UseDiskBuffer is set to true.
|
int |
getContentDisposition()
Gets how content will be stored when result of operation is stored into HttpServletResponse
object.
|
String |
getConversionLog()
Gets log of conversion process.
|
boolean |
getCopyLogicalStructure()
If true then logical structure of the file is copied when concatenation is performed.
|
boolean |
getCopyOutlines()
If true then outlines will be copied.
|
int |
getCorruptedFileAction()
This property defines behavior when concatenating process met corrupted file.
|
PdfFileEditor.CorruptedItem[] |
getCorruptedItems()
Array of encountered problems when concatenation was performed.
|
boolean |
getIncrementalUpdates()
If true, incremental updates are made during concatenation.
|
boolean |
getKeepActions()
If true actions will be copied from source documents.
|
boolean |
getKeepFieldsUnique()
If true then field names will be made unique when forms are concatenated.
|
Exception |
getLastException()
Gets last occured exception.
|
boolean |
getMergeDuplicateLayers()
Optional contents of concatentated documents with equal names will be merged into one layer
in resulstant document if this property is true.
|
boolean |
getMergeDuplicateOutlines()
If true, duplicate outlines are merged.
|
boolean |
getOptimizeSize()
Gets or sets optimization flag.
|
String |
getOwnerPassword()
Gets owner's password if the source input Pdf file is encrypted.
|
boolean |
getPreserveUserRights()
If true, user rights of first document are applied to concatenated document.
|
SaveOptions |
getSaveOptions()
Gets or sets save options when result is stored as HttpServletResponse.
|
String |
getUniqueSuffix()
Get format of the suffix which is added to field name to make it unique when forms are
concatenated.
|
boolean |
getUseDiskBuffer()
If this option used then destination document will be saved on disk periodically and further
concatenation will appllied to it as incremental updates.
|
boolean |
insert(InputStream inputStream,
int insertLocation,
InputStream portStream,
int[] pageNumber,
OutputStream outputStream)
Inserts pages from an other file into the input Pdf file.
|
boolean |
insert(InputStream inputStream,
int insertLocation,
InputStream portStream,
int startPage,
int endPage,
OutputStream outputStream)
Inserts pages from an other file into the input Pdf file.
|
boolean |
insert(String inputFile,
int insertLocation,
String portFile,
int[] pageNumber,
String outputFile)
Inserts pages from an other file into the input Pdf file.
|
boolean |
insert(String inputFile,
int insertLocation,
String portFile,
int startPage,
int endPage,
String outputFile)
Inserts pages from an other file into the Pdf file at a position.
|
boolean |
makeBooklet(InputStream inputStream,
OutputStream outputStream)
Makes booklet from the InputStream to outputStream.
|
boolean |
makeBooklet(InputStream inputStream,
OutputStream outputStream,
int[] leftPages,
int[] rightPages)
Makes customized booklet from the firstInputStream to outputStream.
|
boolean |
makeBooklet(InputStream inputStream,
OutputStream outputStream,
PageSize pageSize)
Makes booklet from the input stream and save result into output stream.
|
boolean |
makeBooklet(InputStream inputStream,
OutputStream outputStream,
PageSize pageSize,
int[] leftPages,
int[] rightPages)
Makes booklet from the firstInputStream to outputStream.
|
boolean |
makeBooklet(String inputFile,
String outputFile)
Makes booklet from the input file to output file.
|
boolean |
makeBooklet(String inputFile,
String outputFile,
int[] leftPages,
int[] rightPages)
Makes customized booklet from the firstInputFile to outputFile.
|
boolean |
makeBooklet(String inputFile,
String outputFile,
PageSize pageSize)
Makes booklet from the inputFile to outputFile.
|
boolean |
makeBooklet(String inputFile,
String outputFile,
PageSize pageSize,
int[] leftPages,
int[] rightPages)
Makes customized booklet from the firstInputFile to outputFile.
|
boolean |
makeNUp(InputStream[] inputStreams,
OutputStream outputStream,
boolean isSidewise)
Makes N-Up document from the multi input PDF streams to outputStream.
|
boolean |
makeNUp(InputStream firstInputStream,
InputStream secondInputStream,
OutputStream outputStream)
Makes N-Up document from the two input PDF streams to outputStream.
|
boolean |
makeNUp(InputStream inputStream,
OutputStream outputStream,
int x,
int y)
Makes N-Up document from the input stream and saves result into output stream.
|
boolean |
makeNUp(InputStream inputStream,
OutputStream outputStream,
int x,
int y,
PageSize pageSize)
Makes N-Up document from the first input stream to output stream.
|
boolean |
makeNUp(String[] inputFiles,
String outputFile,
boolean isSidewise)
Makes N-Up document from the multi input PDF files to outputFile.
|
boolean |
makeNUp(String inputFile,
String outputFile,
int x,
int y)
Makes N-Up document from the firstInputFile to outputFile.
|
boolean |
makeNUp(String inputFile,
String outputFile,
int x,
int y,
PageSize pageSize)
Makes N-Up document from the input file to outputFile.
|
boolean |
makeNUp(String firstInputFile,
String secondInputFile,
String outputFile)
Makes N-Up document from the two input PDF files to outputFile.
|
void |
resizeContents(Document source,
IPdfFileEditor.ContentsResizeParameters parameters)
Resizes pages of document.
|
void |
resizeContents(IDocument source,
int[] pages,
IPdfFileEditor.ContentsResizeParameters parameters)
Resizes pages of document.
|
boolean |
resizeContents(InputStream source,
OutputStream destination,
int[] pages,
double newWidth,
double newHeight)
Resizes contents of document pages.
|
boolean |
resizeContents(InputStream source,
OutputStream destination,
int[] pages,
IPdfFileEditor.ContentsResizeParameters parameters)
Resizes contents of pages of the document.
|
boolean |
resizeContents(String source,
String destination,
int[] pages,
double newWidth,
double newHeight)
Resizes contents of document pages.
|
boolean |
resizeContents(String source,
String destination,
int[] pages,
IPdfFileEditor.ContentsResizeParameters parameters)
Resizes contents of pages in document.
|
boolean |
resizeContentsPct(InputStream source,
OutputStream destination,
int[] pages,
double newWidth,
double newHeight)
Resizes contents of document pages.
|
boolean |
resizeContentsPct(String source,
String destination,
int[] pages,
double newWidth,
double newHeight)
Resizes contents of document pages.
|
void |
setAllowConcatenateExceptions(boolean value)
If set to true, exceptions are thrown if error occured.
|
void |
setAttachmentName(String value)
Sets name of attachment when result of operation is stored into HttpServletResponse objects
as attachment.
|
void |
setCloseConcatenatedStreams(boolean value)
If set to true, streams are closed after operation.
|
void |
setConcatenationPacketSize(int value)
Number of documents concatenated before new incremental update was made during concatenation
when UseDiskBuffer is set to true.
|
void |
setContentDisposition(int value)
Sets how content will be stored when result of operation is stored into HttpServletResponse
object.
|
void |
setConvertTo(int value)
Sets PDF file format.
|
void |
setCopyLogicalStructure(boolean value)
If true then logical structure of the file is copied when concatenation is performed.
|
void |
setCopyOutlines(boolean value)
If true then outlines will be copied.
|
void |
setCorruptedFileAction(int value)
This property defines behavior when concatenating process met corrupted file.
|
void |
setIncrementalUpdates(boolean value)
If true, incremental updates are made during concatenation.
|
void |
setKeepActions(boolean value)
If true actions will be copied from source documents.
|
void |
setKeepFieldsUnique(boolean value)
If true then field names will be made unique when forms are concatenated.
|
void |
setMergeDuplicateLayers(boolean value)
Optional contents of concatentated documents with equal names will be merged into one layer
in resulstant document if this property is true.
|
void |
setMergeDuplicateOutlines(boolean value)
If true, duplicate outlines are merged.
|
void |
setOptimizeSize(boolean value)
Gets or sets optimization flag.
|
void |
setOwnerPassword(String value)
Sets owner's password if the source input Pdf file is encrypted.
|
void |
setPreserveUserRights(boolean value)
If true, user rights of first document are applied to concatenated document.
|
void |
setSaveOptions(SaveOptions value)
Sets save options when result is stored as HttpServletResponse.
|
void |
setUniqueSuffix(String value)
Set format of the suffix which is added to field name to make it unique when forms are
concatenated.
|
void |
setUseDiskBuffer(boolean value)
If this option used then destination document will be saved on disk periodically and further
concatenation will appllied to it as incremental updates.
|
boolean |
splitFromFirst(InputStream inputStream,
int location,
OutputStream outputStream)
Splits from start to specified location,and saves the front part in output Stream.
|
boolean |
splitFromFirst(String inputFile,
int location,
String outputFile)
Splits Pdf file from first page to specified location,and saves the front part as a new file.
|
ByteArrayInputStream[] |
splitToBulks(InputStream inputStream,
int[][] numberOfPage)
Splits the Pdf file into several documents.The documents can be single-page or multi-pages.
|
ByteArrayInputStream[] |
splitToBulks(String inputFile,
int[][] numberOfPage)
Splits the Pdf file into several documents.The documents can be single-page or multi-pages.
|
boolean |
splitToEnd(InputStream inputStream,
int location,
OutputStream outputStream)
Splits from specified location, and saves the rear part as a new file Stream.
|
boolean |
splitToEnd(String inputFile,
int location,
String outputFile)
Splits from location, and saves the rear part as a new file.
|
ByteArrayInputStream[] |
splitToPages(InputStream inputStream)
Splits the Pdf file into single-page documents.
|
void |
splitToPages(InputStream inputStream,
String fileNameTemplate)
Split the Pdf file into single-page documents and saves it into specified path.
|
ByteArrayInputStream[] |
splitToPages(String inputFile)
Splits the PDF file into single-page documents.
|
void |
splitToPages(String inputFile,
String fileNameTemplate)
Split the Pdf file into single-page documents and saves it into specified path.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConversionLog, getIncrementalUpdates, getMergeDuplicateLayers, getMergeDuplicateOutlines, getPreserveUserRights, setIncrementalUpdates, setMergeDuplicateLayers, setMergeDuplicateOutlines, setPreserveUserRights, splitToPages, splitToPages
public boolean TryMergeAdjacentSameBackgroundImages
Sometimes PDFs contain background images (of pages or table cells) constructed from several same tiling background images put one near other. In such case renderers of target formats (f.e MsWord for DOCS format) sometimes generates visible boundaries beetween parts of background images, cause their techniques of image edge smoothing (anti-aliasing) is different from Acrobat Reader. If it looks like exported document contains such visible boundaries between parts of same background images, please try use this setting to get rid of that unwanted effect. ATTENTION! This optimization of quality usually essentially slows down conversion, so, please, use this option only when it's really necessary.
public PdfFileEditor.ConcatenationProgressHandler customProgressConcatenationHandler
Representation of internal progress events processor that works during concatenation and
translates concatenation events of internal concatenation stages into external customer's
code. This field uses different types of events.
Simple concatenation has 8 events :
1)AllPagesCopied
2)DocumentEmbeddedFiles
3)DocumentForms
4)DocumentOutlines
5)DocumentJavaScript
6)DocumentLogicalStructure
7)DocumentConcated.
8)TotalPercentage.
Parallel concatenation informs about every page concatenation and has 3 events:
1)PageConcatenated
2)BlankPage
3)TotalPercentage
ProgressEventType
public PdfFileEditor.CorruptedItem[] getCorruptedItems()
Array of encountered problems when concatenation was performed. For every corrupted document from passed to Concatenate() function new CorruptedItem entry is created. This property may be used only when CorruptedFileAction is ConcatenateIgnoringCorrupted.
//concatenate documents and show information about corrupted documents
PdfFileEditor pfe = new PdfFileEditor();
pfe.setCorruptedFileAction(PdfFileEditor.ConcatenateCorruptedFileAction.ConcatenateIgnoringCorrupted);
if (pfe.getCorruptedItems().length >0)
{
for(PdfFileEditor.CorruptedItem item : pfe.getCorruptedItems())
{
System.out.println(item.getIndex()+ " reason: " + item.getException());
}
}
public int getCorruptedFileAction()
This property defines behavior when concatenating process met corrupted file. Possible values are: StopWithError and ConcatenateIgnoringCorrupted.
getCorruptedFileAction
in interface IPdfFileEditor
PdfFileEditor.ConcatenateCorruptedFileAction
public void setCorruptedFileAction(int value)
This property defines behavior when concatenating process met corrupted file. Possible values are: StopWithError and ConcatenateIgnoringCorrupted.
setCorruptedFileAction
in interface IPdfFileEditor
value
- int valuePdfFileEditor.ConcatenateCorruptedFileAction
public String getOwnerPassword()
Gets owner's password if the source input Pdf file is encrypted. This property is not implemented yet.
getOwnerPassword
in interface IPdfFileEditor
public void setOwnerPassword(String value)
Sets owner's password if the source input Pdf file is encrypted. This property is not implemented yet.
setOwnerPassword
in interface IPdfFileEditor
value
- String valuepublic boolean getAllowConcatenateExceptions()
If set to true, exceptions are thrown if error occured. Else excetion are not thrown and methods return false if failed.
PdfFileEditor pfe = new PdfFileEditor(); pfe.setAllowConcatenatedException (true);
getAllowConcatenateExceptions
in interface IPdfFileEditor
public void setAllowConcatenateExceptions(boolean value)
If set to true, exceptions are thrown if error occured. Else excetion are not thrown and methods return false if failed.
setAllowConcatenateExceptions
in interface IPdfFileEditor
value
- boolean value
PdfFileEditor pfe = new PdfFileEditor(); pfe.setAllowConcatenatedException (true);
public void setConvertTo(int value)
Sets PDF file format. Result file will be saved in specified file format. If this property is not specified then file will be save in default PDF format without conversion.
setConvertTo
in interface IPdfFileEditor
value
- int valuePdfFormat
public boolean getCloseConcatenatedStreams()
getCloseConcatenatedStreams
in interface IPdfFileEditor
public void setCloseConcatenatedStreams(boolean value)
If set to true, streams are closed after operation.
setCloseConcatenatedStreams
in interface IPdfFileEditor
value
- boolean value
PdfFileEditor pfe = new PdfFileEditor(); pfe.setCloseConcatenatedStreams (true);
public String getUniqueSuffix()
Get format of the suffix which is added to field name to make it unique when forms are concatenated. This string must contain %NUM% substring which will be replaced with numbers. For example if UniqueSuffix = "ABC%NUM%" then for field "fieldName" names will be: fieldNameABC1, fieldNameABC2, fieldNameABC3 etc.
getUniqueSuffix
in interface IPdfFileEditor
public void setUniqueSuffix(String value)
Set format of the suffix which is added to field name to make it unique when forms are concatenated. This string must contain %NUM% substring which will be replaced with numbers. For example if UniqueSuffix = "ABC%NUM%" then for field "fieldName" names will be: fieldNameABC1, fieldNameABC2, fieldNameABC3 etc.
PdfFileEditor ed = new PdfFileEditor(); ed.setUniqueSuffix ( "_%NUM%");
setUniqueSuffix
in interface IPdfFileEditor
value
- String objectpublic boolean getKeepFieldsUnique()
If true then field names will be made unique when forms are concatenated. Suffixes will be added to field names, suffix template may be specified in UniqueSuffix property.
getKeepFieldsUnique
in interface IPdfFileEditor
public void setKeepFieldsUnique(boolean value)
If true then field names will be made unique when forms are concatenated. Suffixes will be added to field names, suffix template may be specified in UniqueSuffix property.
setKeepFieldsUnique
in interface IPdfFileEditor
value
- boolean valuepublic boolean concatenate(String firstInputFile, String secInputFile, String outputFile)
Concatentates two files.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.concatenate("file1.pdf", "file2.pdf", "outfile.pdf");
concatenate
in interface IPdfFileEditor
firstInputFile
- First file to concatenate.secInputFile
- Second file to concatenate.outputFile
- Output file.public boolean concatenate(InputStream firstInputStream, InputStream secInputStream, OutputStream outputStream)
Concatenates two files.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream stream1 = new FileInputStream("file1.pdf"); InputStream stream2 = new FileInputStream("file2.pdf"); OutputStream outstream = new FileOutputStream("outfile.pdf"); fileEditor.concatenate(stream1, stream2, outstream);
concatenate
in interface IPdfFileEditor
firstInputStream
- Stream of first file.secInputStream
- Stream of second file.outputStream
- Stream where result file will be stored.public boolean concatenate(IDocument[] src, IDocument dest)
Concatenates documents.
concatenate
in interface IPdfFileEditor
src
- Array of source documents.dest
- Destination document.public boolean concatenate(String[] inputFiles, String outputFile)
Concatenates files into one file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.concatenate(new String[] { "src1.pdf", "src2.pdf" }, "dest.pdf");
concatenate
in interface IPdfFileEditor
inputFiles
- Array of files to concatenate.outputFile
- Name of output file.public boolean concatenate(InputStream[] inputStream, OutputStream outputStream)
Concatenates files
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream stream1 = new FileInputStream("file1.pdf"); InputStream stream2 = new FileInputStream("file2.pdf"); OutputStream outstream = new FileOutputStream("outfile.pdf"); fileEditor.concatenate(new Stream[] { stream1, stream2 } , outstream);
concatenate
in interface IPdfFileEditor
inputStream
- Array of streams to be concatenated.outputStream
- Stream where result file will be stored.public boolean concatenate(String firstInputFile, String secInputFile, String blankPageFile, String outputFile)
Merges two Pdf documents into a new Pdf document with pages in alternate ways and fill the blank places with blank pages. e.g.: document1 has 5 pages: p1, p2, p3, p4, p5. document2 has 3 pages: p1', p2', p3'. Merging the two Pdf document will produce the result document with pages:p1, p1', p2, p2', p3, p3', p4, blankpage, p5, blankpage.
PdfFileEditor pfe = new PdfFileEditor(); pfe.concatenate("src1.pdf", "src2.pdf", "blank.pdf", "dest.pdf");
concatenate
in interface IPdfFileEditor
firstInputFile
- First file.secInputFile
- Second file.blankPageFile
- PDF file with blank page.outputFile
- Result file.public boolean concatenate(InputStream firstInputStream, InputStream secInputStream, InputStream blankPageStream, OutputStream outputStream)
Merges two Pdf documents into a new Pdf document with pages in alternate ways and fill the blank places with blank pages. e.g.: document1 has 5 pages: p1, p2, p3, p4, p5. document2 has 3 pages: p1', p2', p3'. Merging the two Pdf document will produce the result document with pages:p1, p1', p2, p2', p3, p3', p4, blankpage, p5, blankpage.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream stream1 = new FileInputStream("file1.pdf"); InputStream stream2 = new FileInputStream("file2.pdf"); InputStream blank = new FileInputStream("blank.pdf"); OutputStream outstream = new FileOutputStream("outfile.pdf"); fileEditor.concatenate(new Stream[] { stream1, stream2, blank } , outstream);
concatenate
in interface IPdfFileEditor
firstInputStream
- The first Pdf Stream.secInputStream
- The second Pdf Stream.blankPageStream
- The Pdf Stream with blank pageoutputStream
- Output Pdf Stream.public boolean append(InputStream inputStream, InputStream[] portStreams, int startPage, int endPage, OutputStream outputStream)
Appends pages, which are chosen from array of documents in portStreams. The result document includes firstInputFile and all portStreams documents pages in the range startPage to endPage.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream instream = new FileInputStream("input.pdf"); InputStream stream1 = new FileInputStream("file1.pdf"); InputStream stream2 = new FileInputStream("file2.pdf"); OtputStream outstream = new FileOutputStream("outfile.pdf"); fileEditor.append(instream, new InputStream[] { stream1, stream2}, 3, 5, outstream);
append
in interface IPdfFileEditor
inputStream
- Input Pdf stream.portStreams
- Documents to copy pages from.startPage
- Page starts in portStreams documents.endPage
- Page ends in portStreams documents .outputStream
- Output Pdf stream.public boolean append(String inputFile, String[] portFiles, int startPage, int endPage, String outputFile)
Appends pages, which are chosen from portFiles documents. The result document includes firstInputFile and all portFiles documents pages in the range startPage to endPage.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.append("input.pdf", new string[] { "file1.pdf", "file2.pdf"}, 3, 5, "outfile.pdf");
append
in interface IPdfFileEditor
inputFile
- Input Pdf file.portFiles
- Documents to copy pages from.startPage
- Page starts in portFiles documents.endPage
- Page ends in portFiles documents .outputFile
- Output Pdf document.public boolean append(String inputFile, String portFile, int startPage, int endPage, String outputFile)
Appends pages, which are chosen from portFile within the range from startPage to endPage, in portFile at the end of firstInputFile.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.append("input.pdf", "file1.pdf", 3, 5, "outfile.pdf");
append
in interface IPdfFileEditor
inputFile
- Input Pdf file.portFile
- Pages from Pdf file.startPage
- Page starts in portFile.endPage
- Page ends in portFile.outputFile
- Output Pdf document.public boolean append(InputStream inputStream, InputStream portStream, int startPage, int endPage, OutputStream outputStream)
Appends pages,which are chosen from portStream within the range from startPage to endPage, in portStream at the end of firstInputStream.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream instream = new FileInputStream("input.pdf"); InputStream stream1 = new FileInputStream("file1.pdf"); OutputStream outstream = new FileOutputStream("outfile.pdf"); fileEditor.append(instream, stream1, 3, 5, outstream);
append
in interface IPdfFileEditor
inputStream
- Input file Stream.portStream
- Pages from Pdf file Stream.startPage
- Page starts in portFile Stream.endPage
- Page ends in portFile Stream.outputStream
- Output Pdf file Stream.public boolean insert(String inputFile, int insertLocation, String portFile, int startPage, int endPage, String outputFile)
Inserts pages from an other file into the Pdf file at a position.
PdfFileEditor pfe = new PdfFileEditor(); pfe.insert("file1.pdf", 1, "file2.pdf", 2, 6, "out.pdf");
insert
in interface IPdfFileEditor
inputFile
- Input Pdf file.insertLocation
- Position in input file.portFile
- The porting Pdf file.startPage
- Start position in portFile.endPage
- End position in portFile.outputFile
- Output Pdf file.public boolean insert(InputStream inputStream, int insertLocation, InputStream portStream, int startPage, int endPage, OutputStream outputStream)
Inserts pages from an other file into the input Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); outstream sourceStream = new FileInputStream("file1.pdf"); outstream insertedStream = new FileInputStream("file2.pdf"); OutputStream outStream = new FileOutputStream("out.pdf"); pfe.insert(sourceStream, 1, insertedStream, 2, 6, outStream);
insert
in interface IPdfFileEditor
inputStream
- Input Stream of Pdf file.insertLocation
- Insert position in input file.portStream
- Stream of Pdf file for pages.startPage
- From which page to start.endPage
- To which page to end.outputStream
- Output Stream.public boolean insert(String inputFile, int insertLocation, String portFile, int[] pageNumber, String outputFile)
Inserts pages from an other file into the input Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); outstream sourceStream = new FileInputStream("file1.pdf"); outstream insertedStream = new FileInputStream("file2.pdf"); OutputStream outStream = new FileInputStream("out.pdf"); pfe.insert(sourceStream, 1, insertedStream, 2, 6, outStream);
insert
in interface IPdfFileEditor
inputFile
- Input Pdf file.insertLocation
- Insert position in input file.portFile
- Pages from the Pdf file.pageNumber
- The page number of the ported in portFile.outputFile
- Output Pdf file.public boolean insert(InputStream inputStream, int insertLocation, InputStream portStream, int[] pageNumber, OutputStream outputStream)
Inserts pages from an other file into the input Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); outstream sourceStream = new FileInputStream("file1.pdf"); outstream insertedStream = new FileInputStream("file2.pdf"); OutputStream outStream = new FileoutputStream("out.pdf"); pfe.Insert(sourceStream, 1, insertedStream, new int[] { 3, 4, 5}, outStream);
insert
in interface IPdfFileEditor
inputStream
- Input Stream of Pdf file.insertLocation
- Insert position in input file.portStream
- Stream of Pdf file for pages.pageNumber
- The page number of the ported in portFile.outputStream
- Output Stream.public boolean delete(String inputFile, int[] pageNumber, String outputFile)
Deletes pages specified by number array from input file, saves as a new Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.delete("input.pdf", new int[] { 2, 3 }, "out.pdf");
delete
in interface IPdfFileEditor
inputFile
- Input file path.pageNumber
- Index of page out of the input file.outputFile
- Output file path.public boolean delete(InputStream inputStream, int[] pageNumber, OutputStream outputStream)
Deletes pages specified by number array from input file, saves as a new Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); InputStream intputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileInputStream("output.pdf"); pfe.Delete(inputStream, new int[] { 2, 3 }, outputStream);
delete
in interface IPdfFileEditor
inputStream
- Input file Stream.pageNumber
- Index of page out of the input file.outputStream
- Output file stream.public boolean extract(String inputFile, int startPage, int endPage, String outputFile)
Extracts pages from input file,saves as a new Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.Extract("input.pdf", 3, 7, "output.pdf");
extract
in interface IPdfFileEditor
inputFile
- Input Pdf file path.startPage
- Start page number.endPage
- End page number.outputFile
- Output Pdf file path.public boolean extract(String inputFile, int[] pageNumber, String outputFile)
Extracts pages specified by number array, saves as a new PDF file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.extract("input.pdf", new int[] { 3, 5, 7 }, "output.pdf");
extract
in interface IPdfFileEditor
inputFile
- Input file path.pageNumber
- Index of page out of the input file.outputFile
- Output file path.public boolean extract(InputStream inputStream, int startPage, int endPage, OutputStream outputStream)
Extracts pages from input file,saves as a new Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); InputStream sourceStream = new FileInputStream("file1.pdf"); OutputStream outStream = new FileOutputStream("out.pdf"); pfe.extract(sourceStream, 1, 3, 6, outStream);
extract
in interface IPdfFileEditor
inputStream
- Input file Stream.startPage
- Start page number.endPage
- End page number.outputStream
- Output Pdf file Stream.public boolean extract(InputStream inputStream, int[] pageNumber, OutputStream outputStream)
Extracts pages specified by number array, saves as a new Pdf file.
PdfFileEditor pfe = new PdfFileEditor(); InputStream sourceStream = new FileInputStream("file1.pdf"); OutputStream outStream = new FileInputStream("out.pdf"); pfe.extract(sourceStream, new int[] { 3, 5, 8 }, outStream);
extract
in interface IPdfFileEditor
inputStream
- Input file Stream.pageNumber
- Index of page out of the input file.outputStream
- Output file stream.public boolean splitFromFirst(String inputFile, int location, String outputFile)
Splits Pdf file from first page to specified location,and saves the front part as a new file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.splitFromFirst("input.pdf", 5, "out.pdf");
splitFromFirst
in interface IPdfFileEditor
inputFile
- Source Pdf file.location
- The splitting point.outputFile
- Output Pdf file.public boolean splitFromFirst(InputStream inputStream, int location, OutputStream outputStream)
Splits from start to specified location,and saves the front part in output Stream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream sourceStream = new FileInputStream("file1.pdf"); OutputStream outStream = new FileOutputStream("out.pdf"); pfe.splitFromFirst(sourceStream, 5, outStream);
splitFromFirst
in interface IPdfFileEditor
inputStream
- Source Pdf file Stream.location
- The splitting point.outputStream
- Output file Stream.public boolean splitToEnd(String inputFile, int location, String outputFile)
Splits from location, and saves the rear part as a new file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.splitToEnd("input.pdf", 5, "out.pdf");
splitToEnd
in interface IPdfFileEditor
inputFile
- Source Pdf file.location
- The splitting position.outputFile
- Output Pdf file path.public boolean splitToEnd(InputStream inputStream, int location, OutputStream outputStream)
Splits from specified location, and saves the rear part as a new file Stream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream sourceStream = new FileInputStream("file1.pdf"); OutputStream outStream = new FileInputStream("out.pdf"); pfe.splitToEnd(sourceStream, 5, outStream);
splitToEnd
in interface IPdfFileEditor
inputStream
- Source Pdf file Stream.location
- The splitting position.outputStream
- Output Pdf file Stream.public boolean makeBooklet(String inputFile, String outputFile)
Makes booklet from the input file to output file.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeBooklet("input.pdf", "output.pdf");
makeBooklet
in interface IPdfFileEditor
inputFile
- Input pdf file path and name.outputFile
- Output pdf file path and name.public boolean makeBooklet(InputStream inputStream, OutputStream outputStream)
Makes booklet from the InputStream to outputStream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileInputStream("output.pdf"); pfe.makeBooklet(inputStream, outputStream);
makeBooklet
in interface IPdfFileEditor
inputStream
- Input pdf stream.outputStream
- output pdf stream.public boolean makeBooklet(String inputFile, String outputFile, PageSize pageSize)
Makes booklet from the inputFile to outputFile.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeBooklet("input.pdf", "output.pdf", PageSize.A4);
makeBooklet
in interface IPdfFileEditor
inputFile
- Input pdf file path and name.outputFile
- Output pdf file path and name.pageSize
- The page size of the output pdf file.public boolean makeBooklet(InputStream inputStream, OutputStream outputStream, PageSize pageSize)
Makes booklet from the input stream and save result into output stream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileInputStream("output.pdf"); pfe.makeBooklet(inputStream, outputStream, PageSize.A4);
makeBooklet
in interface IPdfFileEditor
inputStream
- Input PDF stream.outputStream
- output pdf stream.pageSize
- The page size of the output pdf file.public boolean makeBooklet(String inputFile, String outputFile, int[] leftPages, int[] rightPages)
Makes customized booklet from the firstInputFile to outputFile.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeBooklet("input.pdf", "output.pdf", new int[] { 2, 4, 6 }, new int[] 1, 3, 5, 7 });
makeBooklet
in interface IPdfFileEditor
inputFile
- The input file.outputFile
- Output pdf file path and name.leftPages
- The left pages of the booklet.rightPages
- The right pages of the booklet.public boolean makeBooklet(InputStream inputStream, OutputStream outputStream, int[] leftPages, int[] rightPages)
Makes customized booklet from the firstInputStream to outputStream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileOutputStream("output.pdf"); pfe.makeBooklet(inputStream, outputStream, new int[] { 2, 4, 6 }, new int[] 1, 3, 5, 7 });
makeBooklet
in interface IPdfFileEditor
inputStream
- The input stream.outputStream
- output pdf stream.leftPages
- The left pages.rightPages
- The right pages.public boolean makeBooklet(String inputFile, String outputFile, PageSize pageSize, int[] leftPages, int[] rightPages)
Makes customized booklet from the firstInputFile to outputFile.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeBooklet("input.pdf", "output.pdf", PageSize.A4, new int[] { 2, 4, 6 }, new int[] 1, 3, 5, 7 });
makeBooklet
in interface IPdfFileEditor
inputFile
- The input file.outputFile
- Output pdf file path and name.pageSize
- The page size of the output pdf file.leftPages
- The left pages.rightPages
- The right pages.public boolean makeBooklet(InputStream inputStream, OutputStream outputStream, PageSize pageSize, int[] leftPages, int[] rightPages)
Makes booklet from the firstInputStream to outputStream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileOutputStream("output.pdf"); pfe.makeBooklet(inputStream, outputStream, PageSize.A4, new int[] { 2, 4, 6 }, new int[] 1, 3, 5, 7 });
makeBooklet
in interface IPdfFileEditor
inputStream
- The input stream.outputStream
- output pdf stream.pageSize
- The page size of the output pdf file.leftPages
- The left pages.rightPages
- The right pages.public boolean makeNUp(String inputFile, String outputFile, int x, int y)
Makes N-Up document from the firstInputFile to outputFile.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeNUp("input.pdf", "output.pdf", 3, 3);
makeNUp
in interface IPdfFileEditor
inputFile
- Input pdf file path and name.outputFile
- Output pdf file path and name.x
- Number of columns.y
- Number of rows.public boolean makeNUp(InputStream inputStream, OutputStream outputStream, int x, int y)
Makes N-Up document from the input stream and saves result into output stream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileOutputStream("output.pdf"); pfe.makeNUp(inputStream, outputStream, 3, 3);
makeNUp
in interface IPdfFileEditor
inputStream
- Input pdf stream.outputStream
- Output pdf stream.x
- Number of columns.y
- Number of rows.public boolean makeNUp(InputStream inputStream, OutputStream outputStream, int x, int y, PageSize pageSize)
Makes N-Up document from the first input stream to output stream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream inputStream = new FileInputStream("input.pdf"); OutputStream outputStream = new FileOutputStream("output.pdf"); pfe.MakeNUp(inputStream, outputStream, 3, 3, PageSize.A4);
makeNUp
in interface IPdfFileEditor
inputStream
- Input pdf stream.outputStream
- Output pdf stream.x
- Number of columns.y
- Number of rows.pageSize
- The page size of the output pdf file.public boolean makeNUp(String firstInputFile, String secondInputFile, String outputFile)
Makes N-Up document from the two input PDF files to outputFile. Each page of outputFile will contain two pages, one page is from the first input file and another is from the second input file. The two pages are piled up horizontally.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeNUp("input1.pdf", "input2.pdf", "output.pdf");
makeNUp
in interface IPdfFileEditor
firstInputFile
- first input file.secondInputFile
- second input file.outputFile
- Output pdf file path and name.public boolean makeNUp(InputStream firstInputStream, InputStream secondInputStream, OutputStream outputStream)
Makes N-Up document from the two input PDF streams to outputStream.
PdfFileEditor pfe = new PdfFileEditor(); InputStream input1 = new FileInputStream("input1.pdf"); InputStream input2 = new FileInputStream("input2.pdf"); OutputStream output = new FileOutputStream("output.pdf"); pfe.makeNUp(input1, input2, output);
makeNUp
in interface IPdfFileEditor
firstInputStream
- first input stream.secondInputStream
- second input stream.outputStream
- Output pdf stream.public boolean makeNUp(String[] inputFiles, String outputFile, boolean isSidewise)
Makes N-Up document from the multi input PDF files to outputFile. Each page of outputFile will contain multi pages, which are combination with pages in the input files of the same page number. The multi pages piled up horizontally if isSidewise is true and piled up vertically if isSidewise is false.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeNUp(new String[] { "input1.pdf", "input2.pdf", "input3.pdf" }, "output.pdf", false);
makeNUp
in interface IPdfFileEditor
inputFiles
- Input Pdf files.outputFile
- Output pdf file path and name.isSidewise
- Piled up way, true for horizontally and flase for vertically.public boolean makeNUp(InputStream[] inputStreams, OutputStream outputStream, boolean isSidewise)
Makes N-Up document from the multi input PDF streams to outputStream. Each page of outputStream will contain multi pages, which are combination with pages in the input streams of the same page number. The multi-pages piled up horizontally if isSidewise is true and piled up vertically if isSidewise is false.
PdfFileEditor pfe = new PdfFileEditor(); InputStream stream1 = new FileInputStream("input1.pdf"); InputStream stream2 = new FileInputStream("input2.pdf"); InputStream stream3 = new FileInputStream("input3.pdf"); OutputStream output = new FileOutputStream("output.pdf"); pfe.makeNUp(new InputStream[] { stream1, stream2, stream3 }, output, false);
makeNUp
in interface IPdfFileEditor
inputStreams
- Input Pdf streams.outputStream
- Output pdf stream.isSidewise
- Piled up way, true for horizontally and flase for verticallypublic boolean makeNUp(String inputFile, String outputFile, int x, int y, PageSize pageSize)
Makes N-Up document from the input file to outputFile.
PdfFileEditor pfe = new PdfFileEditor(); pfe.makeNUp("input.pdf", "output.pdf", 3, 3, PageSize.A4);
makeNUp
in interface IPdfFileEditor
inputFile
- Input pdf file path and name.outputFile
- Output pdf file path and name.x
- Number of columns.y
- Number of rows.pageSize
- The page size of the output pdf file.public ByteArrayInputStream[] splitToPages(String inputFile)
Splits the PDF file into single-page documents.
splitToPages
in interface IPdfFileEditor
inputFile
- Input PDF file name.public ByteArrayInputStream[] splitToPages(InputStream inputStream)
Splits the Pdf file into single-page documents.
splitToPages
in interface IPdfFileEditor
inputStream
- Input Pdf stream.public ByteArrayInputStream[] splitToBulks(String inputFile, int[][] numberOfPage)
Splits the Pdf file into several documents.The documents can be single-page or multi-pages.
splitToBulks
in interface IPdfFileEditor
inputFile
- Input PDF file.numberOfPage
- Array which contains array of double elements, which is start and end pages of document.public ByteArrayInputStream[] splitToBulks(InputStream inputStream, int[][] numberOfPage)
Splits the Pdf file into several documents.The documents can be single-page or multi-pages.
splitToBulks
in interface IPdfFileEditor
inputStream
- Input PDF stream.numberOfPage
- The start page and the end page of each document.public Exception getLastException()
Gets last occured exception. May be used to check the reason of failure when AllowconcatenateExceptions = false.
getLastException
in interface IPdfFileEditor
PdfFileEditor pfe = new PdfFileEditor(); pfe.setAllowConcatenateExceptions ( false); if (!pfe.concatenate("file1.pdf", "file2.pdf", "file3.pdf")) { System.out.println("Error occured:"); if (pfe.getLastException() != null) { System.out.println(pfe.getLastException().getMessage()); if (pfe.getLastException().getCause() != null) System.out.println(pfe.getLastException().getCause().getMessage()); } }
public boolean resizeContents(InputStream source, OutputStream destination, int[] pages, IPdfFileEditor.ContentsResizeParameters parameters)
Resizes contents of pages of the document.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream src = new FileInputStream("input.pdf"); OutputStream dest = new FileOutputStream("output.pdf"); PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters( //left margin = 10% of page width PdfFileEditor.ContentsResizeValue.percents(10), //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%) null, //right margin is 10% of page PdfFileEditor.ContentsResizeValue.percents(10), //top margin = 10% of height PdfFileEditor.ContentsResizeValue.percents(10), //new contents height is calculated automatically (similar to width) null, //bottom margin is 10% PdfFileEditor.ContentsResizeValue.percents(10) ); fileEditor.resizeContents(src, dest, new int[] { 1, 2, 3}, parameters); dest.close();
source
- Stream with source document.destination
- Stream with the destination document.pages
- Array of page indexes.parameters
- Resize parameters.public boolean resizeContents(InputStream source, OutputStream destination, int[] pages, double newWidth, double newHeight)
Resizes contents of document pages. Shrinks contents of page and adds margins. New size of contents is specified in default space units.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream src = new FileInputStream("input.pdf"); OutputStream dest = new FileOutputStream("output.pdf"); fileEditor.resizeContents(src, dest, //resize all pages of document null, //new contents width = 200 200, //new contents height = 300 300); // rest area of page will be empty
resizeContents
in interface IPdfFileEditor
source
- Stream which contains source document.destination
- Stream where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.newWidth
- New width of page contents in default space units.newHeight
- New height of page contents in default space units.public boolean resizeContentsPct(InputStream source, OutputStream destination, int[] pages, double newWidth, double newHeight)
Resizes contents of document pages. Shrinks contents of page and adds margins. New contents size is specified in percents.
PdfFileEditor fileEditor = new PdfFileEditor(); InputStream src = new FileInputStream("input.pdf"); OutputStream dest = new FileOutputStream("output.pdf"); fileEditor.resizePct(src, dest, //resize all pages of document null, //new contents width = 60% of initial size 60, //new contents height = 60% of initial size 60); // Rest area of page will be empty (page margins). Size of left and right margins is (100% - 60%) / 2 = 20% // The same for top and bottom margins.
resizeContentsPct
in interface IPdfFileEditor
source
- Stream which contains source document.destination
- Stream where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.newWidth
- New width of page contents in percents.newHeight
- New height of page contents in percetns.public boolean addMargins(InputStream source, OutputStream destination, int[] pages, double leftMargin, double rightMargin, double topMargin, double bottomMargin)
Resizes page contents and add specifed margins. Margins are specified in default space units.
PdfFileEditor fileEditor = new PdfFileEditor(); InmputStream src = new FileInputStream("input.pdf"); OutputStream dest = new FileInputStream("output.pdf"); fileEditor.addMargins(src, dest, //process pages 1, 2, 3 new int[] { 1, 2, 3}, //left margin is 10 units 10, //right margin is 5 units 5, //top margin is 5 units 5, //bottom margin is 5 units 5); dest.Close();
addMargins
in interface IPdfFileEditor
source
- Stream which contains source document.destination
- Stream where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.leftMargin
- Left margin.rightMargin
- Right margin.topMargin
- Top margin.bottomMargin
- Bottom margin.public boolean addMarginsPct(InputStream source, OutputStream destination, int[] pages, double leftMargin, double rightMargin, double topMargin, double bottomMargin)
Resizes page contents and add specified margins. Margins are specified in percents of intitial page size.
PdfFileEditor fileEditor = new PdfFileEditor(); InmputStream src = new FileInputStream("input.pdf"); OutputStream dest = new FileInputStream("output.pdf"); fileEditor.addMarginsPct(src, dest, //process pages 1, 2, 3 new int[] { 1, 2, 3}, //left margin is 15% of page width 15, //right margin is 10% of page width 10, //top margin is 20% of page width 20, //bottom margin is 5% of page width 5); dest.close();
addMarginsPct
in interface IPdfFileEditor
source
- Stream which contains source document.destination
- Stream where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.leftMargin
- Left margin in percents of initial page size.rightMargin
- Right margin in percents of initial page size.topMargin
- Top margin in percents of initial page size.bottomMargin
- Bottom margin in percents of initial page size.public boolean resizeContents(String source, String destination, int[] pages, double newWidth, double newHeight)
Resizes contents of document pages. Shrinks contents of page and adds margins. New size of contents is specified in default space units.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.resizeContents("input.pdf", "output.pdf", //resize all pages of document null, //new contents width = 200 200, //new contents height = 300 300); // rest area of page will be empty
resizeContents
in interface IPdfFileEditor
source
- Path to source document.destination
- Path where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.newWidth
- New width of page contents in default space units.newHeight
- New height of page contents in default space units.public boolean resizeContentsPct(String source, String destination, int[] pages, double newWidth, double newHeight)
Resizes contents of document pages. Shrinks contents of page and adds margins. New contents size is specified in percents.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.resizePct("input.pdf", "output.pdf", //resize all pages of document null, //new contents width = 60% of initial size 60, //new contents height = 60% of initial size 60); // Rest area of page will be empty (page margins). Size of left and right margins is (100% - 60%) / 2 = 20% // The same for top and bottom margins.
resizeContentsPct
in interface IPdfFileEditor
source
- Path to source document.destination
- Path where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.newWidth
- New width of page contents in percents.newHeight
- New height of page contents in percetns.public boolean addMargins(String source, String destination, int[] pages, double leftMargin, double rightMargin, double topMargin, double bottomMargin)
Resizes page contents and add specifed margins. Margins are specified in default space units.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.addMargins("input.pdf", "output.pdf", //process pages 1, 2, 3 new int[] { 1, 2, 3}, //left margin is 10 units 10, //right margin is 5 units 5, //top margin is 5 units 5, //bottom margin is 5 units 5);
addMargins
in interface IPdfFileEditor
source
- Path to source document.destination
- Path where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.leftMargin
- Left margin.rightMargin
- Right margin.topMargin
- Top margin.bottomMargin
- Bottom margin.public boolean addMarginsPct(String source, String destination, int[] pages, double leftMargin, double rightMargin, double topMargin, double bottomMargin)
Resizes page contents and add specified margins. Margins are specified in percents of intitial page size.
PdfFileEditor fileEditor = new PdfFileEditor(); fileEditor.addMarginsPct("input.pdf", "output.pdf", //process pages 1, 2, 3 new int[] { 1, 2, 3}, //left margin is 15% of page width 15, //right margin is 10% of page width 10, //top margin is 20% of page width 20, //bottom margin is 5% of page width 5);
addMarginsPct
in interface IPdfFileEditor
source
- Path to source document.destination
- Path where resultant document will be saved.pages
- Array of page indexes. If null then all document pages will be processed.leftMargin
- Left margin in percents of initial page size.rightMargin
- Right margin in percents of initial page size.topMargin
- Top margin in percents of initial page size.bottomMargin
- Bottom margin in percents of initial page size.public boolean resizeContents(String source, String destination, int[] pages, IPdfFileEditor.ContentsResizeParameters parameters)
Resizes contents of pages in document. If page is shrinked blank margins are added around the page.
PdfFileEditor fileEditor = new PdfFileEditor(); PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters( //left margin = 10% of page width PdfFileEditor.ContentsResizeValue.percents(10), //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%) null, //right margin is 10% of page PdfFileEditor.ContentsResizeValue.percents(10), //top margin = 10% of height PdfFileEditor.ContentsResizeValue.percents(10), //new contents height is calculated automatically (similar to width) null, //bottom margin is 10% PdfFileEditor.ContentsResizeValue.percents(10) ); fileEditor.resizeContents("input.pdf", "output.pdf", new int[] { 1, 2,.3}, parameters);
source
- Source document path.destination
- Destination document path.pages
- Array of page indexes (page index starts from 1).parameters
- Parameters of page resize.public void resizeContents(IDocument source, int[] pages, IPdfFileEditor.ContentsResizeParameters parameters)
Resizes pages of document. Blank margins are added around of shrinked page.
PdfFileEditor fileEditor = new PdfFileEditor(); Document doc = new Document("input.pdf"); PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters( //left margin = 10% of page width PdfFileEditor.ContentsResizeValue.percents(10), //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%) null, //right margin is 10% of page PdfFileEditor.ContentsResizeValue.percents(10), //top margin = 10% of height PdfFileEditor.ContentsResizeValue.percents(10), //new contents height is calculated automatically (similar to width) null, //bottom margin is 10% PdfFileEditor.ContentsResizeValue.percents(10) ); fileEditor.resizeContents(doc, new int[] { 1, 2, 3}, parameters); doc.save("output.pdf");
source
- Source document.pages
- List of page indexes.parameters
- Resize parameters.public int getContentDisposition()
Gets how content will be stored when result of operation is stored into HttpServletResponse object. Possible value: inline / attachment. Default: inline.
getContentDisposition
in interface IPdfFileEditor
ContentDisposition
public void setContentDisposition(int value)
Sets how content will be stored when result of operation is stored into HttpServletResponse object. Possible value: inline / attachment. Default: inline.
setContentDisposition
in interface IPdfFileEditor
value
- int valueContentDisposition
public SaveOptions getSaveOptions()
Gets or sets save options when result is stored as HttpServletResponse. Default value: PdfSaveOptions.
getSaveOptions
in interface IPdfFileEditor
public void setSaveOptions(SaveOptions value)
Sets save options when result is stored as HttpServletResponse. Default value: PdfSaveOptions.
setSaveOptions
in interface IPdfFileEditor
value
- SaveOptions objectpublic String getAttachmentName()
Gets name of attachment when result of operation is stored into HttpServletResponse objects as attachment.
getAttachmentName
in interface IPdfFileEditor
public void setAttachmentName(String value)
Sets name of attachment when result of operation is stored into HttpServletResponse objects as attachment.
setAttachmentName
in interface IPdfFileEditor
value
- String valuepublic String getConversionLog()
Gets log of conversion process.
getConversionLog
in interface IPdfFileEditor
public boolean getMergeDuplicateLayers()
Optional contents of concatentated documents with equal names will be merged into one layer in resulstant document if this property is true. Else, layers with equal names will be save as different layers in resultant document.
getMergeDuplicateLayers
in interface IPdfFileEditor
public void setMergeDuplicateLayers(boolean value)
IPdfFileEditor
Optional contents of concatentated documents with equal names will be merged into one layer in resulstant document if this property is true. Else, layers with equal names will be save as different layers in resultant document.
setMergeDuplicateLayers
in interface IPdfFileEditor
value
- boolean valuepublic boolean getCopyOutlines()
If true then outlines will be copied.
public void setCopyOutlines(boolean value)
If true then outlines will be copied.
value
- boolean valuepublic boolean getCopyLogicalStructure()
If true then logical structure of the file is copied when concatenation is performed.
public void setCopyLogicalStructure(boolean value)
If true then logical structure of the file is copied when concatenation is performed.
value
- boolean valuepublic boolean getMergeDuplicateOutlines()
If true, duplicate outlines are merged.
getMergeDuplicateOutlines
in interface IPdfFileEditor
public void setMergeDuplicateOutlines(boolean value)
If true, duplicate outlines are merged.
setMergeDuplicateOutlines
in interface IPdfFileEditor
value
- boolean valuepublic boolean getPreserveUserRights()
If true, user rights of first document are applied to concatenated document. User rights of all other documents are ignored.
getPreserveUserRights
in interface IPdfFileEditor
public void setPreserveUserRights(boolean value)
If true, user rights of first document are applied to concatenated document. User rights of all other documents are ignored.
setPreserveUserRights
in interface IPdfFileEditor
value
- boolean valuepublic boolean getIncrementalUpdates()
If true, incremental updates are made during concatenation.
getIncrementalUpdates
in interface IPdfFileEditor
public void setIncrementalUpdates(boolean value)
If true, incremental updates are made during concatenation.
setIncrementalUpdates
in interface IPdfFileEditor
value
- boolean valuepublic boolean getOptimizeSize()
Gets or sets optimization flag. Equal resource streams in resultant file are merged into one PDF object if this flag set. This allows to decrease resultant file size but may cause slower execution and larger memory requirements. Default value: false.
public void setOptimizeSize(boolean value)
Gets or sets optimization flag. Equal resource streams in resultant file are merged into one PDF object if this flag set. This allows to decrease resultant file size but may cause slower execution and larger memory requirements. Default value: false.
value
- boolean valuepublic final boolean getKeepActions()
If true actions will be copied from source documents. Defaulkt value : true.
public final void setKeepActions(boolean value)
If true actions will be copied from source documents. Defaulkt value : true.
value
- boolean valuepublic boolean getUseDiskBuffer()
If this option used then destination document will be saved on disk periodically and further concatenation will appllied to it as incremental updates.
public void setUseDiskBuffer(boolean value)
If this option used then destination document will be saved on disk periodically and further concatenation will appllied to it as incremental updates.
value
- boolean valuepublic int getConcatenationPacketSize()
Number of documents concatenated before new incremental update was made during concatenation when UseDiskBuffer is set to true.
public void setConcatenationPacketSize(int value)
Number of documents concatenated before new incremental update was made during concatenation when UseDiskBuffer is set to true.
value
- int valuepublic void splitToPages(String inputFile, String fileNameTemplate)
Split the Pdf file into single-page documents and saves it into specified path. Path is specifield by field name temaplate.
splitToPages
in interface IPdfFileEditor
inputFile
- Input file name.fileNameTemplate
- Template of resultant file name. Must contain %NUM% which is replaced with page number
. For
example, if c:/dir/page%NUM%.pdf is specified, resultant files will have the following
names:
c:/dir/page1.pdf, c:/dir/page2.pdf etc.public void splitToPages(InputStream inputStream, String fileNameTemplate)
Split the Pdf file into single-page documents and saves it into specified path. Path is specifield by field name temaplate.
splitToPages
in interface IPdfFileEditor
inputStream
- Stream of the soruce document.fileNameTemplate
- Template of resultant file name. Must contain %NUM% which is replaced with page number
. For
example, if c:/dir/page%NUM%.pdf is specified, resultant files will have the following
names:
c:/dir/page1.pdf, c:/dir/page2.pdf etc.public void resizeContents(Document source, IPdfFileEditor.ContentsResizeParameters parameters)
Resizes pages of document. Blank margins are added around of shrinked page.
PdfFileEditor fileEditor = new PdfFileEditor(); Document src = new Document("input.pdf"); Document dest = new Document(); APdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters( //left margin = 10% of page width PdfFileEditor.ContentsResizeValue.percents(10), //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%) null, //right margin is 10% of page PdfFileEditor.ContentsResizeValue.percents(10), //top margin = 10% of height PdfFileEditor.ContentsResizeValue.percents(10), //new contents height is calculated automatically (similar to width) null, //bottom margin is 10% PdfFileEditor.ContentsResizeValue.percents(10) ); fileEditor.resizeContents(doc, parameters); dest.save("output.pdf");
source
- Source document.parameters
- Resize parameters.public void addPageBreak(IDocument src, IDocument dest, PdfFileEditor.PageBreak[] pageBreaks)
Adds page breaks into document pages.
src
- Source document.dest
- Destination document.pageBreaks
- Array of PageBreak objects which describe places of page breaks.public void addPageBreak(String src, String dest, PdfFileEditor.PageBreak[] pageBreaks)
Adds page breaks into document pages.
src
- Path to source document.dest
- Path to destination document.pageBreaks
- Array of PageBreak object describing pages and places where page break will be added.public void addPageBreak(InputStream src, OutputStream dest, PdfFileEditor.PageBreak[] pageBreaks)