When I run the code below I get an IOException - Header signature not found. 
The reason I'm using that seperate thread is because I'm not using the
FileOutputStream in my actual app.  I'm using the Piped In/Out Streams (the
commented lines).  What I'm trying to do is to add some things to an existing
pdf and then use PdfBox to convert the resultant pdf to an image.  Now, when I
run the below code using the Piped Streams I don't get an error.  When I try to
read in the pdf with PdfBox using the FileStream method I get that same error. 
When I try to read in the pdf with PdfBox using the PipedStream method it works
but the text I have added displays as black.  I realize that this could be a
problem with the PdfBox library which, of course, has nothing to do with iText
but I thought I would post this here just in case there was some glaring error
that I'm overlooking.  Any help is much appreciated, I've been stumped on this
for days.

-007

public class test {
  PdfReader reader = null;
  public static void main(String[] args) throws IOException{
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new test();
      }
    });
  }

  public test() {
    try {
      reader = new PdfReader("PathToPdf");
    }
    catch (IOException iox) {
      iox.printStackTrace();
    }

    try {
//      PipedInputStream inStream = new PipedInputStream();
//      PipedOutputStream outStream = new PipedOutputStream(inStream);
      FileOutputStream fileStream = new FileOutputStream("PathToNewPdf");

//      final PdfStamper stamper = new PdfStamper(reader, outStream);
      final PdfStamper stamper = new PdfStamper(reader, fileStream);

      new Thread() {
        public void run() {
          PdfContentByte cb = stamper.getOverContent(1);

          ColumnText textCol = new ColumnText(cb);
          textCol.setSimpleColumn( 10, 10, 100, 100 );

          Font font = null;
          try {
            font = new Font(BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.EMBEDDED), 12, Font.NORMAL, Color.RED);
          }
          catch (Exception e) {}
          Phrase phrase = new Phrase(12, "test", font);
          textCol.addText(phrase);

          try {
            textCol.go();
          }
          catch (Exception e) {
            e.printStackTrace();
          }


          try {
            stamper.close();
          }
          catch (Exception x) {
            x.printStackTrace();
          }
        }
      }.start();

      PdfReader reader2 = new PdfReader("PathToNewPdf");
//      PdfReader reader2 = new PdfReader(inStream);
    }
    catch (Exception x) {
      x.printStackTrace();
    }
  }
}


_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to