If I run multiple threads that attempt to create a PDF and add some text
with an embedded Type1 font, an EndOfStreamException exception is throw in
RandomAccessFileOrArray. Sample code:

static void Main(string[] args)
{
Font font = FontFactory.GetFont("c:\\windows\\fonts\\KozGoProVI-Medium.otf", 
BaseFont.IDENTITY_H,
    BaseFont.EMBEDDED, 36f, Font.NORMAL, new BaseColor(0f, 0f, 0f));

      List<Thread> threads = new List<Thread>();
      threads.Add(new Thread(() => { MyProc("file1.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file2.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file3.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file4.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file5.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file6.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file7.pdf", font); }));
      threads.Add(new Thread(() => { MyProc("file8.pdf", font); }));

      foreach(Thread t in threads)
            t.Start();

      int numRunning = threads.Count;
      while(numRunning > 0) {
            int num = threads.Count;
            foreach(Thread t in threads) {
                  if((t.ThreadState & System.Threading.ThreadState.Stopped) == 
System.Threading.ThreadState.Stopped)
                        num--;
            }
            numRunning = num;
      }
}

private static void MyProc(string fileName, Font font)
{
      System.IO.FileStream fs = new FileStream(fileName, FileMode.Create);
      Document document = new Document(PageSize.LETTER, 36, 36, 36, 36);
      PdfWriter writer = PdfWriter.GetInstance(document, fs);
      document.Open();
      document.Add(new Paragraph("Hello World!", font));
      document.Close();
      writer.Close();
      fs.Close();
}

If I do exactly the same thing, but use a non-Type1 font, e.g.,
Font font = FontFactory.GetFont("c:\\windows\\fonts\\ArialUni.ttf", 
BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
    36f, Font.NORMAL, new BaseColor(0f, 0f, 0f));
then everything is OK. Also OK if I use the Type1 font, but only run one thread.


- Eric de Beus
eric.deb...@xerox.com<mailto:eric.deb...@xerox.com>


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
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