Will Rayer,
Can you try following code its work.
Inside the For loop u can get all the time new RandomAccessFileOrArray its
works.
// Loop through all the pages in the TIFF file, convert each to
PDF.
for (int c = 0; c < comps; ++c) {
try {
* ** RandomAccessFileOrArray raNew = null;*
* raNew = new RandomAccessFileOrArray(fis);*
Image img = TiffImage.getTiffImage(raNew , c
+ 1);
if (img != null) {
if (img.getScaledWidth() > 500 ||
img.getScaledHeight() > 700) {
img.scaleToFit(500,
700);
}
img.setAbsolutePosition(20, 20);
//document.add(new Paragraph(tiff_file +
" - page " + (c + 1)));
cb.addImage(img);
document.newPage();
++pages;
}
}
catch (Throwable e) {
throw new PRRuntimeException("Exception " +
tiff_file + " page " + (c + 1) + " " + e.getMessage());
}
}
// Close the TIFF file and the PDF file.
ra.close();
document.close();
}
On Thu, Nov 19, 2009 at 1:32 PM, Rayer, William (RBS Coutts, Jersey) <
will.ra...@rbscoutts.com> wrote:
>
> Dear iText
> We have been using your conversion library as part of the deployment of
> a Java web-based system (Pega BPM). During the conversion of some TIFF
> files to PDF, we have found that if a TIFF file contains the same page
> repeated twice or more, the conversion process fails. Is it possible
> that TIFF files containing repeated pages use some kind of compression
> that isn't handled by iText? The error message we get is not very
> specific, eg "page NN NULL". By examining the input TIFF we can tell
> that Page NN is identical as page NN-1. We are using the following
> (attached) Java for the conversion:
>
>
> String sError = "";
> String tiff_file = InputTiffFile;
> String pdf_file = tiff_file.substring(0, tiff_file.lastIndexOf('.') + 1)
> + "pdf";
>
> Document document = new Document();
>
> try {
> // Create PDF file writer.
> FileOutputStream fos = new FileOutputStream(pdf_file);
> PdfWriter writer = PdfWriter.getInstance(document, fos);
> document.open();
> int pages = 0;
> PdfContentByte cb = writer.getDirectContent();
>
> // Open the TIFF file and find the number of pages.
> RandomAccessFileOrArray ra = null;
> int comps = 0;
> FileInputStream fis = null;
> try {
> File tiffFile = new File(tiff_file);
> fis = new FileInputStream(tiffFile);
> }
> catch (Throwable e) {
> throw new PRRuntimeException("Tiff file " + tiff_file +
>
> " could not be opened, it does not exist or
> lacks permissions. "
> + e.getMessage());
> }
>
> try {
> ra = new RandomAccessFileOrArray(fis);
> comps = TiffImage.getNumberOfPages(ra);
> }
> catch (Throwable e) {
> throw new PRRuntimeException("Tiff file " + tiff_file
> + " could not be opened as a Random Access File. "
> + e.getMessage());
> }
>
> // Loop through all the pages in the TIFF file, convert each to
> PDF.
> for (int c = 0; c < comps; ++c) {
> try {
> Image img = TiffImage.getTiffImage(ra, c
> + 1);
> if (img != null) {
> if (img.getScaledWidth() > 500 ||
> img.getScaledHeight() > 700) {
> img.scaleToFit(500,
> 700);
> }
> img.setAbsolutePosition(20, 20);
> //document.add(new Paragraph(tiff_file +
> " - page " + (c + 1)));
> cb.addImage(img);
> document.newPage();
> ++pages;
> }
> }
> catch (Throwable e) {
> throw new PRRuntimeException("Exception " +
> tiff_file + " page " + (c + 1) + " " + e.getMessage());
> }
> }
>
> // Close the TIFF file and the PDF file.
> ra.close();
> document.close();
> }
> catch (Throwable e) {
> // throw new PRRuntimeException("Error converting Tiff file
> "+tiff_file+" to PDF "+ e.getMessage());
> sError = "Error converting Tiff file " + tiff_file + " to PDF "
> + e.getMessage() + ".";
> }
>
> // If anything went wrong, return "*" + the error description.
> // If we converted OK, return the pdf_file name.
> return ((sError.length() > 0) ? "*" + sError : pdf_file);
>
>
> We are using version "itext-2.0.8.jar" of iText, size 1,213,150 bytes.
> Is this a known issue and is there a work-around?
>
> Will Rayer
> Senior Systems Analyst
>
> RBS Coutts TFS,
> PO Box 6, 23-25 Broad Street,
> St Helier, Jersey JE4 8ND
> Direct line: + 44 1534 282563
> E-mail: will.ra...@rbscoutts.com
>
> _______________________________________________________________
>
> DISCLAIMER
>
> This e-mail message is confidential and for use by the addressee only. If
> the message is received by anyone other than the intended addressee, please
> return the message to the sender by replying to it and then delete the
> message from your computer. This e-mail may also be legally privileged
> and any unauthorised use may be unlawful and result in civil and or criminal
> proceedings being taken against you.
>
> Internet e-mails are not necessarily secure as information might be
> intercepted, lost or destroyed. Please do not e-mail any account or other
> confidential information.
>
> The Royal Bank of Scotland International Limited, The Royal Bank of
> Scotland (Gibraltar) Limited and The Isle of Man Bank Limited, (the
> "Companies") do not accept responsibility for changes made to this message
> after it was sent.
>
> If you have received this message in error please contact our IT helpdesk
> immediately on (+44) (0) 1534 285 268.
>
> While all reasonable care has been taken to avoid the transmission of
> viruses, it is the responsibility of the recipient to ensure that the onward
> transmission, opening or use of this message and any attachments will not
> adversely affect its systems or data. No responsibility is accepted by the
> Companies in this regard and the recipient should carry out such virus and
> other checks as it considers appropriate.
>
> This e-mail facility is provided by the Companies, which are members of The
> Royal Bank of Scotland Group.
>
> Calls may be recorded.
>
> Please refer to (place link) for regulatory disclosures.
>
> http://www.rbscoutts.com/legal_notice.asp
> _______________________________________________________________
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list:
> http://1t3xt.info/tutorials/keywords/
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/