PdfDocument document = new PdfDocument();
//Load the multi frame TIFF image from the disk
FileStream imageStream = new FileStream("D://TiffImage.tiff", FileMode.Open, FileAccess.Read);
PdfTiffImage tiffImage = new PdfTiffImage(imageStream);
//Get the frame count
int frameCount = tiffImage.FrameCount;
//Access each frame and draw into the page
for (int i = 0; i < frameCount; i++)
{
//Add a section to the PDF document
PdfSection section = document.Sections.Add();
//Set page margins
section.PageSettings.Margins.All = 0;
tiffImage.ActiveFrame = i;
//Create a PDF unit converter instance
PdfUnitConvertor converter = new PdfUnitConvertor();
//Convert to point
Syncfusion.Drawing.SizeF size = converter.ConvertFromPixels(tiffImage.PhysicalDimension, PdfGraphicsUnit.Point);
//Set page orientation
section.PageSettings.Orientation = (size.Width > size.Height) ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait;
//Set page size
section.PageSettings.Size = size;
//Add a page to the section
PdfPage page = section.Pages.Add();
//Draw TIFF image into the PDF page
page.Graphics.DrawImage(tiffImage, Syncfusion.Drawing.PointF.Empty, size);
}
//Creating the stream object
FileStream fileStream = new FileStream("TiffToPDF.pdf", FileMode.Create, FileAccess.ReadWrite);
//Save and close the PDF document
document.Save(fileStream);
document.Close(true);
|