Search code examples
c#asp.net-mvcxulrunnergeckoabcpdf

ABCpdf nuget package XULRunner folder is corrupt?


I'm trying to update my (previously working) pdf-creating web application to use the ABCpdf.NET and ABCpdf.NET Gecko Runtime nuget packages.

I've installed both packages (both are version 8.1.1.6) however when I run my application, I get the following WebSupergoo.ABCpdf8.Internal.PDFException:

Failed to add HTML: Gecko engine hit an error it was unable to recover from. Possible causes: XULRunner folder is corrupt or is from another version of ABCpdf.

After installing the ABCpdf.NET Gecko Runtime package, I got a dialog telling me that I would need to manually copy the XULRunner folder into my output directory. In order to achieve this, I added the following to my applications .csproj file:

  <Target Name="AfterBuild">
    <CallTarget Targets="CopyAbcpdfToDeployFolder" />
  </Target>
  <Target Name="CopyAbcpdfToDeployFolder">
    <ItemGroup>
      <SourceDir Include="$(ProjectDir)XULRunner\**\*.*" />
    </ItemGroup>
    <Copy SourceFiles="@(SourceDir)" DestinationFolder="$(WebProjectOutputDir)\$(OutputPath)%(SourceDir.RecursiveDir)\XULRunner" />
  </Target>

(This seems to be working correctly - the XULRunner folder and its contents are present in my bin folder after a build)

The line of code that is failing is as follows:

theDoc.AddImageUrl(url);

Can anyone help me get this working?


Solution

  • As it turns out, my changes to the .csproj file we not copying all files into the correct subfolders. In order to copy the folder structure and files recursively, the XML should have looked like this:

      <Target Name="AfterBuild">
        <CallTarget Targets="CopyXULRunnerToDeployFolder" />
      </Target>
      <Target Name="CopyXULRunnerToDeployFolder">
          <ItemGroup>
              <MyFiles Include="XULRunner\**\*.*" />
          </ItemGroup>
          <Microsoft.Build.Tasks.Copy SourceFiles="@(MyFiles)"  DestinationFiles="@(MyFiles->'$(OutputPath)\XULRunner\%(RecursiveDir)%(Filename)%(Extension)')"/>
      </Target>