3

I can't seem to figure out this error message while upgrading to the newest version of ABCPDF, 10.0.1.0. Does the error message give any clues? It happens in spurts and restarting the app pool is the only way to fix it right away.

WebSupergoo.ABCpdf10.Internal.PDFException: Failed to add HTML: Gecko engine failed to initialize. Possible causes: XULRunner folder not found or failure to create temporary browser profile directory.
   at WebSupergoo.ABCpdf9.Doc.AddUrlHtml(String urlOrHtml, Boolean isHtml, Boolean paged, Int32 width, Boolean disableCache)
   at WebSupergoo.ABCpdf9.Doc.AddImageUrl(String url, Boolean paged, Int32 width, Boolean disableCache)
   at WebSupergoo.ABCpdf9.Doc.AddImageUrl(String url)

My process log shows this type of entry.

"1:46:21.9863465 PM","ABCGeckoWP.exe","4052","CreateFile","C:\Windows\Temp\ABCpdf\ABCGecko\wq3tvwof.2uc","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"1:46:21.9865561 PM","ABCGeckoWP.exe","4052","CreateFile","C:\Windows\Temp\ABCpdf\ABCGecko\wq3tvwof.2uc","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
2
  • 2
    I have the exact same problem with no solution as of yet. Jun 5, 2015 at 10:57
  • We had the exact same problem. We ended up having to roll back to v9, which is disappointing. We went to v10 in hopes of dealing with other issues. Namely, our PDF documents were being artificially truncated. We've used ABCpdf for years, but these issues are probably going to force us to find another solution.
    – campbelt
    Jun 25, 2015 at 19:33

4 Answers 4

2

Seems that the fix tempPdf.HtmlOptions.EndTasks(WebSupergoo.ABCpdf10.TaskState.AllWhenBecomeIdle); isn't really a fix and even causes some performance hit. I went ahead and removed the try/catch with it and reverted back to an older version of ABC PDF until this is resolved. This version probably shouldn't have been released and they knew about this issue also before the release of it.

1
  • We also had this issue, and had to do the same.
    – campbelt
    Jun 25, 2015 at 19:34
0
+50

I had the same issue and using the below configuration helped me to solve the problem.

First I downloaded and installed from the website.

Add this to configSections in your Web.config (or App.Config):

<section name="ABCpdf10.Section" type="WebSupergoo.ABCpdf10.ConfigSection, ABCpdf" allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToLocalUser" overrideModeDefault="Allow" restartOnExternalChanges="true" requirePermission="true" />

Then add this to your Web.config (or App.Config):

<ABCpdf10.Section>
    <Preferences>
        <clear />
        <add Key="XULRunnerDirectory" Value="C:\Program Files\WebSupergoo\ABCpdf .NET 10.1 x64\ABCGecko" />
    </Preferences>
</ABCpdf10.Section>

The folder might change depending on what version you have installed (32 bits or 64 bits).

I also removed every ABCPdf related dlls (ABCpdf10-32.dll, ABCpdf10-64.dll, ABCGeckoWP.exe, etc) from bin folder except ABCPdf.dll. (Make sure you remove the copy to output directory property if you installed via nuget)

Not sure if helps, but might worth a try.

Edit

The above did not solve the issue for me too, but I noticed the errors start usually after I deploy new code. Then after an iisreset it goes back to normal.

I did some more digging in the manual and there is one more thing you could try (I will :)). The manual shows many settings you could override, and there are two that I believe are related do the error: TempDirectory and ClearoutSize

For the first one I created a temp folder and added the following setting:

<add Key="TempDirectory" Value="D:\ABCPdf\Temp" />

For the second one, I believe there is nothing to do but the manual says the following: On startup, the ABCpdf temp directory is checked. If it appears that there are a large number of unused items, then the directory will be cleared.

So maybe something could be going wrong during this process (by locking the folder for example), specially if multiple processes are doing the same. You could setup a different temp dir for each app and see how it goes.

10
  • If I did the manual install (all of the files of ABCPDF and XULRunner are in the BIN-folder), would I include the path to the XULRunner folder in the web.config or to some other folder? Jun 9, 2015 at 12:40
  • Never mind my last comment, I figured it out. It's supposed to be a link to my bin folder in my case, not to my xulrunner folder. Then this seems to work. I'm just going to wait a few hours to make sure the problem is completely gone, before I award the bounty, but at first sight, this does seem to work correctly. Jun 9, 2015 at 13:16
  • Unfortunately, this didn't solve the problem in the end. Still gave you the bounty though, seeing as your answer was technically correct. Will post an answer if I ever find one. Jun 9, 2015 at 20:23
  • @StevenLemmens I'm still not getting the error, but will monitor and let you know if I find anything else. Have you tried using version 10.0.0.0?
    – gsimoes
    Jun 9, 2015 at 22:47
  • 2
    I went and reverted back to an older version and told support about it. They will need to do more testing on their version before I upgrade again.
    – Mike Flynn
    Jun 10, 2015 at 13:49
0

With help from the ABC PDF support, I was able to implement the following work-around.

Apparently, when you use AddImageHtml, a background process is started that will convert the HTML to a PDF for you. It is this process that seems to hang at some point, at which you'll start to receive this error. ABC PDF 10 offers a method of killing this process if it's sitting idle (which is the case here).

//before you start creating your PDF, be sure to kill any remaining processes 
using (var tempPdf = new WebSupergoo.ABCpdf10.Doc()) { 
      tempPdf.HtmlOptions.Engine = WebSupergoo.ABCpdf10.EngineType.Gecko;
      tempPdf.HtmlOptions.EndTasks(WebSupergoo.ABCpdf10.TaskState.AllWhenBecomeIdle);
}

This code simply creates a doc, sets the engine type to Gecko and then calls EndTasks with the parameter "AllWhenBecomeIdle". This will kill all remaining background worker processes that aren't doing anything right now.

After that, it's business as usual, you can create your PDF, convert your HTML, ...

And in the end (AFTER you've saved your PDF or streamed it to a browser (or after you've disposed of the Doc variable), I do the same thing again: kill any remaining background processes. So far, this seems to work in our production environment. I hope it stays that way until ABC PDF can come up with a more definitive solution.

I wrapped my reset code in a static function so I can call it anywhere. Here's the code:

public static class AbcPdfUtils {
    public static void ResetAbcPdfGeckoProcess()
    {
        using (var tempPdf = new WebSupergoo.ABCpdf10.Doc()) { 
            tempPdf.HtmlOptions.Engine = WebSupergoo.ABCpdf10.EngineType.Gecko;
            tempPdf.HtmlOptions.EndTasks(WebSupergoo.ABCpdf10.TaskState.AllWhenBecomeIdle);
        }
    }
}

EDIT 2

The stopping and restarting of the Gecko process does incur a bit of a performance hit it seems, so this is not an ideal solution. I've contacted their support team about it and they say they plan to release a new version without this problem, but no idea when that will be. They also advise to only use the EndTasks function when we catch the exception that is being thrown here. For my site that incurs quite a rewrite, so I won't be going down this route.

1
  • Support also told me this after I sent them this post.
    – Mike Flynn
    Jun 11, 2015 at 13:33
-1

Building on Steven Lemmens' answer:

using (var abcpdf = new Doc())
{
    abcpdf.HtmlOptions.PageCacheClear();
    abcpdf.HtmlOptions.HideBackground = true;

    abcpdf.HtmlOptions.Engine = EngineType.Gecko;
    abcpdf.HtmlOptions.UseScript = true;
    abcpdf.HtmlOptions.Timeout = 10000;
    abcpdf.HtmlOptions.OnLoadScript = "(function(){window.ABCpdf_go = false; setTimeout(function(){window.ABCpdf_go = true;},3000);})();";

    var printContentUrl = "url for content";

    try
    {
        abcpdf.Rect.Width = 612 - 14 - 14;      //612 - 54 - 54; // whole width minus left and right
        abcpdf.Rect.Height = 792 - 46 - 46;     //792 - 54 - 54; // whole height minus top and bottom
        abcpdf.Rect.Position(14, 46);          // 54, 54 centered

        // Generate pdf from Url
        var id = abcpdf.AddImageUrl(printContentUrl);

        while (abcpdf.GetInfo(id, "Truncated") == "1")
        {
            abcpdf.Page = abcpdf.AddPage();
            id = abcpdf.AddImageToChain(id);
        }

        // Add footer with page number.
        abcpdf.Font = abcpdf.AddFont("Helvetica-Oblique");
        for (var i = 1; i <= abcpdf.PageCount; ++i)
        {
            abcpdf.PageNumber = i;
            abcpdf.Rect.Height = 54;
            abcpdf.Rect.Position(54, 0);
            abcpdf.HPos = 0.9; // align to the right
            abcpdf.VPos = 0.25; // above center
            abcpdf.AddText(string.Format("Page {0} of {1}", i, abcpdf.PageCount));
        }

        var docData = abcpdf.GetData();
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "inline; filename=DynamicPdf.pdf");
        Response.BinaryWrite(docData);
    }
    catch(WebSupergoo.ABCpdf10.Internal.PDFException pdfEx)
    {
        //Log Exception here....
        ResetAbcPdfGeckoProcess();
        Response.Redirect(Request.RawUrl);
    }
    catch (Exception ex)
    {
        //Log Exception here....
        throw ex;
    }
}

public static void ResetAbcPdfGeckoProcess()
{
    using (var tempPdf = new WebSupergoo.ABCpdf10.Doc()) { 
        tempPdf.HtmlOptions.Engine = WebSupergoo.ABCpdf10.EngineType.Gecko;
        tempPdf.HtmlOptions.EndTasks(WebSupergoo.ABCpdf10.TaskState.AllWhenBecomeIdle);
    }
}

This code works well for me. Note that this code is part of the Page_Load() method of an asp.net page. The overhead of calling ResetAbcPdfGeckoProcess() method is only incurred if the first attempt to generate the pdf fails. If the PDFException is raised, I do a Response.Redirect(Request.RawUrl); to make the Page_Load fire again after the Gecko process is started and stopped. On the second iteration of the Page_Load, the PDF is rendered correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.