Bas*_*sic 7 pdf .net-4.0 itext
我正在尝试将图像缩放为PDF文档的整页.我正在使用iTextSharp生成文档.图像具有正确的页面宽高比,但理想情况下,我希望图像扭曲而不是填充所有可用区域.
我目前有:
Dim Document As New Document(PageSize, 0, 0, 0, 0)
...
Dim ContentImage = '''Method call to get image'
Dim Content = iTextSharp.text.Image.GetInstance(ContentImage, New BackgroundColor)
Content.SetAbsolutePosition(0, 0)
Content.ScaleToFit(Document.PageSize.Width, Document.PageSize.Height)
Document.Add(Content)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这并不能解释打印机的利润率......
我需要图像适合可打印区域(尽可能在pdf中定义)
提前致谢
如果您决定按照经验进行操作,那么请使用您的代码打印一个页面,这样可以缩放到页面边框,这样图像会在前半英寸的边距上涂成黑色,如果它可以到达边缘.测量从每个边缘到黑色的距离(以英寸为单位)并将每个边距除以72.0.
我们将它们命名为:lm,rm,tm,bm(左上角的下边距.
Dim pageWidth = document.PageSize.Width - (lm + rm);
Dim pageHeight = document.PageSize.Height - (bm + tm);
Content.SetAbsolutePosition(lm, bm);
Content.ScaleToFit(pageWidth, pageHeight);
Document.Add(Content)
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码段缩放图像以适合PDF页面。
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromStream(resourceStream), System.Drawing.Imaging.ImageFormat.Png)
img.SetAbsolutePosition(0, 0)
'set the position to bottom left corner of pdf
img.ScaleAbsolute(iTextSharp.text.PageSize.A7.Width, iTextSharp.text.PageSize.A7.Height)
'set the height and width of image to PDF page size
Run Code Online (Sandbox Code Playgroud)
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromStream(resourceStream, System.Drawing.Imaging.ImageFormat.Png);
img.SetAbsolutePosition(0, 0); // set the position to bottom left corner of pdf
img.ScaleAbsolute(iTextSharp.text.PageSize.A7.Width,iTextSharp.text.PageSize.A7.Height); // set the height and width of image to PDF page size
Run Code Online (Sandbox Code Playgroud)
如果您需要完整的代码(c#),也可以参考以下链接。完整的代码将图像添加到现有PDF的所有页面。
| 归档时间: |
|
| 查看次数: |
21354 次 |
| 最近记录: |