我正在尝试从HTML字符串创建PDF文件,基本上HTML是一个包含多个列的表。问题是,当我生成PDF文件时,我无法看到所有列。
我尝试了几种选择,但到目前为止还没有运气:
var generator = new NReco.PdfGenerator.HtmlToPdfConverter();
generator.CustomWkHtmlPageArgs = "--enable-smart-shrinking";
generator.CustomWkHtmlArgs = "--page-width value";
generator.PageWidth = Value;
所有HTML元素(如body和table)都有width = 100%
如何让HTML适合一个页面?
这是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>
答案 0 :(得分:1)
我最终结合了方向,缩放和页面大小:
generator.Orientation = NReco.PdfGenerator.PageOrientation.Landscape
generator.Zoom = 0.55f;
generator.Size = NReco.PdfGenerator.PageSize.A3;
这样,我就可以显示所有列。
答案 1 :(得分:0)
在大多数情况下,您无法查看所有列,因为您的表需要的空间大于PDF页面上指定宽度(mm)和默认DPI的可用空间。对于A4尺寸,尝试在Web浏览器中打开HTML模板,将其窗口大小调整为大约800-900px,并查看页面布局发生的情况。
顺便说一下,以下代码行设置了相同的wkhtmltopdf选项:
generator.CustomWkHtmlArgs = "--page-width value";
generator.PageWidth = Value;