You say "by hand" which confused some people, I think. You're not actually saying that you want to write raw PDF, right? Below is code that uses the open source iTextSharp library (5.1.1.0). Set the variable FolderWithImages to your folder containing images and PdfFileName to the PDF that you want to kick out and it will take all JPGs in the folder and create a PDF. This code is very simple but you can do a lot of things like resizing, scaling, etc. There's tons of code out there for iTextSharp and its parent project iText.
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//The folder containing our images
string FolderWithImages = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//The PDF that we will output
string PdfFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ImagesCombined.pdf");
//Create a basic stream to write to
using (FileStream fs = new FileStream(PdfFileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
//Create a new PDF document
using (Document doc = new Document())
{
//Bind a the document to the stream
using (PdfWriter w = PdfWriter.GetInstance(doc, fs))
{
//Open our document for writing
doc.Open();
//Will hold an instance of our image
iTextSharp.text.Image img;
//Grab all JPGs from the given folder and loop through them
string[] Images = Directory.GetFiles(FolderWithImages, "*.jpg", SearchOption.TopDirectoryOnly);
foreach (string i in Images)
{
//Get the JPG as an iTextSharp "image"
img = iTextSharp.text.Image.GetInstance(i);
//Tell the image that when placed we want it at (0,0)
img.SetAbsolutePosition(0, 0);
//Tell the system that the next "page" that we add should be the dimension of the image
doc.SetPageSize(new iTextSharp.text.Rectangle(0, 0, img.Width, img.Height));
//Add a new blank page
doc.NewPage();
//Put the image on the blank page
doc.Add(img);
}
//Close our output PDF
doc.Close();
}
}
}
this.Close();
}
}
}