How to resize pdf file using iTextSharp

I have a bunch of PDF files that I'm just trying to open, resize the page, and then save. I also hope that file sizes will be significantly reduced. I use iTextSharp and the resizing is just fine, but the file size is almost identical, in fact it is a bit larger. Here I have a function:

Dim reader As New PdfReader(inPDF) Dim doc As New Document(PageSize.LETTER) Document.Compress = True Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(outPDF, FileMode.Create)) doc.Open() Dim cb As PdfContentByte = writer.DirectContent Dim page As PdfImportedPage For pageNumber As Long = 1 To reader.NumberOfPages page = writer.GetImportedPage(reader, pageNumber) cb.AddTemplate(page, PageSize.LETTER.Width / reader.GetPageSize(pageNumber).Width, 0, 0, PageSize.LETTER.Height / reader.GetPageSize(pageNumber).Height, 0, 0) doc.NewPage() Next pageNumber doc.Close() 

Does anyone know what I can lose to actually get the file size?

Thanks.

+4
source share
1 answer

Reducing page size simply reduces page size; you do not delete any content, so the file size will not change.

There are three ways to reduce file size; remove the content, make sure the text objects are compressed and / or make sure the images are effective.

By effective images, I mean that the images are no bigger than they should be, and that the correct type of compression is used. You can use a huge image, say 1800 pixels wide, and scale it to 2.5 inches in pdf format. If you do this, it will still have a width of 1800 pixels, even if it appears as 2.5 inches wide. size by resizing the image β€” in this case, for a print resolution of 300 dpi, it should be only 750 pixels. For standard PDF resolution with a resolution of 72 dpi, you only need an image with a width of 202 pixels.

Many programs that generate PDF files automatically use jpeg. If the image has 2 colors, for example, an invoice or verification check, using tiff with G4 compression will make the file size much smaller than jpeg.

+2
source

All Articles