Max*_*ann 2 c# printing printdocument ironpdf
我尝试使用IronPdf从 html打印 pdf ,但结果留下了边框。有没有办法在我的 PrintDocument 中设置“适合页面”?
这是我的代码:
public static void PrintDocument(string printer, bool landscape, PdfDocument pdfDocument, Duplexing duplex)
{
var printDocument = pdfDocument.GetPrintDocument();
printDocument.PrinterSettings.PrinterName = printer;
printDocument.DefaultPageSettings.Landscape = landscape;
printDocument.PrinterSettings.Duplex = DuplexMapping(duplex);
printDocument.PrinterSettings.DefaultPageSettings.PaperSize.RawKind = (int)PaperKind.A4;
printDocument.Print();
}
Run Code Online (Sandbox Code Playgroud)
感谢 IronPdf-Support 我找到了一个解决方案:
// enable javascript
var renderer = new IronPdf.HtmlToPdf();
renderer.PrintOptions.EnableJavaScript = true;
renderer.PrintOptions.RenderDelay = 500; //milliseconds
renderer.PrintOptions.CssMediaType = IronPdf.PdfPrintOptions.PdfCssMediaType.Screen;
renderer.PrintOptions.MarginTop = 0;
renderer.PrintOptions.MarginBottom = 0;
renderer.PrintOptions.MarginLeft = 0;
renderer.PrintOptions.MarginRight = 0;
Run Code Online (Sandbox Code Playgroud)
将边距设置为 0。
| 归档时间: |
|
| 查看次数: |
3825 次 |
| 最近记录: |