views:

1103

answers:

6

I would like to convert from JPG to PDF, I've checked out ImageMagickNET, but it is far too complex for what I am after doing, it needs to be simple.

Any pointers would be welcomed

+6  A: 

iTextSharp does it pretty cleanly and is open source. Also, it has a very good accompanying book by the author which I recommend if you end up doing more interesting things like managing forms. For normal usage, there are plenty resources on mailing lists and newsgroups for samples of how to do common things.

Ruben Bartelink
Don't forget the link http://itextsharp.sourceforge.net/
csl
@csl: Thanks, yes - Jeff is right about people not reading previews (I didnt trust it for some reason). I originally put it in but left off the http:// in the link which stopped it being linkified. (If you delete your comment, I'll delete this one)
Ruben Bartelink
Perfect thanks, does the job with ease
Coppermill
+6  A: 

Easy with iTextSharp:

class Program
{
    static void Main(string[] args)
    {
        Document document = new Document();
        using (var stream = new FileStream("test.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
        {
            PdfWriter.GetInstance(document, stream);
            document.Open();
            using (var imageStream = new FileStream("test.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var image = Image.GetInstance(imageStream);
                document.Add(image);
            }
            document.Close();
        }
    }
}
Darin Dimitrov
Nice, +1 for the tidying too. As a matter of interest (I havent used it in ages), is there a cleaner way to use Document w/ IDisposable and/or should there be a try/finally guarding the Close? Presumably not if imageStream is the actual resource holder/owner?
Ruben Bartelink
A: 

Many diff tools out there. One I use is PrimoPDF (FREE) http://www.primopdf.com/ you go to print the file and you print it to pdf format onto your drive. works on Windows

Harry
wrong answer. he wants to do it in a programming way (C# in specific).
Shivan Raptor
+1  A: 

One we've had great luck with is PDFSharp (we use it for TIFF and Text to PDF conversion for hundreds of medical claims every day).

http://pdfsharp.com/PDFsharp/

Bob Palmer
A: 

We've built a new service to do it via a simple URL pass. If you encoded your JPG inside an HTML wrapper, you could just throw it at our tool, and it would return a PDF of the image. It would also let you add captions, etc, in the html.

URL is http://fourpdf.com/

Regards, Jake.

Jake Liddell
A: 

Hi there, not sure if you're looking for just free / open source solutions or considering commercial ones as well. But if you're including commercial solutions, there's a toolkit called EasyPDF SDK that offers an API for converting images (plus a number of other file types) to PDF. It supports C# and can be found here:

 http://www.pdfonline.com/

The C# code would look as follows:

 Printer oPrinter = new Printer();

 ImagePrintJob oPrintJob = oPrinter.ImagePrintJob;
 oPrintJob.PrintOut(imageFile, pdfFile);

To be fully transparent, I should disclaim that I do work for the makers of EasyPDF SDK (hence my handle), so this suggestion is not without some personal bias :) But feel free to check out the eval version if you're interested. Cheers!

yu-chen-pdfonline-com