Create multipage tiff to pdf with pdf sdk is simple to apply in C# if you use these source codes below. ByteScout PDF Suite: the bundle that provides six different SDK libraries to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript. It can create multipage tiff to pdf with pdf sdk in C#.
The following code snippet for ByteScout PDF Suite works best when you need to quickly create multipage tiff to pdf with pdf sdk in your C# application. 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! Enjoy writing a code with ready-to-use sample C# codes.
The trial version of ByteScout PDF 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)
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 Suite Home Page
Explore ByteScout PDF Suite Documentation
Explore Samples
Sign Up for ByteScout PDF Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout PDF Suite Home Page
Explore ByteScout PDF Suite Documentation
Explore Samples
Sign Up for ByteScout PDF Suite Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
also available as: