开发者

Itext, access denied on htmlworker.parseToList

开发者 https://www.devze.com 2023-03-13 22:24 出处:网络
I have spent far too long trying to work out why I am getting an access denied here so I am really hopingsomeone can help?

I have spent far too long trying to work out why I am getting an access denied here so I am really hoping someone can help? I am using itextsharp, the latest version downloaded today.

I am parsing an html page within my own project so I can convert it to pdf, but everytime I run it I get an access denied on path c:\

For starters I cannot work out why it's trying to access the c drive other than the website directory which it definitely has access to.

And I have tried adding network service with full permission to everything but it didn't work.

I even impersonated an admin user in the web config but I still got access denied.

My code is:

  string download = new WebClient().DownloadString("http://" + HttpContext.Current.Request.Url.Host + "/pagetoparse.aspx?user=" + userName);

        string tempFolder = HttpContext.Current.Server.MapPath("pdfs");
        if (!Directory.Exists(tempFolder))
        {
            Directory.CreateDirectory(tempFolder);
        }
        string fileName = Path.Combine(tempFolder, "test3.pdf");
        Document document = new Document(PageSize.A4, 80, 50, 30, 65);
        try
        {
                PdfWriter writer = Pdf开发者_运维问答Writer.GetInstance(document, new FileStream(fileName, FileMode.Create));

                using (StringReader stringReader = new StringReader(download))
                {
                    List<IElement> parsedList = HTMLWorker.ParseToList(stringReader, null);//<-- fails here!
                    document.Open();
                    foreach (object item in parsedList)
                    {
                        document.Add((IElement)item);
                    }
                    document.Close();
                }


        }
        catch (Exception exc)
        {
            Console.Error.WriteLine(exc.Message);
        }

        return document;

It must be obvious, what I am doing wrong??

Bex


Arrrgh! And the answer is:

An empty image tag! It tried to parse it as a path!!

0

精彩评论

暂无评论...
验证码 换一张
取 消