Using both Enable Form and PdfFooter causes error

I am trying out the HTML to PDF conversion and when I combine the following
EnableForm = true
PdfFooter = CreateFooter(converterSettings.PdfPageSize.Width); 

I get the following error

Syncfusion.Pdf.PdfException
  HResult=0x80131500
  Message=Value can not be less 0, equal or more than number of pages in the document. (Parameter 'index')
  Source=Syncfusion.HtmlConverter.Portable
  StackTrace:
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String url)
   at ProjectService.Schema.Mutation.RootMutation.<>c__DisplayClass3_0.<AddPDFMutations>b__0(IResolveFieldContext`1 context) in D:\work\NineHi\git\ProjectService\ProjectService\Schema\Mutation\PDFMutation.cs:line 43
   at GraphQL.Resolvers.FuncFieldResolver`2.Resolve(IResolveFieldContext context) in /_/src/GraphQL/Resolvers/FuncFieldResolver.cs:line 42
   at GraphQL.Resolvers.FuncFieldResolver`2.GraphQL.Resolvers.IFieldResolver.Resolve(IResolveFieldContext context) in /_/src/GraphQL/Resolvers/FuncFieldResolver.cs:line 44
   at GraphQL.Resolvers.FieldResolverExtensions.<ResolveAsync>d__0.MoveNext() in /_/src/GraphQL/Resolvers/FieldResolverExtensions.cs:line 16

HTML Page
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <link rel='nofollow' href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-white">
<h3 class="text-2xl font-bold">Header</h3>
<p class="italic pt-3 pb-6">Sub Header text</p>
<table>
    <thead>
    <tr>
        <th class="text-left">Name</th>
        <th class="w-50 w-px text-center">Count</th>
        <th class="w-50 w-px text-center">Input</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td colspan="3">Category</td>
    </tr>
    <tr>
        <td>Category 1</td>
        <td class="w-50 w-px text-center">4</td>
        <td class="w-50 w-px text-center"><select class=" border-b-2 border-gray-700">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
        </select></td>
    </tr>
    <tr>

        <td colspan="3">
            <p style="font-style: italic;">Some random helper text</p>
        </td>
    </tr>
    <tr>
        <td>Category 2</td>
        <td class="w-50 w-px text-center">4</td>
        <td class="w-50 w-px text-center"><input type="text" class=" border-b-2 border-gray-700" /></td>
    </tr>
     ... Repeat to get 3 pages worth
</tbody></table>
</div>
</body>
</html>

C# code
GeneratePDF()
{
//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

//Initialize WebKit converter settings
WebKitConverterSettings converterSettings = new WebKitConverterSettings();

//Set the WebKit path
converterSettings.WebKitPath = Path.Combine(hostingEnvironment.ContentRootPath, "Pdf/QtBinariesWindows");

//Enable the form to convert HTML form to PDF fill able form
converterSettings.EnableForm = true;

converterSettings.PdfFooter = CreateFooter(converterSettings.PdfPageSize.Width);

//Assign WebKit settings to HTML converter settings
htmlConverter.ConverterSettings = converterSettings;

//Convert HTML to PDF
PdfDocument document = htmlConverter.Convert(Path.Combine(hostingEnvironment.ContentRootPath, "Template.html")); <-- Error here

//Creates a new Memory stream
MemoryStream stream = new MemoryStream();

// Saves the document as stream
document.Save(stream);
document.Close(true);

// Converts the PdfDocument object to byte form.
return stream.ToArray();
}

PdfPageTemplateElement CreateFooter(float width)
{
     //Create a Page template that can be used as footer.
     RectangleF bounds = new RectangleF(0, 0, width, 40);
     PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
     PdfGraphics g = footer.Graphics;

     //Create page number field.
     PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
     PdfBrush brush = new PdfSolidBrush(Color.Black);
     PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

     //Create page count field.
     PdfPageCountField count = new PdfPageCountField(font, brush);

     //Add the fields in composite fields.
     PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count) {Bounds = footer.Bounds};
     //Draw the composite field in footer.
     compositeField.Draw(g, new PointF(10, 0));
     return footer;
}

any help would be appreciated


11 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team May 6, 2021 02:42 PM UTC

Hi Brad, 
 
Thank you for using Syncfusion products.  
 
We are able to reproduce the reported exception while converting HTML to PDF with provided details. Currently, we are validating the reported issue and we will update the further validation details by May 10, 2021.  
 
Regards, 
Gowthamraj K 



GK Gowthamraj Kumar Syncfusion Team May 10, 2021 12:54 PM UTC

Hi Brad, 
 
Thank you for your patience.   
 
We have confirmed that the issue with "Exception occurs while converting HTML to PDF with footer and forms" is a defect. The fix for this issue in our latest stable version is estimated to be available by May 17th , 2021. 
 
The status of this bug can be tracked through the following feedback link,  
 
Note: Can you please share us the product version which you need the patch, so that we will update the patch in the same version. 
 
Regards, 
Gowthamraj K 



BS Brad Stansbury May 10, 2021 12:57 PM UTC

Gowthamraj,

Thank you for the quick response. i am currently using the most latest release.


PV Prakash Viswanathan Syncfusion Team May 11, 2021 06:30 AM UTC

Hi Brad, 
 
Thank you for the update.  
 
As we said earlier, we will fix this issue and update the patch on May 17th , 2021 with latest version.  
 
Regards, 
Prakash V 



SG Sivaram Gunabalan Syncfusion Team May 17, 2021 03:55 PM UTC

Hi Brad, 
 
Thank you for your patience.  
  
We have generated the patch assemblies and NuGet package for “Exception occurs while converting HTML to PDF with footer and forms” in latest version 19.1.0.63. Patch for the bug can be downloaded from below link,   

Version: 19.1.0.63. 
Platform: ASP.NET Core.     
 
The status of this bug can be tracked through the following feedback link,   
  
We have Attached the sample with provided patch Assemblies, the reported exception was resolved and PDF output preserves forms and footer contents. Kindly please try the below sample in your machine and let us know the result.     
 
 
Note:       
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.      
  
Disclaimer:       
Please note that we have created this patch for version 19.1.0.63 specifically to resolve the following issue(s) reported in this/the forum(s).165187 
  
If you have received other patches for the same version for other products, please apply all patches in the order received.      
     
Note: This package does not have a QtbinariesWindows folder. You can use the existing QtbinariesWindows folder for conversion. 
  
Please try the above provided patch in your end and let us know if it suites your requirement or not. 

Regards, 
Sivaram G 



BS Brad Stansbury May 18, 2021 01:14 PM UTC

Hi Sivaram,

I tried 19.1.0.63 and i am still seeing the same issue.
Value can not be less 0, equal or more than number of pages in the document. (Parameter 'index')


And my Binaries are copied from HTMLConverter/19.1.0.63/QtBinariesDotNetCore
and i used the exact example i posted before

Regards,
Brad


SG Sivaram Gunabalan Syncfusion Team May 19, 2021 12:32 PM UTC

Hi Brad, 

Thanks for your update, 

We have ensured the sample with provided patch on our end, the HTML to PDF conversion preserves forms and footer content properly. Kindly please try the below sample in your machine and let us know the result.  
 
 
However, the exception may occurs due to the NuGet package already installed was not replaced with provided NuGet package. 
 
Steps to remove already existing nuget package: 
 
1.Find the syncfusion.htmltopdfconverter.qtwebkit.net.core(19.1.0.63) NuGet package installed location.(i.e C:\Users\*******\.nuget\packages\syncfusion.htmltopdfconverter.qtwebkit.net.core\19.1.0.63\). 
2.Before removing the folder need to get backup of QtBinariesWindows folder if not have in another location. 
3.Remove 19.1.0.63 NuGet folder. 
4.Clean the sample project and install provided custom NuGet. 
5. Build and run the sample project. 
 
If still facing same issue, Kindly please try the conversion with add the provided patch assemblies .dll files in project dependencies. 
 
Note: Above sample does not contains QtBinariesWindows folder. You can use the already existing QtBinariesWindows folder in your machine. 
 
Please try the above steps in your end and let us know the result. 

Regards, 
Sivaram G 



BS Brad Stansbury May 19, 2021 12:49 PM UTC

Hi Sivaram,



GK Gowthamraj Kumar Syncfusion Team May 19, 2021 02:28 PM UTC

Hi Brad, 
 
Thanks for your update. 
 
The reported issue with  Exception occurs while converting HTML to PDF with footer and forms” is not included in latest version 19.1.0.63. So, we have generate and provide a custom patch for this fix with current latest version (19.1.0.63).The custom patch for this issue can be downloaded from below link, 
 
 
Please refer the below KB steps to install custom NuGet package, 
 
Please try the above patch in your end and let us know the result. 
 
Regards, 
Gowthamraj K 


Marked as answer

BS Brad Stansbury May 19, 2021 03:37 PM UTC

Gowthamraj,

Thanks. I tried the attached assemblies and confirm it does fix the issue in the sample code

Regards,
Brad


GK Gowthamraj Kumar Syncfusion Team May 20, 2021 06:19 AM UTC

Hi Brad, 
 
Thank you for your update. We are glad to know that your problem has been solved. 

Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon