iTextSharp的找不到PDF [英] ItextSharp can't find PDF

查看:747
本文介绍了iTextSharp的找不到PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iTextSharp的5.4.5在.NET 3.5的应用程序。当从一个文件路径创建PdfReader对象我越来越找不到文件异常,但该文件存在。我已经证实File.Open能够打开该文件。测试code:

I am using itextsharp 5.4.5 in a .net 3.5 app. When creating a PdfReader object from a file path I am getting a file not found exception but the file exists. I have confirmed that File.Open is able to open the file. Test code:

try
{
    FileStream f = File.Open(Server.MapPath("~/App_Data/pdf/EC_1.0.pdf"), FileMode.Open);
    f.Close();
    f.Dispose();

    PdfReader pdfReader = new PdfReader(Server.MapPath("~/App_Data/pdf/EC_1.0.pdf"));
    pdfReader.Close();
    pdfReader.Dispose();

    Response.Write("Succeed");
}
catch (IOException cex)
{
    Response.Write("Fail: <br /><br /><b>Message:</b> " + cex.Message.Replace("<", "&lt;").Replace(">", "&gt;") +
        "<br /><br /><b>Exception .ToString:</b> " + cex.ToString().Replace("<", "&lt;").Replace(">", "&gt;") +
        "<br /><br /><b>Source:</b> " + cex.Source +
        "<br /><br /><b>StackTrace:</b> " + cex.StackTrace +
        "<br /><br /><b>TargetSite:</b> " + cex.TargetSite);
}
catch (Exception cex)
{
    Response.Write("Fail: <br /><br /><b>Message:</b> " + cex.Message.Replace("<", "&lt;").Replace(">", "&gt;") +
        "<br /><br /><b>Exception .ToString:</b> " + cex.ToString().Replace("<", "&lt;").Replace(">", "&gt;") +
        "<br /><br /><b>Source:</b> " + cex.Source +
        "<br /><br /><b>StackTrace:</b> " + cex.StackTrace +
        "<br /><br /><b>TargetSite:</b> " + cex.TargetSite);
}

异常详细信息:

Message: C:\inetpub\wwwroot\HepBnet\research\DataSystem\App_Data\pdf\EC_1.0.pdf not found as file or resource.

Exception .ToString: System.IO.IOException: C:\inetpub\wwwroot\HepBnet\research\DataSystem\App_Data\pdf\EC_1.0.pdf not found as file or resource. at iTextSharp.text.io.RandomAccessSourceFactory.CreateByReadingToMemory(String filename) at iTextSharp.text.io.RandomAccessSourceFactory.CreateBestSource(String filename) at iTextSharp.text.pdf.PdfReader..ctor(String filename, Byte[] ownerPassword, Boolean partial) at iTextSharp.text.pdf.PdfReader..ctor(String filename) at ASP.errors_pdf_test_aspx.Page_Load()

Source: itextsharp

StackTrace: at iTextSharp.text.io.RandomAccessSourceFactory.CreateByReadingToMemory(String filename) at iTextSharp.text.io.RandomAccessSourceFactory.CreateBestSource(String filename) at iTextSharp.text.pdf.PdfReader..ctor(String filename, Byte[] ownerPassword, Boolean partial) at iTextSharp.text.pdf.PdfReader..ctor(String filename) at ASP.errors_pdf_test_aspx.Page_Load()

TargetSite: iTextSharp.text.io.IRandomAccessSource CreateByReadingToMemory(System.String)

我假定这是一个权限问题,但不应被的iText使用相同的用户作为.NET应用程序?

I'm assuming this a permission issue but shouldn't itext be using the same user as the .net app?

推荐答案

我想出什么问题了。出于某种原因,Web服务器是'堵'的iText库。右键单击库访问属性,然后单击阻止,然后迫使应用程序启动固定的问题。

I figured out what the issue was. For some reason the webserver was 'blocking' the itext library. Right clicking the library to access the properties and clicking 'Unblock' then forcing an app restart fixed the issue.

我希望这可以帮助别人...

I hope this helps someone else...

这篇关于iTextSharp的找不到PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆