)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to reduce the file size when drawing the TIFF image into PDF document ?

Platform: WinForms |
Control: PDF |
Published Date: January 20, 2016 |
Last Revised Date: May 6, 2019

How to reduce the file size when drawing the TIFF image into PDF document?

To reduce the file size when drawing the TIFF image (which contains large no of frames) into PDF document, we can save each frame to Jpeg format and then draw the image into PDF document.

Please refer to the below code example how to draw the TIFF image into PDF document:

C#

//Create a PDF document
Syncfusion.Pdf.PdfDocument document = new Syncfusion.Pdf.PdfDocument();
document.PageSettings.SetMargins(0f);
//Load the image
using (System.Drawing.Image imageFile = System.Drawing.Image.FromFile("../../Data/image.tiff"))
{
FrameDimension frameDimensions = new FrameDimension(
imageFile.FrameDimensionsList[0]);
//Get frame count
int frameNumber = imageFile.GetFrameCount(frameDimensions);
for (int frame = 0; frame < frameNumber; frame++)
{
// Selects one frame at a time and save as Jpeg.
imageFile.SelectActiveFrame(frameDimensions, frame);
MemoryStream ms = new MemoryStream();
//save the frame as Jpeg image
using (Bitmap bmp = new Bitmap(imageFile))
{
ImageCodecInfo encoderInfo = this.GetEncoderInfo("image/jpeg");
EncoderParameters encoderParams = new EncoderParameters(1);
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 50L);
bmp.Save(ms, encoderInfo, encoderParams);
bmp.Dispose();
}
ms.Position = 0;
//Load the Jpeg image
PdfBitmap image = new PdfBitmap(ms);
//Add the page
Syncfusion.Pdf.PdfPage page = document.Pages.Add();
//Create a PDF graphics
PdfGraphics g = page.Graphics;
//Draw the image into PDF page
g.DrawImage(image, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
//Dispose the memory
ms.Dispose();
}
}
// Save and close the document.
document.Save("Output.pdf");
document.Close(true);

 

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/TIFFtoPDFSample-892388088.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon