小编Kam*_*ran的帖子

资源文件中的iTextSharp pdf图像

我使用c#在Windows窗体中使用iTextSharp创建pdf文件,我想从Resource文件夹(图像名称:LOGO.png)向该文件添加图像。我有一个ExportExPdf.cs类,该类位于App_Class文件夹中。我正在使用下面的代码。任何人都可以帮忙。

internal static void exportEchoReport(Patient p)
{
    using (var ms = new MemoryStream())
    {
        using (var doc1 = new iTextSharp.text.Document(PageSize.A4, 50, 50, 15, 15))
        {
            try
            {
                PdfWriter writer = PdfWriter.GetInstance(doc1, new FileStream("echo.pdf", FileMode.Create));
                doc1.Open();

                string imagePath = // I want to use this image LOGO.png (Resources.LOGO)
                iTextSharp.text.Image logoImg = iTextSharp.text.Image.GetInstance(imagePath);

                PdfPTable headerTable = createTable(logoImg, p);
                doc1.Add(headerTable);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                doc1.Close();
            }
        }
        System.Diagnostics.Process.Start("echo.pdf");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# pdf itext

4
推荐指数
1
解决办法
2619
查看次数

标签 统计

c# ×1

itext ×1

pdf ×1