ByteScout PDF SDK - C# - Create Multipage Tiff to PDF - ByteScout

ByteScout PDF SDK – C# – Create Multipage Tiff to PDF

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Create Multipage Tiff to PDF

How to create multipage tiff to PDF in C# using ByteScout PDF SDK

This code in C# shows how to create multipage tiff to PDF with this how to tutorial

Learn how to create multipage tiff to PDF in C# with this source code sample. ByteScout PDF SDK is the component to help programmers in generating new pdf files, modifying and updating existing pdf documents or pdf forms. Provides support for auto-filling pdf forms, adding text with adjustable font, style, size, font family, new form fields, vector and raster drawings. It can create multipage tiff to PDF in C#.

This code snippet below for ByteScout PDF SDK works best when you need to quickly create multipage tiff to PDF in your C# application. In your C# project or application you may simply copy & paste the code and then run your app! You can use these C# sample examples in one or many applications.

Trial version of ByteScout PDF SDK can be downloaded for free from our website. It also includes source code samples for C# and other programming languages.

Try ByteScout PDF SDK today: Get 60 Day Free Trial or sign up for Web API

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; } } }

Try ByteScout PDF SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)



Get 60 Day Free Trial or Visit ByteScout PDF SDK page

Explore ByteScout PDF SDK documentation


Sign Up for free Web API key

Explore Web API Documentation