Articles in this section
Category / Section

How to Reduce the File Size When Drawing TIFF Image in WinForms PDF?

3 mins read

To reduce the file size when drawing the TIFF image (which contains large no of frames) into PDF document in WinForms PDF, 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:

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

Conclusion

I hope you enjoyed learning about how to educe the file size when drawing the TIFF image in WinForms PDF.

You can refer to our  WinForms PDF feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied