none
请问如何把多张图片添加到pdf中 RRS feed

答案

  • Hi Bill,

    你可以尝试下面的方法来将多张图片添加到pdf中。

    首先你需要安装nuget包->iTextSharp。

    其次你可以尝试下面的代码。

    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.IO;
                Document doc = new Document(PageSize.A4);
                string path = "D:\\test.pdf";
                var output = new FileStream(path, FileMode.Create);
                var writer = PdfWriter.GetInstance(doc, output);
                doc.Open();
    
    
                var image1 = iTextSharp.text.Image.GetInstance("D://pic/1.jpg");
                //image1.SetAbsolutePosition(0, 0);  //设置图片的位置
                image1.ScaleAbsoluteHeight(550);     //设置图片的高度
                image1.ScaleAbsoluteWidth(550);      //设置图片的宽度
                doc.Add(image1);
    
                var image2 = iTextSharp.text.Image.GetInstance("D://pic/2.jpg");
                //image2.SetAbsolutePosition(0,0);
                image2.ScaleAbsoluteHeight(550);
                image2.ScaleAbsoluteWidth(550);
                doc.Add(image2);
    
                var image3 = iTextSharp.text.Image.GetInstance("D://pic/3.jpg");
                //image3.SetAbsolutePosition(0, 0);
                image3.ScaleAbsoluteHeight(550);
                image3.ScaleAbsoluteWidth(550);
                doc.Add(image3);
    
                doc.Close();

    Best Regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 BillQu0002 2020年10月7日 8:32
    2020年9月25日 6:05
    版主