Abcpdf and XULRunner error or temp profile directory error

I can't seem to figure out this error message when upgrading to the latest ABCPDF, 10.0.1.0. Does the error message indicate any clues? This happens in pins and restarting the application 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 has this entry type listed.

"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"

      

+3


source to share


4 answers


It seems that the fix tempPdf.HtmlOptions.EndTasks(WebSupergoo.ABCpdf10.TaskState.AllWhenBecomeIdle);

is not actually a fix and is even causing some performance. I went ahead and removed the try / catch with it and reverted to the old ABC PDF version until it was resolved. This version probably shouldn't have been released and they knew about this issue even before it was released.



+2


source


I had the same problem and using below config helped me solve the problem.

I first 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 may change depending on the version installed (32 bit or 64 bit).

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



Not sure if it helps, but might be worth trying.

Edit

The above did not solve the problem for me either, but I noticed that errors usually start after deploying new code. Then after 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 options that you can override, and there are two that I think are related to the error: TempDirectory and ClearoutSize

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

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

      

For the second one I believe there is nothing to be done, but the manual says the following: The temp directory of ABCpdf is checked at startup. If it turns out that there are a large number of unused items, the directory will be cleaned up.

It is possible that something wrong can happen during this process (for example, locking a folder), especially if multiple processes are doing the same. You can set up a different temporary directory for each application and see how it goes.

0


source


With ABC PDF support, I was able to implement the following work.

Apparently when you use AddImageHtml a background process is started that converts HTML to PDF for you. It is this process that seems to hang at some point when you start getting this error. ABC PDF 10 offers a method to kill this process if it sits 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 document, sets the engine type to Gecko, and then calls EndTasks with the "AllWhenBecomeIdle" parameter. This will kill any remaining background worker processes that are not doing anything right now.

After that it works as usual, you can create your PDF file, convert HTML code, ...

And at the end (AFTER you've saved your PDF or transferred it to the browser (or after removing the Doc variable) I do the same again: kill any remaining background processes. This seems to work in our production environment. Hopefully that it will stay that way until ABC PDF comes 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

Terminating and restarting the Gecko process will incur a slight performance hit, so this is not an ideal solution. I have contacted their support team and they say they plan to release a new version without this issue, but don't know when it will be. They also advise using the EndTasks function only when we catch the exception that is thrown here. For my site, which requires a complete rewrite, I will not go that route.

0


source


Building on the answer by Steven Lemmens:

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 the asp.net page. The overhead of calling ResetAbcPdfGeckoProcess () only occurs if the first attempt to generate a PDF fails. If a PDFException is thrown, I do Response.Redirect (Request.RawUrl); to start the Page_Load fire again after starting and stopping the Gecko process. On the second iteration, the Page_Load PDF renders correctly.

-1


source







All Articles