C#winform:将图像插入pdf [英] C# winform :insert image to pdf
本文介绍了C#winform:将图像插入pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个图像,我需要将第一个图像插入到第一页,将第二个图像插入到同一PDF中的第二页。我如何实现这一目标?对不起,我是这个节目的新手。 tq
我的尝试:
private void pdfConverter()
{
// FIRST PAGE
//创建新的pdf文档和页面
PdfDocument doc = new PdfDocument();
PdfPage oPage = new PdfPage();
//将页面添加到pdf文档并将捕获的图像添加到其中
doc.Pages.Add(oPage);
XGraphics xgr = XGraphics.FromPdfPage(oPage);
XImage img = XImage.FromFile(@C:\ Temp\img1.jpg);
xgr.DrawImage(img,0,0);
saveFileDialog.Filter =(PDF File | * .pdf);
DialogResult btnSave = saveFileDialog.ShowDialog();
if(btnSave.Equals(DialogResult.OK))
{
doc.Save(saveFileDialog.FileName);
doc.Close();
}
img.Dispose();
}
解决方案
这应该有所帮助:如何将多个图像添加到单个PDF中? | iText开发人员 [ ^
PLS。尝试下面的解决方案
c# - 使用iTextSharp将图像添加到PDF并正确缩放 - Stack Overflow [ ^ ]
插入图像用C#转换成PDF [ ^ ]
希望上面的链接解决你的问题。
i have two image, where i need to insert the first image to first page and second image to second page in the same PDF. How do i achieve this ? sorry, im new in this programming. tq
What I have tried:
private void pdfConverter() { //FIRST PAGE // Create new pdf document and page PdfDocument doc = new PdfDocument(); PdfPage oPage = new PdfPage(); // Add the page to the pdf document and add the captured image to it doc.Pages.Add(oPage); XGraphics xgr = XGraphics.FromPdfPage(oPage); XImage img = XImage.FromFile(@"C:\Temp\img1.jpg"); xgr.DrawImage(img, 0, 0); saveFileDialog.Filter = ("PDF File|*.pdf"); DialogResult btnSave = saveFileDialog.ShowDialog(); if (btnSave.Equals(DialogResult.OK)) { doc.Save(saveFileDialog.FileName); doc.Close(); } img.Dispose(); }
解决方案
This should help: How to add multiple images into a single PDF? | iText Developers[^]
Pls. try below solution
c# - Adding an image to a PDF using iTextSharp and scale it properly - Stack Overflow[^]
Insert an Image Into a PDF in C#[^]
Hope above link solve your prblm.
这篇关于C#winform:将图像插入pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文