8 Nisan 2011 Cuma

ITextSharp Compress,Decompress PDF

İşinize yarar umuduyla kullanacağımız pdf leri compress ve decompress etmeye yarayan iki tane method...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;

        public void compressPdf(String Source, String Destination)
        {
            PdfReader reader = new PdfReader(Source);

            PdfStamper stamper = new PdfStamper(reader, new FileStream(Destination, FileMode.Create), PdfWriter.VERSION_1_7);

            stamper.Writer.CompressionLevel = 9;

            int total = reader.NumberOfPages + 1;

            for (int i = 1; i < total; i++)
            {
                reader.SetPageContent(i, reader.GetPageContent(i));
            }
            stamper.SetFullCompression();
            stamper.Close();
        }

        public void decompressPdf(String source, String Destination)
        {
            PdfReader reader = new PdfReader(source);
            PdfStamper stamper = new PdfStamper(reader, new FileStream(Destination, FileMode.Create));
            Document.Compress = false;
            int total = reader.NumberOfPages + 1;
            for (int i = 1; i < total; i++)
            {
                reader.SetPageContent(i, reader.GetPageContent(i));
            }
            stamper.Close();
            Document.Compress = true;
        }

Hiç yorum yok:

Yorum Gönder