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.
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 ?

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 an 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

 

Article ID: Published Date: Last Revised Date: Platform: Control:
6029 01/20/2016 01/20/2016 WinForms PDF
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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