0

I am trying to create a PDF file from a HTML string, basically the HTML is a Table with several columns. The problem is that when I generate the PDF file I am not able to see all the columns.

I have tried several options but so far no luck:

var generator = new NReco.PdfGenerator.HtmlToPdfConverter();
generator.CustomWkHtmlPageArgs = "--enable-smart-shrinking";
generator.CustomWkHtmlArgs = "--page-width value";
generator.PageWidth = Value;

Also all the HTML elements like body and table have width=100%

How can I make the HTML to fit in one page?

This is the HTML:

<!doctype html>
<html lang="en">
   <body >            
   <table border="1" width="100%">
      <tr>
         <th >Heat Id</th>
         <th >Heat Order Id</th>
         <th >MSP</th>
         <th >Grade</th>
         <th >Recipe</th>
         <th >Shift</th>
         <th >Crew</th>
         <th >Start Date</th>
         <th >End Date</th>
         <th >Tap Date</th>
         <th >Tap Wt. (Tons)</th>
         <th >Scale Tap Wt. (Tons)</th>
         <th >Cast Heat Wt.</th>
         <th >Cast Slab Wt.</th>
         <th >Charge Wt. (Tons)</th>
         <th >Pseudo 1 Bucket</th>
         <th >Scrap Wt. (Tons)</th>
         <th >Scrap Flux Wt. (Tons)</th>
         <th >Alloys Wt. (Lbs)</th>
         <th >Tap Flux Wt. (Lbs)</th>
         <th >MWH</th>
         <th >Avg MW</th>
         <th >KWH / Charge Ton</th>
         <th >Tap To Tap Time A & B Furnace (min)</th>
         <th >Tap To Tap Time Single Furnace (min)</th>
         <th >Power On Time (min)</th>
         <th >Power On %</th>
         <th >Delay Time (min)</th>
         <th >Tons / Hr</th>
         <th >Total O2</th>
         <th >Total O2 SS</th>
         <th >Total Gas</th>
         <th >Total C</th>
         <th >Tap Temp</th>
         <th >Tap C</th>
         <th >Tap O2</th>
         <th >Ladle ID</th>
         <th >Comments</th>
         <th >Auto Preheat On Time (min)</th>
         <th >Auto Preheat Energy (MWH)</th>
         <th >Heating/Lancing Energy (MWH)</th>
      </tr>                  
   </table>               
   </body>
</html>
Juan Alberto
  • 165
  • 3
  • 18

2 Answers2

3

I ended up combining orientation, zoom and page size:

generator.Orientation = NReco.PdfGenerator.PageOrientation.Landscape
generator.Zoom = 0.55f;
generator.Size = NReco.PdfGenerator.PageSize.A3;

That way, I was able to display all the columns.

Juan Alberto
  • 165
  • 3
  • 18
0

In most cases you cannot see all columns because your table needs more space than available on PDF page for specified width (in mm) and default DPI. For A4 size try to open your HTML template in a web browser, resize its window to approx 800-900px in width and see what is happening with the page layout.

BTW the following code lines set the same wkhtmltopdf option:

generator.CustomWkHtmlArgs = "--page-width value";
generator.PageWidth = Value;
Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • I wonder if there is an option to scale the content to fit the PDF page. Something like when you open the html page in Chrome then you try to print it to PDF. It scales very nicely. – Juan Alberto Jun 26 '17 at 15:57