How to convert multiple .jpgs images to a single pdf file in C #

1

What I have is a directory with eg 10 scanned images. I would like to read these images in this directory and convert it to a single .PDF file. I know there are Dlls in the market that do this but I would like to do the same myself routine. Would it be possible?

    
asked by anonymous 20.01.2016 / 18:51

1 answer

2

Because you have nothing done, I'll give you what I have here .. maybe not 100% what you want, but it will give you a way. A basic idea, you may have to readjust the image.

//Cria um novo documento
iTextSharp.text.Document Doc = new iTextSharp.text.Document(PageSize.LETTER, 20, 20, 20, 20);
//Salve o documento
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));

//Abra o PDf
Doc.Open();

string Folder = "C:\Images";
foreach (string F in System.IO.Directory.GetFiles(Folder, "*.jpg")) {
    // Inserir uma pagina
    Doc.NewPage();
    //Adicionar uma Imagem
    Doc.Add(new iTextSharp.text.Jpeg(new Uri(new FileInfo(F).FullName)));
}

//Fechar pdf
Doc.Close();
    
20.01.2016 / 18:59