ByteScout Premium Suite - C# - Convert digital photos to pdf with pdf sdk - ByteScout

ByteScout Premium Suite – C# – Convert digital photos to pdf with pdf sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Premium Suite – C# – Convert digital photos to pdf with pdf sdk

How to convert digital photos to pdf with pdf sdk in C# and ByteScout Premium Suite

If you want to learn more then this tutorial will show how to convert digital photos to pdf with pdf sdk in C#

These sample source codes on this page below are displaying how to convert digital photos to pdf with pdf sdk in C#. ByteScout Premium Suite is the set that includes 12 SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording. It can be applied to convert digital photos to pdf with pdf sdk using C#.

Want to quickly learn? This fast application programming interfaces of ByteScout Premium Suite for C# plus the guidelines and the code below will help you quickly learn how to convert digital photos to pdf with pdf sdk. Follow the instructions from scratch to work and copy the C# code. Applying C# application mostly includes various stages of the software development so even if the functionality works please test it with your data and the production environment.

The trial version of ByteScout Premium Suite can be downloaded for free from our website. It also includes source code samples for C# and other programming languages.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.cs
      
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; } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next