This is the code that I am using to insert the imagen in the PDF. This source 
code works fine in others PDFs, but not in this one. I do not understand.

public TC2 InsertaImagenTC2(PdfReader reader, String ruta, int paginas) {

        TC2 pdf = new TC2(); 
        int i = 0;
        PdfContentByte content = null;

        if (paginas <= 0) {
            System.out.println("Pagina 0 o menor");

            return pdf;
        }

        try {
            Image image = Image.getInstance("c:\\firma.jpg");
            image.scaleAbsolute(180, 100);
            image.setAbsolutePosition(360f, 20f);
            PdfStamper stamp = new PdfStamper(reader, new 
FileOutputStream(ruta.replace(".pdf", "temp.pdf")));
          

            for (i = 1; i <= paginas; i++) {

                content = stamp.getUnderContent(i);
                content.addImage(image);

            }
           
            stamp.close();

        } catch (Exception e) {
            e.printStackTrace();

        }
        pdf.setRuta(ruta.replace(".pdf", "temp.pdf"));
        pdf.setTotalpaginas(i);
        pdf.setDesde(1);
        pdf.setHasta(i);

        return pdf;
    }


I have tried to do a indirect reference, but I need a PdfObject. I do not know 
how to create a PdfObject without using the inheritance.

someOtherDict.put( PdfName.ANOTHER_KEY, myWriter.addToBody( myDict ) ); // 
put(PdfName key, PdfObject object) 

Regarding to the fail of the ContentStream, it is imposible to solve it because 
the generated PDF by Crystal Reports is a mess. I tried to fix it with 
PdfContentReaderTool, but it shows a lot of information that I do not 
understand.

If I could insert the imagen with the PDF generated by the PDF printer. I would 
solved the problem.

Thank you.

Date: Fri, 15 Oct 2010 09:39:42 -0700
From: msto...@autonomy.com
To: itext-questions@lists.sourceforge.net
Subject: Re: [iText-questions] Reading text from PDF










 
First of all, I tried to run Acrobat 9.4 pro's PDF Syntax Check on 
1.pdf:  It FAILED!  The error message stated that you had an illegal 
content stream.  I looked through the content stream and found the 
following:
 
1) Everything is in picas (1/20 of a point), so some of 
the coordinates are Quite Large... though none are so large that they should 
cause a problem (> 0xFFFF).  The original coordinate system crystal 
reports used was "y increases from bottom to top", whereas PDF uses "top to 
bottom".  None of this is all that unusal.
2) The fonts are all custom-encoded subsets without 
legal subset names.  "Arial+0" and "Arial-Bold+1" instead of the usual 
"FontName+<six UPPER CASE characters>" that is the Declared 
Standard way of doing things.  Again, not a huge deal, but not 
great.
3) One of the fonts is named "9".  I don't think 
that's a legal resource name... /9 is a perfectly valid PdfName... I don't see 
anything about restricting font names to "valid variable names" as you'd see in 
C-esque languages.  A bug in the PDF validator perhaps?  The PDF 
renders fine.
 
 
The first exception is a failure to read an array in a 
content stream.  That only happens within "kerned" text (google "kerning" 
if you'd like to know more).  Between the odd encoding and the kerning, it 
sounds like CrystalReports created an illegal content stream.  This may 
well be what's choking the Pdf Validator.
 
 
In the case of the second exception, you're adding 
something as a direct object when it should be added as a reference.  For 
Example:
 
PdfDictionary myDict = new 
PdfDictionary();
someOtherDict.put( PdfName.SOME_KEY, myDict ); // added 
directly
someOtherDict.put( PdfName.ANOTHER_KEY, 
myWriter.addToBody( myDict ) ); // added as a reference
 
Only PdfWriter.addToBody() returns a 
PdfIndirectReference, not a PRIndirectReference... Same concept, but your code 
will be different.  That's why we need to see it.  Could you 
please post your code to the list?

 
 
--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> 
DisCard = null;
 
 


  
  
  From: Modesto Aguirre Gomez 
  [mailto:modestoagui...@hotmail.com] 
Sent: Friday, October 15, 2010 
  12:46 AM
To: Mail list iText
Subject: Re: 
  [iText-questions] Reading text from PDF


  I tired to solve this problem for myself during a month but I could 
  not.

The PDF that I have the problem with is called 1.pdf. I hope that 
  you can solve it.

What I pretend is to read the text of the PDF or 
  directly remove the regionClip that i think is giving me the 
  problem.

This is the 
  error:

java.lang.NullPointerException
        
  at 
  com.itextpdf.text.pdf.PdfContentParser.readArray(PdfContentParser.java:148)
        
  at 
  com.itextpdf.text.pdf.PdfContentParser.readPRObject(PdfContentParser.java:173)
        
  at 
  com.itextpdf.text.pdf.PdfContentParser.parse(PdfContentParser.java:89)
        
  at 
  
com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:338)
        
  at 
  
com.itextpdf.text.pdf.parser.PdfReaderContentParser.processContent(PdfReaderContentParser.java:41)
        
  at 
  
com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage(PdfTextExtractor.java:73)
        
  at 
  
com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage(PdfTextExtractor.java:88)
        
  at mailpdf.Main.main(Main.java:41)

I tried skip the error before by 
  generating the PDF in a pdf print. This works but later i find a diferent 
  error. This error 

is caused when i try to close the file after 
  inserting a picture. "stamper.close();". The PDF that i have the problem with 
  is 

called 2.pdf

java.lang.ClassCastException: 
  com.itextpdf.text.pdf.PdfDictionary cannot be cast to 
  com.itextpdf.text.pdf.PRIndirectReference
        
  at 
  com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:209)
        
  at 
  com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:189)
        
  at 
  Util.EditorTC2.InsertaImagenTC2(EditorTC2.java:171)
        
  at 
  Util.EditorTC2.SeparaPorCIF(EditorTC2.java:74)
        
  at 
  Util.Ejecutar$ejecuta.<init>(Ejecutar.java:105)
        
  at 
  Util.Ejecutar$1.construct(Ejecutar.java:45)
        
  at 
  Util.SwingWorker$2.run(SwingWorker.java:60)
        
  at java.lang.Thread.run(Thread.java:619)

>From the beginning my 
  intention has been read the PDF and to insert it a picture that i 
  want.

Thank you.

> Date: Wed, 8 Sep 2010 17:26:22 
  -0700
> From: ke...@trumpetinc.com
> To: 
  itext-questions@lists.sourceforge.net
> Subject: Re: [iText-questions] 
  Reading text from PDF
> 
> 
> Another option would be to 
  use
> com.itextpdf.text.pdf.parser.PdfContentReaderTool to obtain the 
  content
> stream for the page that is causing problems. The tool should 
  actually fail
> with the null pointer exception, but you'll get the 
  content stream output
> before then.
> 
> Replace the text 
  extraction strategy (which is specified in line 181 of
> 
  PdfContentReaderTool) with your own TextExtractionStrategy implementation 
  (I
> would just print the text content to sysout for each call to 
  renderText() ). 
> The last text emitted before the NPE will be the 
  string to search on in the
> content stream to find the bad 
  array.
> 
> 
> -- 
> View this message in context: 
  
http://itext-general.2136553.n4.nabble.com/Reading-text-from-PDF-tp2528925p2532215.html
> 
  Sent from the iText - General mailing list archive at Nabble.com.
> 
  
> 
  ------------------------------------------------------------------------------
> 
  This SF.net Dev2Dev email is sponsored by:
> 
> Show off your 
  parallel programming skills.
> Enter the Intel(R) Threading Challenge 
  2010.
> http://p.sf.net/sfu/intel-thread-sfd
> 
  _______________________________________________
> iText-questions 
  mailing list
> iText-questions@lists.sourceforge.net
> 
  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/

  No virus found in this incoming message.
Checked 
  by AVG - www.avg.com
Version: 9.0.862 / Virus Database: 271.1.1/3196 - 
  Release Date: 10/14/10 11:34:00

  

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

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                                       
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

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