1
I am using window form . net and would like to convert scanned images to PDF thus generating images pages in PDF. I’m using the Pdfsharp. I have the following code but it only generates a page. Which commands should I use to generate the images and generate the PDF with pages. At first I think about loading a Datatable and after that read each of the lines and generate but I do not know how to do.... Could you give me a hint?
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
try
{
string source = (e.Argument as string[])[0];
string destinaton = (e.Argument as string[])[1];
PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);
doc.Pages[0].Width = XUnit.FromPoint(img.Size.Width);
doc.Pages[0].Height = XUnit.FromPoint(img.Size.Height);
xgr.DrawImage(img, 0, 0, img.Size.Width, img.Size.Height);
doc.Save(destinaton);
doc.Close();
success = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}