Click here to Skip to main content
15,924,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert html to pdf in mvc . for this i am use Abcpdf converter .i am use following code but its gives error ""Unable
to render HTML. Unable to load page. (HTTP 403)." .

Every time we i run this following line gives error and brake
execution " theID = theDoc.AddImageUrl("http://www.yahoo.com/");"
please help me,

What I have tried:

Doc theDoc = new Doc();
        theDoc.Rect.Inset(72, 144);
    
        theDoc.HtmlOptions.Engine = EngineType.MSHtml;
        theDoc.HtmlOptions.UseScript = true;
        theDoc.HtmlOptions.Media = MediaType.Print; 
        
        theDoc.HtmlOptions.InitialWidth = 800; 
        	theDoc.Page = theDoc.AddPage();
        int theID;
        theID = theDoc.AddImageUrl("http://www.yahoo.com/");
        while (true) {
          theDoc.FrameRect(); // add a black border
          if (!theDoc.Chainable(theID))
            break;
          theDoc.Page = theDoc.AddPage();
          theID = theDoc.AddImageToChain(theID);
        }
        for (int i = 1; i <= theDoc.PageCount; i++) {
          theDoc.PageNumber = i;
          theDoc.Flatten();
        }

        theDoc.Save(Server.MapPath("pagedhtml.pdf"));
        theDoc.Clear();
Posted
Updated 4-Dec-17 1:26am
v3

1 solution

See HTTP 403 - Wikipedia[^].

AbcPdf is not a web browser. It might not work as such regarding redirections which are used by the Yahoo URL from your example. If you type that URL in your browser, you will notice that there is a redirection (in my case to "https://de.yahoo.com/?p=us").

You can try to use that HTTPS URL (or those used with your browser). If that works depends on AbcPdf supporting secure connections.

You can also try to use the URL without trailing slash ("http://www.yahoo.com") because that requests a directory listing which is usually forbidden (see the third paragraph of the Wikipedia link).

Because it looks like you used the Yahoo URL for testing, I suggest to use another URL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900