生成 Winnovative PDF 为一定的宽度/高度像素大小
我希望使用 Winnovative PDF 转换器从 HTML 生成 PDF 文档
我希望将 PDF 转换为精确的 842 x 595 像素
我已经尝试过:
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A5
但这不合适。所以我尝试过:
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Custom
pdfConverter.PdfDocumentOptions.CustomPdfPageSize = New SizeF(842, 595)
但是这也不起作用,因为我认为尺寸是以与像素不同的格式测量的?
如何生成精确为 842 x 595 像素的 PDF,使其与我的 HTML 内容匹配?
I'm looking to generate a PDF document from HTML using the Winnovative PDF Converter
I wish to convert the PDF to exactly 842 x 595 pixels
I've tried doing:
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A5
But this doesn't fit right. So I tried:
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Custom
pdfConverter.PdfDocumentOptions.CustomPdfPageSize = New SizeF(842, 595)
However this doesn't work right either as I think the size is measured in a different format to pixels?
How can I generate a PDF at exactly 842 x 595 pixels so that it matches my HTML content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 HTML 内容渲染为 PDF 时涉及两件事。 PDF 页面大小和转换器内部 HTML 查看器宽度。启用 FitWidth 后,可以缩小 HTML 内容以适合 PDF 页面宽度。
PDF 页面大小以磅表示(1 磅为 1/72 英寸),内部 HTML 查看器窗口大小以像素表示(i 像素为 1/96 英寸)。
PDF 页面 A4 肖像尺寸为 595 x 842 点,与 595 点对应的 HTML 查看器宽度为 595 x 96 / 72 = 793 像素。
所以转换器的设置是:
pdfConverter.HtmlViewerWidth = 793
pdfConverter.PdfDocumentOptions.PdfPageSize = new PdfPageSize(595,842)
您可以在 控制 PDF 页面演示中的 HTML 缩放。以下是该演示中相关代码的副本:
There are 2 things involved when rendering the HTML content to PDF. The PDF page size and the converter internal HTML viewer width. When FitWidth is enabled the HTML content can be scaled down to fit the PDF page width.
The PDF page size is expressed in points (1 point is 1/72 inch) and the internal HTML viewer window size is expressed in pixels (i pixel is 1/96 inch).
The PDF page A4 potrait size is 595 x 842 points and the HTML viewer width corresponding to the 595 points is 595 x 96 / 72 = 793 pixels.
So the settings of the converter are:
pdfConverter.HtmlViewerWidth = 793
pdfConverter.PdfDocumentOptions.PdfPageSize = new PdfPageSize(595,842)
You can find a description of all the HTML scaling and fitting options and sample code in the Control HTML Scaling in PDF Page demo. Below is a copy of the relevant code from that demo:
如果您将 PdfConverter.PageWidth 和 PdfConverter.PageHeight 属性设置为 842 和 595,那么这应该会导致您的 Web 内容填充整个 PDF 页面区域。
还有一个 FitWidth 属性,如果您希望 Web 内容不缩小以适应可用页面区域,则可以将其设置为 False。这意味着如果您的内容太大,将会溢出页面。
关于 Winnovative PDF 需要提出的另一点是,处理高分辨率图像并不容易,因此根据您的 PDF 需求(和输入),您可能很难获得高质量的图像 - 也许这只是我的经验。
说到图像,Winnovative PDF 似乎会获取您输入的 html 并创建所有图像的单个图像,然后以屏幕分辨率 (72 dpi) 添加到 PDF,这甚至会使简单的文本看起来质量较低。
如果您想尝试自己处理 html 布局,您始终可以使用其他产品(例如 )将内容直接转换为 PDF ITextSharp 可以为更高分辨率的图像提供更大的灵活性。不过我真的取决于你的总体需求
If you set the PdfConverter.PageWidth and PdfConverter.PageHeight attributes to 842 and 595 then that should cause your web content to fill the whole PDF page area.
There is also a FitWidth property which can be set to False if you want your web content to not be scaled down to fit the available page area. This will mean that your content will overflow the page if it is too large though.
Another point to raise about Winnovative PDF is that it is not easy to work with high resolution images, so depending on your PDF needs (and input) you may struggle to get good quality images - maybe that was just from my experience though.
Speaking of images, it seems that Winnovative PDF takes your input html and creates a single image of it all which then gets added to the PDF at screen resolution (72 dpi) and this can even make simple text look low quality.
If you fancied having a go at handle the html layout yourself you could always convert your content straight to PDF using another product such as ITextSharp which would allow more flexibility over higher resolution images. I really depends on your overall needs though