We made thousands of pre-made source code pieces for easy implementation in your own programming projects. ByteScout PDF SDK is the pdf library that can create, update and modify PDF files. Supports text with fonts and style selections, layers, form fields, drawing lines and objects, automatic tables, images. Can be used to create and fill pdf forms. It can be used to convert digital photos to PDF using C#.
Fast application programming interfaces of ByteScout PDF SDK for C# plus the instruction and the code below will help you quickly learn how to convert digital photos to PDF. This C# sample code is all you need for your app. Just copy and paste the code, add references (if needs to) and you are all set! Test C# sample code examples whether they respond your needs and requirements for the project.
Download free trial version of ByteScout PDF SDK from our website with this and other source code samples for C#.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
using System; using System.Diagnostics; using Bytescout.PDF; using Image = Bytescout.PDF.Image; namespace Images { /// <summary> /// This example demonstrates how to add images in their proper orientation and size /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Input image array var arrImages = new string[]{ "Image1.jpg", "Image2.jpg" }; // Process each image foreach (var itmImage in arrImages) { var sysImage = FixImageOrientation(itmImage); using (sysImage) { var image = new Image(sysImage, ImageCompression.DCT, 75); float w = sysImage.Width / sysImage.HorizontalResolution * 72f; float h = sysImage.Height / sysImage.VerticalResolution * 72f; // Create PDF page var page = new Page(w, h); var canvas = page.Canvas; canvas.DrawImage(image, 0, 0, w, h); // Add PDF document pdfDocument.Pages.Add(page); } } // Save PDF document pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } /// <summary> /// Fix image orientation /// </summary> static System.Drawing.Image FixImageOrientation(string fileName) { System.Drawing.Image sysImage = System.Drawing.Image.FromFile(fileName, false); // fix orientation by EXIF rotation tag const int exifRotationTag = 0x0112; int[] propertyItemIDs = sysImage.PropertyIdList; int found = Array.BinarySearch(propertyItemIDs, 0, propertyItemIDs.Length, exifRotationTag); if (found > -1) { System.Drawing.Imaging.PropertyItem pi = sysImage.GetPropertyItem(exifRotationTag); int orientation = pi.Value[0]; switch (orientation) { case 2: sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); break; case 3: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone); break; case 4: sysImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); break; case 5: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX); break; case 6: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); break; case 7: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipX); break; case 8: sysImage.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone); break; default: break; } sysImage.RemovePropertyItem(0x0112); } return sysImage; } } }
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout PDF SDK Home Page
Explore ByteScout PDF SDK Documentation
Explore Samples
Sign Up for ByteScout PDF SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: