如何为PdfSharp生成的Pdf自定义尺寸 [英] How to give custom size to PdfSharp generated Pdf
问题描述
我试图使用PdfSharp和HTMLRenderer从HTML生成一个包含表格的pdf.下面显示了代码.
I was trying to generate a pdf from HTML which containing a table using PdfSharp and HTMLRenderer. The following shows the code.
pdf = PdfGenerator.GeneratePdf(html, PageSize.A3);
byte[] fileContents = null;
using (MemoryStream stream = new MemoryStream())
{
pdf.Save(stream, true);
fileContents = stream.ToArray();
return new FileStreamResult(new MemoryStream(fileContents.ToArray()), "application/pdf");
}
我是否有可能为PDF提供自定义大小并更改页面方向.我正在使用内存流在浏览器显示屏上直接显示PDF.
Is there any possibility for me to provide a custom size to the PDF and change the orientation of the page. I am using a memory stream to show the PDF directly on the browser display.
推荐答案
您可以使用GeneratePdf
方法的PdfGenerateConfig
参数通过ManualPageSize
属性指定自定义页面大小.
You can use the PdfGenerateConfig
parameter of the GeneratePdf
method to specify a custom page size using the ManualPageSize
property.
使用PageOrientation
获取横向的标准页面大小.
Use the PageOrientation
to get standard page sizes in landscape.
注释中的代码:
var config = new PdfGenerateConfig();
config.PageOrientation = PageOrientation.Landscape;
config.ManualPageSize = new PdfSharp.Drawing.XSize(1080, 828);
pdf = PdfGenerator.GeneratePdf(html, config);
这篇关于如何为PdfSharp生成的Pdf自定义尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!