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