Hi,

I had a code merging two PDFs, which was using setTagged in case both of
the concatenated PDFs are tagged (worked well with 5.4.3).

I've now downloaded the new release and all of a sudden the following
RUNTIME error appeared when closing the PDF (on the line:
 document.close();):

Exception in thread "main" ExceptionConverter: java.io.IOException:
RandomAccessSource not opened
        at
com.itextpdf.text.io.MappedChannelRandomAccessSource.get(MappedChannelRandomAccessSource.java:140)
        at
com.itextpdf.text.io.FileChannelRandomAccessSource.get(FileChannelRandomAccessSource.java:97)
        at
com.itextpdf.text.io.GetBufferedRandomAccessSource.get(GetBufferedRandomAccessSource.java:91)
        at
com.itextpdf.text.io.IndependentRandomAccessSource.get(IndependentRandomAccessSource.java:77)
        at
com.itextpdf.text.pdf.RandomAccessFileOrArray.read(RandomAccessFileOrArray.java:225)
        at
com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:247)
        at
com.itextpdf.text.pdf.RandomAccessFileOrArray.readFully(RandomAccessFileOrArray.java:241)
        at
com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2480)
        at
com.itextpdf.text.pdf.PdfReader.getStreamBytesRaw(PdfReader.java:2517)
        at com.itextpdf.text.pdf.PRStream.toPdf(PRStream.java:215)
        at
com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)
        at
com.itextpdf.text.pdf.PdfWriter$PdfBody.write(PdfWriter.java:424)
        at
com.itextpdf.text.pdf.PdfCopy.writeObjectToBody(PdfCopy.java:1109)
        at
com.itextpdf.text.pdf.PdfCopy.flushIndirectObjects(PdfCopy.java:1064)
        at
com.itextpdf.text.pdf.PdfCopy.flushTaggedObjects(PdfCopy.java:801)
        at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:836)
        at com.itextpdf.text.Document.close(Document.java:416)
        at Concatenate.main(Concatenate.java:108)


Here is the relevant code:

    public static void main(String[] args)
        throws IOException, DocumentException, SQLException {


        String[] files=args;


    // step 1
        PdfReader reader_branding = new PdfReader(files[0]);
            PdfReader reader = new PdfReader(System.in);
            boolean setTagged=reader.isTagged() &&
reader_branding.isTagged();


      Document document = new Document();
        // step 2

        PdfCopy copy = new PdfCopy(document, System.out);
        if (setTagged)
            {
                 copy.setTagged();
            }

        document.open();

        int n;


            // loop over the pages in that document
            n = reader_branding.getNumberOfPages();
            for (int page = 0; page < n; ) {
            if (setTagged)
                {
                copy.addPage(copy.getImportedPage(reader_branding,
++page,true));
                }else
                {
                        copy.addPage(copy.getImportedPage(reader_branding,
++page));
                };

                 }
            copy.freeReader(reader_branding);
            reader_branding.close();

           //reader = new PdfReader(System.in);
            // loop over the pages in that document
            n = reader.getNumberOfPages();
            for (int page = 0; page < n; ) {
                if (setTagged)
                {
                copy.addPage(copy.getImportedPage(reader, ++page,true));
                }else
                {
                        copy.addPage(copy.getImportedPage(reader, ++page));
                };
        }
            copy.freeReader(reader);
            reader.close();

        // step 5
        document.close();
    }
}

Would appreciate your kind help!

The reason I was updating to the new release is that albeit the
accessibility support on 5.4.3, the "read out loud" feature of Adobe failed
to read the output PDF (although it passed most of the accessibility tests,
but not all of them, of course).
JAWS also failed to read the document properly.
When I re-downloaded the "readoutloud.pdf" sample, I noticed that it was
updated and now readable by Adobe Reader, and when checking the properties
of the PDF it showed that the new version which worked was generated by
5.4.4 and this was the reason for the update (my main motivation to switch
to iText was the accessibility support).

Many thanks!
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&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

Reply via email to