IronPdf 打印到边距

IronPdf Print to Margin

我尝试从 html 打印带有 IronPdf 的 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();
        }

感谢 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;

将边距设置为 0。