Hi,

I am using the iText 1.3 jar file to run a Java Agent on Lotus Notes, which
does merge the PDFs.
I have been facing an issue for a while now when I select two or three
documents (which are PDFs) and click on MergeDoc, I get this series of
errors. 

This nature of throwing errors does not happen in a pattern, very sporadic.
9 out 10 times it works fine.



Please take a look at the stacktrace below:
-----------------------------------------------------------------------------

java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:124)
        at com.lowagie.text.pdf.OutputStreamCounter.write(Unknown Source)
        at com.lowagie.text.pdf.PRStream.toPdf(Unknown Source)
        at com.lowagie.text.pdf.PdfIndirectObject.writeTo(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter$PdfBody.add(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter$PdfBody.add(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter.addToBody(Unknown Source)
        at com.lowagie.text.pdf.PdfCopyFieldsImp.closeIt(Unknown Source)
        at com.lowagie.text.pdf.PdfCopyFieldsImp.close(Unknown Source)
        at com.lowagie.text.pdf.PdfCopyFields.close(Unknown Source)
        at JavaAgent.NotesMain(JavaAgent.java:61)
        at lotus.domino.AgentBase.runNotes(Unknown Source)
        at lotus.domino.NotesThread.run(Unknown Source)


-------------------------------------------------------------------------



Here is the code I use to merge documents:

public void NotesMain() {
                try {
                        Session session = getSession();
                        AgentContext agentContext = session.getAgentContext();

                        // getting the configuration profile
                        Database db = agentContext.getCurrentDatabase();
                        View confView = db.getView("Configuration");
                        
                        
                        Document confDoc = confView.getFirstDocument();
                        DocumentCollection dc = 
agentContext.getUnprocessedDocuments();
                        Document doc = dc.getFirstDocument();
                                                
                        // final merged pdf file
                        PdfCopyFields copy = new PdfCopyFields(new
FileOutputStream(confDoc.getItemValueString("temp")+ "MergedDoc.pdf"));
                        
                        //looping through documents
                        while (doc != null) {

                                RichTextItem rtitem = (RichTextItem) 
doc.getFirstItem("Body");

                                if (rtitem != null) {
                                        EmbeddedObject obj = (EmbeddedObject)
rtitem.getEmbeddedObjects().elementAt(0);
                                        
                                        if (obj.getType() == 
EmbeddedObject.EMBED_ATTACHMENT) {
                                                
                                                
                                                String fileName = 
obj.getSource();
                                                
                                                PdfReader reader1;
                                                
                                                // this is to check whether the 
document is already merged with
another pdf's
                                                
                                                if 
(fileName.equals("MergedDoc.pdf")) {
                                                        // extracting the 
existing pdf
                                                        
obj.extractFile(confDoc.getItemValueString("temp")+ "ALLPAGES.pdf");
                                                        reader1 = new 
PdfReader(confDoc.getItemValueString("temp")+
"ALLPAGES.pdf");
                                                        
                                                } else {
                                                        
                                                        
obj.extractFile(confDoc.getItemValueString("temp")+ obj.getSource());
                                                        reader1 = new 
PdfReader(confDoc.getItemValueString("temp")+
obj.getSource());
                                                        
                                                }

                                                copy.addDocument(reader1);
                                                reader1 = null;

                                        }
                                }
                                                                
                                doc = dc.getNextDocument();
                        }
                        
                        if (copy != null)
                            copy.close();
                        
                        system.out.println("No Error so far..");

                } catch (Exception de) {
                        System.out.println("Error");
                        de.printStackTrace();
                }

        }
-----------------------------------------------------------------------------


Any help is very much appreciated.
Thanks!!




-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/ArrayIndexOutOfBoundsException-tp2539504p2539504.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
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/

Reply via email to