PDF Mosaic: How to compress PDF document


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code

 

This sample shows how to create PDF documents with different compressions using PDFMosaic library. Theare are 2 type of corpessions: PDFCompression.None and PDFCompression.Flate. All PDF documents are created with PDFCompression.Flate by default.

All PDF documents are created with PDFCompression.Flate by default
 

PDFDocument document = new PDFDocument();
PDFPage page = new PDFPage(PDFPaperFormat.A4);
 
PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 11);
PDFBrush brush = new PDFSolidBrush();
 
page.Canvas.DrawString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.", font, brush, 10, 10);
page.Canvas.DrawString("Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,", font, brush, 10, 25);
page.Canvas.DrawString("when an unknown printer took a galley of type and scrambled it to make a type specimen book. ", font, brush, 10, 40);
page.Canvas.DrawString("It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.", font, brush, 10, 55);
page.Canvas.DrawString("It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, ", font, brush, 10, 70);
page.Canvas.DrawString("and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", font, brush, 10, 85);
 
page.Canvas.DrawString("Contrary to popular belief, Lorem Ipsum is not simply random text. ", font, brush, 10, 100);
page.Canvas.DrawString("It has roots in a piece of classical Latin literature from 45 BC, ", font, brush, 10, 115);
page.Canvas.DrawString("making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia,", font, brush, 10, 130);
page.Canvas.DrawString("looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, ", font, brush, 10, 145);
page.Canvas.DrawString("and going through the cites of the word in classical literature, discovered the undoubtable source.", font, brush, 10, 160);
page.Canvas.DrawString("Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) ", font, brush, 10, 175);
page.Canvas.DrawString("by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. ", font, brush, 10, 190);
page.Canvas.DrawString("The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.", font, brush, 10, 205);
 
for (int i = 0; i < 50; ++i)
{
    document.Pages.Add(page);
}
 
document.Compression = PDFCompression.None;
document.Save("CreateCompressionNone.pdf", true);
 
document.Compression = PDFCompression.Flate;
document.Save("CreateCompressionFlate.pdf", true);

 


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code