Hello,

thank You answer. But after some tests I guess, that this is not caused by 
missing metadata. Even if there are no metadata in "source.fo", I can use iText 
to print to stdout total number of pages. So it means, that iText can read 
"source.pdf" without throwing any exception. See attached "source.fo" 
(commented metadata), "source.pdf" (commented creation of output) and Java code 
for iText, which passes without problem.

Once I want to create output file and save it without any modification (to 
prevent mistake in font encoding setting), there is an Exception:

ExceptionConverter: 
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 
Invalid byte 1 of 1-byte UTF-8 sequence.

Stepan Rybar

> ------------ Původní zpráva ------------
> Od: Paulo Soares <[EMAIL PROTECTED]>
> Předmět: Re: [iText-questions] iText 2.1.3: Invalid byte 1 of 1-byte UTF-8
> sequence Exception while processing PDF from Apache FOP 0.95
> Datum: 04.11.2008 17:23:03
> ----------------------------------------
> The metadata generated by FOP is broken. They have:
>
> <x:xmpmeta>
>
> instead of:
>
> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-702">
>
> The namespace is not defined and the parser complains about it.
>
> Paulo
> ________________________________________
> From: Stepan RYBAR [EMAIL PROTECTED]
> Sent: Tuesday, November 04, 2008 4:11 PM
> To: [email protected]
> Subject: [iText-questions] iText 2.1.3: Invalid byte 1 of 1-byte UTF-8  
> sequence
> Exception while processing PDF from Apache FOP 0.95
>
> Hello,
>
> I am trying to use iText for adding page numbers to the already existed PDF
> using PDFStamper class. I have problem. PDFs, which I create using Apache FOP
> 0.95, cause Exception as shown below, although they look OK in Adobe Acrobat
> Reader 8.1.2. I guess, that this is problem of missing or wrong encoding
> somewhere (but where?). Attached to this e-mail are: FO source, resulted PDF,
> Java code for iText. I am using Sun Java SE 1.6.0_10 on MS Windows 2000. 
> Please,
> can You point me, where I am making miskate?
>
> Thank You. Stepan
>
> L:\Documents\Capitol\vypisyKv1\_other>L:\RunFiles\jdk\jre\bin\java -cp
> ".;iText-
> 2.1.3.jar" AddPageNumbersToExistingPageNumberPDF
> ExceptionConverter:
> com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequ
> enceException: Invalid byte 1 of 1-byte UTF-8 sequence.
>         at
> com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unk
> nown Source)
>         at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown
> So
> urce)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown
>  Source)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapac
> ity(Unknown Source)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(U
> nknown Source)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineD
> ocVersion(Unknown Source)
>         at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
> nknown Source)
>         at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
> nknown Source)
>         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
> So
> urce)
>         at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown
> So
> urce)
>         at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unk
> nown Source)
>         at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
>         at com.lowagie.text.xml.xmp.XmpReader.<init>(Unknown Source)
>         at com.lowagie.text.pdf.PdfStamperImp.close(Unknown Source)
>         at com.lowagie.text.pdf.PdfStamper.close(Unknown Source)
>         at
> AddPageNumbersToExistingPageNumberPDF.main(AddPageNumbersToExistingPa
> geNumberPDF.java:30)
>
> Aviso Legal:

> Esta mensagem ? destinada exclusivamente ao destinat?rio. Pode conter 
> informa??o
> confidencial ou legalmente protegida. A incorrecta transmiss?o desta mensagem
> n?o significa a perca de confidencialidade. Se esta mensagem for recebida por
> engano, por favor envie-a de volta para o remetente e apague-a do seu sistema 
> de
> imediato. ? proibido a qualquer pessoa que n?o o destinat?rio de usar, revelar
> ou distribuir qualquer parte desta mensagem.

>

> Disclaimer:

> This message is destined exclusively to the intended receiver. It may contain
> confidential or legally protected information. The incorrect transmission of
> this message does not mean the loss of its confidentiality. If this message is
> received by mistake, please send it back to the sender and delete it from your
> system immediately. It is forbidden to any person who is not the intended
> receiver to use, distribute or copy any part of this message.

>
>
>
>
> 
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
  <fo:layout-master-set>
    <fo:simple-page-master master-name="A4-portrait" page-height="29.7cm" page-width="21.0cm" margin="2cm">
      <fo:region-body margin="2cm" />
    </fo:simple-page-master>
  </fo:layout-master-set>
  <!--
  <fo:declarations>
    <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="3.1-702">
      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";>
        <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/";>
          <dc:title>Document title</dc:title>
          <dc:creator>Document author</dc:creator>
          <dc:description>Document subject</dc:description>
        </rdf:Description>
        <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/";>
          <xmp:CreatorTool>Tool used to make the PDF</xmp:CreatorTool>
        </rdf:Description>
      </rdf:RDF>
    </x:xmpmeta>
    </fo:declarations>
  -->
  <fo:page-sequence master-reference="A4-portrait" initial-page-number="1" force-page-count="no-force">
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-family="Arial Narrow">příliš žluťoučký kůň úpěl ďábelské ódy</fo:block>
      <fo:block font-family="Arial Narrow">PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ ÚPĚL ĎÁBELSKÉ ÓDY</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

Attachment: source.pdf
Description: Adobe PDF document

import java.io.FileOutputStream;

import com.lowagie.text.Element;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class AddPageNumbersToExistingPageNumberPDF {
  public static void main(String[] args) {
    try {
      PdfReader reader = new PdfReader("source.pdf");
      int n = reader.getNumberOfPages();
      System.out.println("Total number of pages is \"" + n + "\".");
      /*
      //this throws Exception with message 
      PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("result.pdf"));
      stamp.close();
      */
    } catch (Exception de) {
      de.printStackTrace();
    }
  }
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to