Menu

iText tries to create a directory at Runtime

jenart90
2006-08-11
2013-05-01
  • jenart90

    jenart90 - 2006-08-11

    I have inherited a codebase that was originally build with iTextdoNET.dll v1.1. It was deployed into production and is running on Windows 2003 Server, ASP.NET, .Net Framework v1.1. It is still running fine today (12 months later) and able to generate PDF files for reports that our app produces. It is a rich client using .Net web services.

    I have been tasked with updating it with the latest version - it also runs as an installable intranet application. So I built the latest build of the software - this is installed in over 700 customer sites. However when I deployed the latest build to the production server and tried to generate one of our PDF reports I got the following error message:

    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.WebService.Service1 [] - About to call generateIGReport()
    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.WebService.Service1 [] - DIRPATH [D:\webspace\careervoyage.com.au\www\WebService\Reports\]
    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.WebService.Service1 [] - DIRPATHWEB []
    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Start GenerateIGReport()
    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Created new iText PDF Doc Object
    2006-08-07 03:58:58,484 [main] DEBUG JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Report file path - DIRPATH [D:\webspace\careervoyage.com.au\www\WebService\Reports\445joey090002000018IGReport.pdf]
    2006-08-07 03:58:58,578 [main] DEBUG JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Report file path - DIRPATHWEB [445joey090002000018IGReport.pdf]
    2006-08-07 03:58:58,578 [main] ERROR JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Could not find a part of the path "E:\".
    Exception: System.IO.DirectoryNotFoundException
    Message: Could not find a part of the path "E:\".
    Source: mscorlib
       at System.IO.__Error.WinIOError(Int32 errorCode, String str)
       at System.IO.Directory.InternalCreateDirectory(String fullPath, String path)
       at System.IO.Directory.CreateDirectory(String path)
       at java.lang.ResourceEnum.getResourceURL(Assembly assembly)
       at java.lang.ResourceEnum.getResourceURL(Assembly assembly, Int32 tryDoneRank)
       at java.lang.ResourceEnum.readNext()
       at java.lang.ResourceEnum..ctor(Assembly entryAssembly, Assembly callingAssembly, Assembly assembly, String name)
       at java.lang.JSharpStuff.GetResource(Assembly assembly, String path)
       at java.lang.JSharpStuff.GetResource(Class clazz, String name)
       at java.lang.JSharpStuff.GetResourceAsStream(Class clazz, String name)
       at com.lowagie.text.pdf.BaseFont.getResourceStream(String key, ClassLoader loader)
       at com.lowagie.text.pdf.Type1Font..ctor(String afmFile, String enc, Boolean emb, SByte[] ttfAfm, SByte[] pfb)
       at com.lowagie.text.pdf.BaseFont.createFont(String name, String encoding, Boolean embedded, Boolean cached, SByte[] ttfAfm, SByte[] pfb)
       at com.lowagie.text.pdf.BaseFont.createFont(String name, String encoding, Boolean embedded)
       at JIIGCAL.CareerVoyage.ReportBrain.MyCliPageEvents.onOpenDocument(PdfWriter writer, Document document)
       at com.lowagie.text.pdf.PdfDocument.initPage()
       at com.lowagie.text.pdf.PdfDocument.open()
       at com.lowagie.text.Document.open()
       at JIIGCAL.CareerVoyage.ReportBrain.ReportClass.generateIGReport(String username, String str, String mode, String loeDesc, String igdesc, String DIRPATH, String DIRPATHWEB)

    The main error "Could not find a part of the path "E:\"." is what puzzles me the most. Our production machine is a co-hosted server. It is locked down very tightly permission wise. Our app is configured so that it's webroot is on the D:\ drive. As the logging shows, the app is trying to create the report in the correct location:

    D:\webspace\careervoyage.com.au\www\WebService\Reports\445joey090002000018IGReport.pdf

    After much head scratching I've discovered that some time ago, the intranet version of the software had been updated to use v1.4 of iTextdotNET.dll. This also meant that a new dependancy on Gnu.Classpath.Core.dll was introduced instead of the old JSharpLib.dll dependency with v1.1 of iTextdotNET.dll.

    I've downloaded the oldest source I can find (v1.4 for the .net framework v1.1) and tried to look at why there would be an attempt by the Font loading code to create a directory and write to it.. and in particular on a drive (E:\) that is not even available to the application runtime environment. I have an E:\ drive on my dev machine, but it is a CD-ROM. But despite this, I've never had an issue running the app build with v1.4 of iText on my dev machine, on our test machines, or in any of our customer sites. It's only now that I've deployed it to the heavily locked down co-hosted website that an issue has arisen.

    I've tried to roll back the iText version to v1.1 - this compiles happily if I also include JSharpLib.dll again, but at runtime I get the error message:

    2006-08-10 17:46:39,681 [5092] ERROR JIIGCAL.CareerVoyage.ReportBrain.MyCliPageEvents [] - Helvetica not found as resource. (The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
    Exception: com.lowagie.text.DocumentException
    Message: Helvetica not found as resource. (The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
    Source: iTextdotNET
       at com.lowagie.text.pdf.Type1Font..ctor(String afmFile, String enc, Boolean emb, SByte[] ttfAfm, SByte[] pfb)
       at com.lowagie.text.pdf.BaseFont.createFont(String name, String encoding, Boolean embedded, Boolean cached, SByte[] ttfAfm, SByte[] pfb)
       at com.lowagie.text.pdf.BaseFont.createFont(String name, String encoding, Boolean embedded)
       at JIIGCAL.CareerVoyage.ReportBrain.MyCliPageEvents.onOpenDocument(PdfWriter writer, Document document)

    2006-08-10 17:46:39,696 [5092] DEBUG JIIGCAL.CareerVoyage.Brain.CVUtils [] - Product Version [2006]
    2006-08-10 17:46:39,899 [5092] DEBUG JIIGCAL.CareerVoyage.Brain.CVUtils [] - Product Version [2006]
    2006-08-10 17:46:39,993 [5092] ERROR JIIGCAL.CareerVoyage.ReportBrain.ReportClass [] - Exception of type 'com.lowagie.text.DocumentException' was thrown.
    Exception: com.lowagie.text.DocumentException
    Message: Exception of type 'com.lowagie.text.DocumentException' was thrown.
    Source: iTextdotNET
       at com.lowagie.text.pdf.PdfDocument.add(Element element)
       at com.lowagie.text.Document.add(Element element)
       at JIIGCAL.CareerVoyage.ReportBrain.ReportClass.writeCoverPage(Document document, String name, String group, String recNo, String stage, String orgName, String date, String cat, String loe, String title)
       at JIIGCAL.CareerVoyage.ReportBrain.ReportClass.generateIGReport(String username, String str, String mode, String loeDesc, String igdesc, String DIRPATH, String DIRPATHWEB)

    The code that these problems are initiated from is as follows:

    public override void onOpenDocument(PdfWriter writer, Document document)
    {
        try
        {
            bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb = writer.getDirectContent();
            template = cb.createTemplate(50, 50);
        }
        catch(DocumentException de)
        {
            log.Error( de.Message, de );
        }
        catch(Exception e)
        {
            log.Error( e.Message, e );
        }
    }

    Can anyone suggest how I can stop the assembly resource loading code trying to create this directory? Are other people coming across these issues at all in a runtime environment where the expected directories and/or drives are not available like would be found on a standard server machine? I'm open to any suggestions. At this point I'm between a rock and hard place. The hosting provider wont' b echanging anything for me, and I need to push up the new build because it has new features, but we can't because of these issues.

    Thanks in advance.

    Stu

     
    • Kazuya Ujihara

      Kazuya Ujihara - 2006-08-11

      iTextdotNET creates some directories and files in a temp folder. The location of the temp folder is decided from System.IO.GetTempPath() static method. In Microsoft's implementation, it refers a TEMP envirnment variable.
      Check envirnment variables on Windows 2003 server and the TEMP envirnment variable is valid for a temporary directory, which means ASP.NET needs a read/write/delete privilege.

       
    • jenart90

      jenart90 - 2006-08-12

      Thanks for the reponse. Great stuff. I've written a little test app and run it on my hosted server, and it's shown that they indeed have blocked the ASP.NET process permission to create directories under the system TEMP folder. And their TEMP folder is configured to be the E:\ drive. I can successfully create and delete files in this location but not folders. I've now asked them to rectify this.

      Once again, thanks heaps for your help.

      Stu

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.