Search code examples
c#htmlcssasp.netabcpdf

How I can generate the pdf using AddImageUrl from ABCpdf after the page is loaded complete


I want to add the thumbnail of a web page to pdf document,

I added like this:

    Doc generatedoc = new Doc();
    generatedoc.HtmlOptions.UseScript = true;

    string urlToHtmlPage = "http://example.com?param1=30&param2=true";
    int generatedId = generatedoc.AddImageUrl(urlToHtmlPage);

    generatedoc.Save(HttpContext.Current.Server.MapPath("htmlimport.pdf"));
    generatedoc.Clear();

In url I send two parameters, depending on a parameter in page is added a class for various html tags, for example:

<div class="cssClass <%=param2==true?"secondCssClass":""%>">some html tags</div>

or

<span class="<%= param2==true?"secondCssClass":"" %>"> some text </span>

Inside the style

<style type="text/css">
    .secondCssClass
    {
        display: none;
    }
</style>

pdf is generated ok but secondCssClass is not added to my tags and css is not applying I try to set big time out but also css is not applying

I set time out like this:

generatedoc.HtmlOptions.Timeout = 1000000;

or

generatedoc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false;
            setTimeout(function(){ window.ABCpdf_go = true; }, 1000000); })();";

or RenderWait() and RenderComplete()

   generatedoc.HtmlOptions.OnLoadScript = @"
    window.external.ABCpdf_RenderWait(); 
    window.external.ABCpdf_RenderComplete(true);";

but anyway CSS did not apply when I load url in browser css is applying some proposals?


Solution

  • Based on your response to the comment that you see the issue even in the browser tells that this is not an ABCPDF issue.

    I think the problem lies in the following:

    <div class="cssClass <%=param2==true?"secondCssClass":""%>">some html tags</div>
    

    AND

    <span class="<%= param2==true?"secondCssClass":"" %>"> some text </span>
    

    If that code is exactly what you have in your running code, then you will need to make an adjustment those lines:

    1. Accessing URL parameters, you need to use the Request object
    2. URL parameters are text, and your comparison has them as boolean

    Code should be as follows:

    <div class="cssClass <%= Request.QueryString("param2")=="true"?"secondCssClass":"" %>">some html tags</div>
    

    AND

    <span class="<%= Request.QueryString("param2")=="true"?"secondCssClass":"" %>"> some text </span>
    

    I recommend that you test this in the browser prior to testing it via ABCPDF.