ByteScout Premium Suite - C# - Create multipage tiff to pdf with pdf sdk - ByteScout

ByteScout Premium Suite – C# – Create multipage tiff to pdf with pdf sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Premium Suite – C# – Create multipage tiff to pdf with pdf sdk

How to create multipage tiff to pdf with pdf sdk in C# and ByteScout Premium Suite

Continuous learning is a crucial part of computer science and this tutorial shows how to create multipage tiff to pdf with pdf sdk in C#

The sample source codes on this page shows how to create multipage tiff to pdf with pdf sdk in C#. ByteScout Premium Suite can create multipage tiff to pdf with pdf sdk. It can be applied from 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.

These C# code samples for C# guide developers to speed up coding of the application when using ByteScout Premium Suite. 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.

ByteScout Premium Suite free trial version is available on our website. C# and other programming languages are supported.

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 System.Drawing; using System.Drawing.Imaging; using System.IO; using Bytescout.PDF; using Image = Bytescout.PDF.Image; namespace Images { /// <summary> /// This example demonstrates how to create PDF from multipage TIFF image. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Get Tiff file in Bitmap Bitmap multipageTiffImage = (Bitmap)System.Drawing.Image.FromFile("MultipageTiffFile.tiff"); // Tiff images can contain multiple images named as frame int count = multipageTiffImage.GetFrameCount(FrameDimension.Page); for (int idx = 0; idx < count; idx++) { // save each frame to a bytestream multipageTiffImage.SelectActiveFrame(FrameDimension.Page, idx); MemoryStream byteStream = new MemoryStream(); multipageTiffImage.Save(byteStream, ImageFormat.Tiff); // Fix Image Orientation var sysImage = FixImageOrientation(byteStream); 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 document to file 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(Stream fileStream) { System.Drawing.Image sysImage = System.Drawing.Image.FromStream(fileStream, false, 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) { PropertyItem pi = sysImage.GetPropertyItem(exifRotationTag); int orientation = pi.Value[0]; switch (orientation) { case 2: sysImage.RotateFlip(RotateFlipType.RotateNoneFlipX); break; case 3: sysImage.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 4: sysImage.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case 5: sysImage.RotateFlip(RotateFlipType.Rotate90FlipX); break; case 6: sysImage.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case 7: sysImage.RotateFlip(RotateFlipType.Rotate270FlipX); break; case 8: sysImage.RotateFlip(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