1

我尝试使用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();
        }
4

1 回答 1

3

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

于 2020-01-13T09:52:02.210 回答