Hi all,

I stepped into a problem when using PdfReader to open some documents. For instance, an IllegalArgumentException is thrown by PdfName constructor complaining about some PdfName being too long.

The exception is as follows:

java.lang.IllegalArgumentException: The name 'Corpo de texto;bt;Block text;body text;BODY TEXT;t;Body;sp;text;sbs;block text;1;bt4;body text4;bt5;body text5;bt1;body text1;Justified;plain paragraph;pp;??1;Block 55;??1;txt1;T1;Title 1;Text;Teh2xt;Resposta 1;tx;Resume Text;RFP Text;B;b;EHPT;Garamond' is too long (252 characters).
    at com.lowagie.text.pdf.PdfName.<init>(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readPRObject(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readDictionary(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readPRObject(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readObjStm(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readDocObj(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.readPdf(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
    at br.com.ect.sadel.control.PreparacaoDocumentoControle.executarPreparacao(PreparacaoDocumentoControle.java:228)
    at br.com.ect.sadel.control.PreparacaoDocumentoControle.executarPreparacao(PreparacaoDocumentoControle.java:128)
    at br.com.ect.sadel.control.PreparacaoDocumentoControle.run(PreparacaoDocumentoControle.java:457)
    at java.lang.Thread.run(Thread.java:595)


After taking a look at PdfName I noticed the following lines, of interest to this particular case:

    public PdfName(String name) {
        super(PdfObject.NAME);
        // The minimum number of characters in a name is 0, the maximum is 127 (the '/' not included)
        int length = name.length();
        if (length > 127) {
            throw new IllegalArgumentException("The name '" + name + "' is too long (" + length + " characters).");
        }


I've also checked at PDF Reference (Section 3.2.4) and it confirmed that "the length of a name is subject to an implementation limit". Also, at Appendix C.1 there is an implementation limit table stating that the name object maximum length is 127. So, PdfName class implementation is in strict agreement as to what the PDF Reference states about this name length issue.

So it seems that my problem is that my PDF documents have inapropriate name objects. As a matter of fact, they were transformed from original MS DOC documents into PDF, and this process may be generating the PDF files the wrong way.

However, even though these files are wrong, according to PDF Reference, common PDF Viewers actually "view" these documents without any complaint at all about this name object length issue.

Therefore, I have two questions regarding these subjects:

1) What does PDF Viewers (namely acrobat reader and acrobat standard) do when they face these longer-than-allowed names? Do they ignore them? Do they truncate them into 127 characters? Fact is that they open my documents.

2) Considering that I am unable to change the way my clients create their PDF Documents, and that I must process them using iText, what could I do? Should I edit PdfName class to suit my special needs? Should PdfName class proceed with long names the same way those viewers do (ignoring, truncating or accepting them) instead of just throwing an Exception?

Thank you all in advance,

Filipe Fedalto

Cansado dos disparates e despautérios da República?
Quer um basta nas desventuras de nossos governantes?
Acesse http://www.monarquia.org.br e http://www.brasilimperial.org.br
e saiba mais a respeito.

Reply via email to