C# Image and PDF Manipulation

Asked

Viewed 1,324 times

5

I wonder if there’s a way to turn multiple images into a single PDF file. On my app I’m already pulling their address.

  • Da uma olhda neste link --> http://www.pdfsharp.net/wiki/ExportImages-sample.ashx?AspxAutoDetectCookieSupport=1 e neste outro --> http://weblogs.asp.net/andrenobre/gerando-arquivos-pdf-net-e-e-xtitesharp

  • If you choose to call an external application, see about ImageMagick and PDFTK. They are very easy to use, do very well the service, and running external applications in C# is very simple. Of course it is not always ;D option

1 answer

2


Using the iTextSharp 4, can be done as follows:

iTextSharp.text.Document Doc = new iTextSharp.text.Document(PageSize.LETTER, 20, 20, 20, 20);
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 = "C:\\Diretorio\\das\\Imagens";
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();

I got the answer from here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.