只要能执着远大的理想,且有不达目的绝不终止的意愿,便能产生惊人的力量。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
convertJpegToPDFUsingItextSharp();
}
private void convertJpegToPDFUsingItextSharp()
{
iTextSharp.text.Document Doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A2, 10, 10, 10, 10);
string PDFOutput = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Output.pdf");
PdfWriter writer = PdfWriter.GetInstance(Doc, new FileStream(PDFOutput, FileMode.Create, FileAccess.Write, FileShare.Read));
Doc.Open();
string Folder = "D:\\Images";
foreach (string F in System.IO.Directory.GetFiles(Folder, "*.jpg"))
{
Doc.NewPage();
Doc.Add(new iTextSharp.text.Jpeg(new Uri(new FileInfo(F).FullName)));
}
Doc.Close();
}
}
结果如图: