Hello,
I have one observation from the code I wrote from PDF file split up using
iText.
I have two PDFs for size 182 KB and 185 KB.
I merged them using acrobat writer. The merged file size is displayed as
349KB.
Now I am splitting the merged file exactly into two files giving correct
page number.
I get two new files but there size is 184 KB and 186 KB instead of 182 KB
and 185 KB.
In my application these files give errors as my code is unable to find the
required form fields in these files where are the original files work
correctly.
There two files when opened in acrobat reader looks content wise same as
original files.
My code for splitting is as follows:
public byte[] splitPDF(byte[] inputBytes,
int fromPage, int toPage) throws IOException {
Document document = new Document();
boolean isException = false;
byte[] outputBytes = new byte[inputBytes.length];
ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(outputBytes.length);
try {
PdfReader inputPDF = new PdfReader(inputBytes);
int totalPages = inputPDF.getNumberOfPages();
//make fromPage equals to toPage if it is greater
if(fromPage > toPage ) {
fromPage = toPage;
}
if(toPage > totalPages) {
toPage = totalPages;
}
// Create a writer for the outputstream
PdfWriter writer = PdfWriter.getInstance(document,
outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
data
PdfImportedPage page;
while(fromPage <= toPage) {
document.newPage();
page = writer.getImportedPage(inputPDF, fromPage);
cb.addTemplate(page, 0, 0);
fromPage++;
}
outputStream.flush();
document.close();
outputBytes = outputStream.toByteArray();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
isException = true;
} finally {
if (document.isOpen())
document.close();
try {
if (outputStream != null)
outputStream.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
if (isException) {
throw new IOException("unable to split document");
}
return outputBytes ;
}
I guess the byte contents are not getting regenerated correctly as in
original case.
Can anyone please throw some light on this?
Regards
Geeta Bapat | Specialist System Designer | Arrk Group
Tel +91 (0)22 2778 4233 | Fax +91 (0)22 2778 4210 |
<blocked::http://www.arrkgroup.com/> www.arrkgroup.com
THINK DIFFERENT. THINK ARRK.
Web & mobile development specialists - Application Management services -
unique hybrid delivery.
*** British Computer Society & Computer Weekly National IT Awards medal
winner ***
*** Proud developers and supporters of Virgin Money Giving -
<blocked::http://www.virginmoneygiving.org/> www.virginmoneygiving.org ***
Email Disclaimer: <blocked::http://www.arrkgroup.com/EmailDisclaimer>
www.arrkgroup.com/EmailDisclaimer
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php