0

I am using AbcPdf and I am getting some difficute to use Alpha/Opacity style to be rendered in .AddImageHtml() method.

This need to be added as stylesheet because I am creating the pdf from my html.

Some images has opacity, but not all, so, I need to put opacity only to images that have opacity as stylesheet.

The AbcPdf version I am using is 8.1.1.5

SAMPLE CODE

 [HttpPost]
    [ValidateInput(false)]
    public virtual ActionResult GeneratePDF(string pdf)
    {
        Doc theDoc = new Doc();

        theDoc.AddImageHtml(pdf);
        theDoc.Rect.Inset(20, 20);
        string pathForSaving = Server.MapPath("~/Uploads");
        theDoc.Save(Path.Combine(pathForSaving, "htmlimport.pdf"));
        theDoc.Clear();

        return Json(new { }, "text/html");
    }

[UPDATED]

I still have the problem, but I am applying opacity in my image before upload. In other words, my image has been saved with opacity.

Despite applying the opacity, the rendered image don't have opacity. (I checked my Upload folder and the saved image has opacity)

What's happening here?

[/UPDATED]

Any help will be appreciated.

Thanks.

Hugo S. Mendes
  • 1,076
  • 11
  • 23

2 Answers2

0

There are many possible reasons for the behavior that you are seeing.

Option 1

The Css that is used in your page is not being passed to the AddImageHtml. Meaning the pdf variable does not have the Css. You can fix this by appending the Css to the html in a style tag. Example:

pdf += @"<style> your css code</style>";

Option 2

The version of IE on your server is IE8 and you are using Css Opacity property which is not supported by IE8. To fix this you can

a. use the Gecko engine by adding this line

doc.HtmlOptions.Engine = WebSupergoo.ABCpdf9.EngineType.Gecko;

b. upgrade IE on the server to IE9

c. change your Css to be IE8 compatible. check this thread Opacity CSS not working in IE8

Community
  • 1
  • 1
malkassem
  • 1,937
  • 1
  • 20
  • 39
0

This is not an answer, but to add to the question with an example that might be more easily verifiable. I get two gray boxes where the images should be. I am using ABCPdf 9.1.

Doc docPDF = new Doc();

docPDF.HtmlOptions.Engine = EngineType.Gecko;
docPDF.HtmlOptions.ForGecko.RequestMethod = UrlRequestMethodType.Get;
//docPDF.HtmlOptions.ForGecko.Media = MediaType.Screen;
docPDF.HtmlOptions.ForGecko.UseScript = true;
docPDF.HtmlOptions.ForGecko.OnLoadScript = 
    "window.ABCpdf_go = false; " + 
    "setTimeout(function() {window.ABCpdf_go = true;}, 5000);";

docPDF.AddImageUrl("http://www.w3schools.com/css/tryit.asp?filename=trycss_image_transparency");
docPDF.Save(@".\out.pdf");
elyuro
  • 91
  • 4
  • What does it OnLoadScript do? – Hugo S. Mendes Mar 20 '14 at 20:36
  • Provides a JavaScript code that you may want to execute before the Webpage is copied over to the PDF. In this case, it's just to wait for the page to be fully rendered. For more info see http://www.websupergoo.com/helppdfnet/source/5-abcpdf/xhtmloptions/2-properties/onloadscript.htm – elyuro Mar 20 '14 at 21:42