The first free coding sample explains how to transform images and add them into PDF document in Visual Studio C# .NET application. Developers can choose to change one image or a few image files to PDF document. Now, we will convert JPEG/JPG images on local disk to PDF for illustration.
using System; using PQScan.ImageToPDF; namespace ImageToPDF { class Program { static void Main(string[] args) { // Create an instance of PQScan.ImageToPDF.PDFConverter object. PDFConverter converter = new PDFConverter(); // Set PDF page layout. A4 is the most widely used one. converter.PageSizeType = PageSizeMode.A4; // Set input images from local files. string[] imgFiles = newstring[3] { "input1.jpg", "input2.jpeg", "input3.jpg" }; // Set output PDF file name. string outFile = "jpeg-to-pdf.pdf"; // Generate PDF from input images. converter.CreatePDF(imgFiles, outFile); } } }
The second sample will tell developers how to convert PNG images from file stream to PDF document using C#.NET class code.
using System; using System.IO; using PQScan.ImageToPDF; namespace ImageToPDF { class Program { static void Main(string[] args) { // Create an instance of PQScan.ImageToPDF.PDFConverter object. PDFConverter converter = new PDFConverter(); // Set PDF page layout. If set to ImageSize, // PDF page will keep the original size and quality of source image. converter.PageSizeType = PageSizeMode.ImageSize; // Set input images from file streams. FileStream[] streams = newFileStream[3]; streams[0] = newFileStream("input1.png", FileMode.Open); streams[1] = newFileStream("input2.png", FileMode.Open); streams[2] = newFileStream("input3.png", FileMode.Open); // Give a name to output PDF document. string outFile = "png-to-pdf.pdf"; // Create PDF from loaded image files. converter.CreatePDF(streams, outFile); } } }