如何使用NReco.PdfGenerator设置边距?

时间:2015-02-11 22:33:49

标签: asp.net c#-4.0 pdf-generation margins

我成功地使用NReco.PDFGenerator更改了许多设置,但我不明白如何设置边距。我找到了.Margins选项,但它希望类型为PageMargins。以下是我尝试过的一些事情。如何设置上边距,左边距,下边距和右边距?

HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter();
pdfConverter.Size = PageSize.Letter;
pdfConverter.Orientation = PageOrientation.Landscape;
pdfConverter.Zoom = 1F;
pdfConverter.CustomWkHtmlArgs = "--encoding UTF-8";

// What I tried...
pdfConverter.Margins = (PageMargins)1;    // can't caste
pdfConverter.Margins = PageMargins.????;  // no appropriate methods
pdfConverter.Margins = 1;                 // wrong type
pdfConverter.Margins = "1";               // wrong type

1 个答案:

答案 0 :(得分:6)

设置边距:

pdfConverter.Margins = new PageMargins {Top = 1, Bottom = 1, Left = 1, Right = 1}

var margins = new PageMargins();

margins.Top = 1;
margins.Bottom = 1;
margins.Left= 1;
margins.Right= 1;

pdfConverter.Margins = margins;

(假设:using NReco.PdfGenerator;

他们做同样的事情,即将所有边距设置为1毫米。 您可以在此处阅读更多内容:http://www.nrecosite.com/doc/NReco.PdfGenerator/