gpt4 book ai didi

C# 使用 iTextSharp 将位图保存为 PDF

转载 作者:行者123 更新时间:2023-11-30 20:02:08 25 4
gpt4 key购买 nike

以下代码从窗体上的控件创建位图,然后显示保存对话框以保存为 JPEG。任何人都可以帮助使用 iTextSharp 将位图 bm 保存为 PDF 的代码吗?

 Bitmap bm = null;
bm = new Bitmap(this.RCofactorTBS.SelectedTab.Width, this.RCofactorTBS.SelectedTab.Height);
this.RCofactorTBS.SelectedTab.DrawToBitmap(bm, this.RCofactorTBS.SelectedTab.ClientRectangle);

SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "JPEG|*.jpeg";
dialog.Title = "Save Test As Jpeg";
dialog.ShowDialog();

if (dialog.FileName != "" && bm != null)
{
bm.Save(dialog.FileName);
}

最佳答案

你可以试试这个

System.Drawing.Image image = System.Drawing.Image.FromFile("Your image file path");
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, new FileStream("image.pdf", FileMode.Create));
doc.Open();
iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
doc.Add(pdfImage);
doc.Close();

引用自here

关于C# 使用 iTextSharp 将位图保存为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17145837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com