使用itextsharp将图像转换为pdf

时间:2016-10-25 07:50:07

标签: c# itext

这里我试图通过逐个追加来将jpg格式的图像文件转换为单个pdf ..这里是代码

 //Create a new document
        iTextSharp.text.Document Doc = new iTextSharp.text.Document(PageSize.A4);
        //Store the document on the desktop
        string PDFOutput = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output2.pdf");
        PdfWriter writer = PdfWriter.GetInstance(Doc, new FileStream(PDFOutput, FileMode.Create, FileAccess.Write, FileShare.Read));

        //Open the PDF for writing
        Doc.Open();

        //give folder from your local system that contains images
        string Folder = System.Web.Configuration.WebConfigurationManager.AppSettings["path"].ToString();
        foreach (string F in System.IO.Directory.GetFiles(Folder, "*.jpg"))
        {
           Image image1 = Image.GetInstance(F);
            //image1.SetAbsolutePosition(10f, 10f);
            image1.ScaleAbsolute(100, 300);

            //Insert a page
            Doc.NewPage();
            //Add image
            Doc.Add(image1);
        }

        //Close the PDF
        Doc.Close();

但在输出中,图像不适合页面但超出页面大小..

帮我解决如何设置图像尺寸以适应而不会降低质量...... 谢谢

0 个答案:

没有答案