Discussion:
[iText-questions] Reduce PDF file size
Suresh Amsala
2014-07-08 10:23:26 UTC
Permalink
Hi,

I want to compress a *PDF file size from MB's to KB's* (if the file size is
5 MB then it should be compressed in to KB's like 500 KB or 600 KB). How
can I achieve this using iTextSharp in C#.
--
Thanks and Regards
Amsala Suresh
9966151913
mkl
2014-07-08 10:42:33 UTC
Permalink
Amsala Suresh,
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?

Regards, Michael

PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like

* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
TvT
2014-07-08 11:34:29 UTC
Permalink
There are several options but mkl is right: You need to be certain that
there are unused things in your pdf.
To get an idea whats possible try the following two options in adobe
acrobat:
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size
PDF...".

In iText you got several options:

- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore

However you need to be more specific about your situation. Maybe you merged
two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?

Still some code which shows some of the stuff:

PdfStamper stamper = new PdfStamper(reader, fs,
PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();

stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Post by mkl
Amsala Suresh,
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
Suresh Amsala
2014-07-08 14:45:54 UTC
Permalink
I am uploading 20 MB pdf file it contains images and text and i want to
compress this file size to bellow 1 MB using iTextSharp in C#.

How to do this? I tried TVT's Sample code but the file does not compressing
I mean the file size is same before uploading and after uploading.
Post by TvT
There are several options but mkl is right: You need to be certain that
there are unused things in your pdf.
To get an idea whats possible try the following two options in adobe
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size
PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
Leonard Rosenthol
2014-07-08 14:55:37 UTC
Permalink
Did you try using Adobe Acrobat (even a trial version) to see if it can reduce the size of your PDFs? Depending on what is in there, and what options are important to you (embedded fonts, high quality images, etc.) it may not be possible to reduce the size.

Leonard

From: Suresh Amsala <***@gmail.com<mailto:***@gmail.com>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Tuesday, July 8, 2014 at 10:45 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size

I am uploading 20 MB pdf file it contains images and text and i want to compress this file size to bellow 1 MB using iTextSharp in C#.

How to do this? I tried TVT's Sample code but the file does not compressing I mean the file size is same before uploading and after uploading.


On Tue, Jul 8, 2014 at 5:04 PM, TvT <***@nepatec.de<mailto:***@nepatec.de>> wrote:
There are several options but mkl is right: You need to be certain that there are unused things in your pdf.
To get an idea whats possible try the following two options in adobe acrobat:
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".

In iText you got several options:

- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore

However you need to be more specific about your situation. Maybe you merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?

Still some code which shows some of the stuff:

PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();

stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();






2014-07-08 12:42 GMT+02:00 mkl <***@wir-sind-cool.org<mailto:***@wir-sind-cool.org>>:

Amsala Suresh,
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?

Regards, Michael

PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like

* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Thanks and Regards
Amsala Suresh
9966151913
Suresh Amsala
2014-07-08 15:09:35 UTC
Permalink
Dear Leonard Rosenthol,

I didn't try using Adobe Acrobat but i want to do through programmatically
not manually why because that is not a fixed size it may vary and the files
should be uploaded by users.

The quality should maintain 70%-80% compare to original pdf.The remaining
things I don't mine like fonts,headers etc.
Post by Leonard Rosenthol
Did you try using Adobe Acrobat (even a trial version) to see if it can
reduce the size of your PDFs? Depending on what is in there, and what
options are important to you (embedded fonts, high quality images, etc.) it
may not be possible to reduce the size.
Leonard
Date: Tuesday, July 8, 2014 at 10:45 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
I am uploading 20 MB pdf file it contains images and text and i want to
compress this file size to bellow 1 MB using iTextSharp in C#.
How to do this? I tried TVT's Sample code but the file does not
compressing I mean the file size is same before uploading and after
uploading.
Post by TvT
There are several options but mkl is right: You need to be certain
that there are unused things in your pdf.
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file
size
Post by Suresh Amsala
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
TvT
2014-07-08 15:18:27 UTC
Permalink
Ok Suresh,

that is not possible. Some pdfs do not contain any images, nor any unused
objects - size reduction is not possible in that case even if the pdf is
200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only)
contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final
size will be much smaller...?

You need to be more specific here...
Post by Suresh Amsala
Dear Leonard Rosenthol,
I didn't try using Adobe Acrobat but i want to do through
programmatically not manually why because that is not a fixed size it may
vary and the files should be uploaded by users.
The quality should maintain 70%-80% compare to original pdf.The remaining
things I don't mine like fonts,headers etc.
Post by Leonard Rosenthol
Did you try using Adobe Acrobat (even a trial version) to see if it can
reduce the size of your PDFs? Depending on what is in there, and what
options are important to you (embedded fonts, high quality images, etc.) it
may not be possible to reduce the size.
Leonard
Date: Tuesday, July 8, 2014 at 10:45 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
I am uploading 20 MB pdf file it contains images and text and i want
to compress this file size to bellow 1 MB using iTextSharp in C#.
How to do this? I tried TVT's Sample code but the file does not
compressing I mean the file size is same before uploading and after
uploading.
Post by TvT
There are several options but mkl is right: You need to be certain
that there are unused things in your pdf.
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file
size
Post by Suresh Amsala
is 5 MB then it should be compressed in to KB's like 500 KB or 600
KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
Leonard Rosenthol
2014-07-08 15:34:57 UTC
Permalink
I understand your end goal – but doing that ONCE will show if it’s even possible to reduce the size of your file…

As we’ve been trying to explain, there are MANY THINGS that you could POSSIBLY do to reduce a PDFs size…BUT ONLY YOU can decide which ones you are willing to accept and then if those choices will enable the results you want.

Leonard

From: TvT <***@nepatec.de<mailto:***@nepatec.de>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Tuesday, July 8, 2014 at 11:18 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size

Ok Suresh,

that is not possible. Some pdfs do not contain any images, nor any unused objects - size reduction is not possible in that case even if the pdf is 200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only) contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final size will be much smaller...?

You need to be more specific here...



2014-07-08 17:09 GMT+02:00 Suresh Amsala <***@gmail.com<mailto:***@gmail.com>>:
Dear Leonard Rosenthol,

I didn't try using Adobe Acrobat but i want to do through programmatically not manually why because that is not a fixed size it may vary and the files should be uploaded by users.

The quality should maintain 70%-80% compare to original pdf.The remaining things I don't mine like fonts,headers etc.


On Tue, Jul 8, 2014 at 8:25 PM, Leonard Rosenthol <***@adobe.com<mailto:***@adobe.com>> wrote:
Did you try using Adobe Acrobat (even a trial version) to see if it can reduce the size of your PDFs? Depending on what is in there, and what options are important to you (embedded fonts, high quality images, etc.) it may not be possible to reduce the size.

Leonard

From: Suresh Amsala <***@gmail.com<mailto:***@gmail.com>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Tuesday, July 8, 2014 at 10:45 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size

I am uploading 20 MB pdf file it contains images and text and i want to compress this file size to bellow 1 MB using iTextSharp in C#.

How to do this? I tried TVT's Sample code but the file does not compressing I mean the file size is same before uploading and after uploading.


On Tue, Jul 8, 2014 at 5:04 PM, TvT <***@nepatec.de<mailto:***@nepatec.de>> wrote:
There are several options but mkl is right: You need to be certain that there are unused things in your pdf.
To get an idea whats possible try the following two options in adobe acrobat:
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".

In iText you got several options:

- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore

However you need to be more specific about your situation. Maybe you merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?

Still some code which shows some of the stuff:

PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();

stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();






2014-07-08 12:42 GMT+02:00 mkl <***@wir-sind-cool.org<mailto:***@wir-sind-cool.org>>:

Amsala Suresh,
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?

Regards, Michael

PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like

* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Thanks and Regards
Amsala Suresh
9966151913

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Thanks and Regards
Amsala Suresh
9966151913

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Carlos Arturo Bernal Carvajal
2014-07-08 15:38:51 UTC
Permalink
You could try using Ghostscript after generating the PDF width iText.
http://www.ghostscript.com/

It works really good for me. I work at a photobook internet company and we
generate the print PDF's using iText, but the output can be huge, like
500mb, so we use Ghostscript to compress the resulting file.

We use the following command;

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -dPDFSETTINGS=/prepress
-sDefaultRGBProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/AdobeRGB1998.icc
-sDefaultCMYKProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc
-dOverrideICC=true
-sOutputICCProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc
-dNOPAUSE -dQUIET -dBATCH -sOutputFile="${file/.pdf/}_optimized.pdf" "$file"
Post by TvT
Ok Suresh,
that is not possible. Some pdfs do not contain any images, nor any unused
objects - size reduction is not possible in that case even if the pdf is
200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only)
contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final
size will be much smaller...?
You need to be more specific here...
Dear Leonard Rosenthol,
Post by Suresh Amsala
I didn't try using Adobe Acrobat but i want to do through
programmatically not manually why because that is not a fixed size it may
vary and the files should be uploaded by users.
The quality should maintain 70%-80% compare to original pdf.The remaining
things I don't mine like fonts,headers etc.
Post by Leonard Rosenthol
Did you try using Adobe Acrobat (even a trial version) to see if it
can reduce the size of your PDFs? Depending on what is in there, and what
options are important to you (embedded fonts, high quality images, etc.) it
may not be possible to reduce the size.
Leonard
Date: Tuesday, July 8, 2014 at 10:45 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
I am uploading 20 MB pdf file it contains images and text and i want
to compress this file size to bellow 1 MB using iTextSharp in C#.
How to do this? I tried TVT's Sample code but the file does not
compressing I mean the file size is same before uploading and after
uploading.
Post by TvT
There are several options but mkl is right: You need to be certain
that there are unused things in your pdf.
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file
size
Post by Suresh Amsala
is 5 MB then it should be compressed in to KB's like 500 KB or 600
KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Carlos Bernal
Leonard Rosenthol
2014-07-08 15:52:32 UTC
Permalink
Just remember that doing that is considered a REFRYING operation and is quite LOSSY. If that’s OK for your content – feel free, but just make sure you understand the risks involved in doing so.

Leonard

From: Carlos Arturo Bernal Carvajal <***@gmail.com<mailto:***@gmail.com>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Tuesday, July 8, 2014 at 11:38 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size

You could try using Ghostscript after generating the PDF width iText. http://www.ghostscript.com/

It works really good for me. I work at a photobook internet company and we generate the print PDF's using iText, but the output can be huge, like 500mb, so we use Ghostscript to compress the resulting file.

We use the following command;

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -dPDFSETTINGS=/prepress -sDefaultRGBProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/AdobeRGB1998.icc -sDefaultCMYKProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc -dOverrideICC=true -sOutputICCProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${file/.pdf/}_optimized.pdf" "$file"


2014-07-08 10:18 GMT-05:00 TvT <***@nepatec.de<mailto:***@nepatec.de>>:
Ok Suresh,

that is not possible. Some pdfs do not contain any images, nor any unused objects - size reduction is not possible in that case even if the pdf is 200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only) contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final size will be much smaller...?

You need to be more specific here...



2014-07-08 17:09 GMT+02:00 Suresh Amsala <***@gmail.com<mailto:***@gmail.com>>:

Dear Leonard Rosenthol,

I didn't try using Adobe Acrobat but i want to do through programmatically not manually why because that is not a fixed size it may vary and the files should be uploaded by users.

The quality should maintain 70%-80% compare to original pdf.The remaining things I don't mine like fonts,headers etc.


On Tue, Jul 8, 2014 at 8:25 PM, Leonard Rosenthol <***@adobe.com<mailto:***@adobe.com>> wrote:
Did you try using Adobe Acrobat (even a trial version) to see if it can reduce the size of your PDFs? Depending on what is in there, and what options are important to you (embedded fonts, high quality images, etc.) it may not be possible to reduce the size.

Leonard

From: Suresh Amsala <***@gmail.com<mailto:***@gmail.com>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Tuesday, July 8, 2014 at 10:45 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size

I am uploading 20 MB pdf file it contains images and text and i want to compress this file size to bellow 1 MB using iTextSharp in C#.

How to do this? I tried TVT's Sample code but the file does not compressing I mean the file size is same before uploading and after uploading.


On Tue, Jul 8, 2014 at 5:04 PM, TvT <***@nepatec.de<mailto:***@nepatec.de>> wrote:
There are several options but mkl is right: You need to be certain that there are unused things in your pdf.
To get an idea whats possible try the following two options in adobe acrobat:
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".

In iText you got several options:

- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore

However you need to be more specific about your situation. Maybe you merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?

Still some code which shows some of the stuff:

PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();

stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();






2014-07-08 12:42 GMT+02:00 mkl <***@wir-sind-cool.org<mailto:***@wir-sind-cool.org>>:

Amsala Suresh,
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file size
is 5 MB then it should be compressed in to KB's like 500 KB or 600 KB).
What information in those PDFs is superfluous in your context and can be
thrown away?

Regards, Michael

PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like

* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Thanks and Regards
Amsala Suresh
9966151913

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Thanks and Regards
Amsala Suresh
9966151913

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php



--
Carlos Bernal
Suresh Amsala
2014-07-08 16:29:41 UTC
Permalink
Is there any way for do that without REFRYING operation.
Post by Leonard Rosenthol
Just remember that doing that is considered a REFRYING operation and is
quite LOSSY. If that's OK for your content - feel free, but just make sure
you understand the risks involved in doing so.
Leonard
Date: Tuesday, July 8, 2014 at 11:38 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
You could try using Ghostscript after generating the PDF width iText.
http://www.ghostscript.com/
It works really good for me. I work at a photobook internet company and
we generate the print PDF's using iText, but the output can be huge, like
500mb, so we use Ghostscript to compress the resulting file.
We use the following command;
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 -dPDFSETTINGS=/prepress
-sDefaultRGBProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/AdobeRGB1998.icc
-sDefaultCMYKProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc
-dOverrideICC=true
-sOutputICCProfile=/home/ubuntu/cronjob_autopdf_pixote2/colorProfiles/CoatedFOGRA39.icc
-dNOPAUSE -dQUIET -dBATCH -sOutputFile="${file/.pdf/}_optimized.pdf" "$file"
Post by TvT
Ok Suresh,
that is not possible. Some pdfs do not contain any images, nor any
unused objects - size reduction is not possible in that case even if the
pdf is 200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only)
contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final
size will be much smaller...?
You need to be more specific here...
Dear Leonard Rosenthol,
Post by Suresh Amsala
I didn't try using Adobe Acrobat but i want to do through
programmatically not manually why because that is not a fixed size it may
vary and the files should be uploaded by users.
The quality should maintain 70%-80% compare to original pdf.The
remaining things I don't mine like fonts,headers etc.
Post by Leonard Rosenthol
Did you try using Adobe Acrobat (even a trial version) to see if it
can reduce the size of your PDFs? Depending on what is in there, and what
options are important to you (embedded fonts, high quality images, etc.) it
may not be possible to reduce the size.
Leonard
Date: Tuesday, July 8, 2014 at 10:45 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
I am uploading 20 MB pdf file it contains images and text and i want
to compress this file size to bellow 1 MB using iTextSharp in C#.
How to do this? I tried TVT's Sample code but the file does not
compressing I mean the file size is same before uploading and after
uploading.
Post by TvT
There are several options but mkl is right: You need to be certain
that there are unused things in your pdf.
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file
size
Post by Suresh Amsala
is 5 MB then it should be compressed in to KB's like 500 KB or 600
KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality
replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Carlos Bernal
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
TvT
2014-07-09 08:00:17 UTC
Permalink
Leonard, didn't know at first what you meant with "refrying" but found this
article of yours which explains it quite well :-)
http://www.gwg.org/wp-content/uploads/attachments/f121c163fa679f86977235da32290812.pdf

@Suresh
70%-80% migth be possible in certain rare cases (lots of thrash or
redundant information, really big images etc) - but will never be possible
in other cases.
I mean if you want to reduce the size of your pdf we could also tell you to
cut of pages until your pdf has the right size.

Ok, seriously: We have mentioned several ways depending what content your
pdf has:
- you may shrink the size/compress the images inside your PDF (e.g.:
http://stackoverflow.com/questions/15129025/reduce-image-size-bytes-in-itextpdf
)
- you may enable compression for the pdf itself (e.g.
http://stackoverflow.com/questions/14354712/how-to-reduce-pdf-file-size-programmatically-in-java
)
- you may throw away certain things like UnusedObjects, Annoations,
FormFields, Fonts etc. (but some of those will have certain consequence)

UnsedObjects and form fields:
http://stackoverflow.com/questions/18397502/formflattening-and-file-size-reduction-unreferenced-objects
Fonts: http://itextpdf.com/sandbox/fonts/UnembedFont
Attachments: http://sourceforge.net/p/itext/mailman/message/21465673/
Annotations:
http://stackoverflow.com/questions/18974031/how-do-i-remove-link-annotations-from-a-pdf-using-itext
Suresh Amsala
2014-07-08 15:43:31 UTC
Permalink
Dear TVT,

Thanks for Reply. Some of the pdf's contains images and text and some of
them are contains plain text some of them both. So, what ever the pdf's
content I want to compress it to KB's and quality should be 70%-80%.
Post by TvT
Ok Suresh,
that is not possible. Some pdfs do not contain any images, nor any unused
objects - size reduction is not possible in that case even if the pdf is
200 MB.
I am guessing you want to reduce the size of Pdfs which mostly (or only)
contain images (e.g. PDFs created from a scanner etc).
You want to reduce the quality of the contained images so that the final
size will be much smaller...?
You need to be more specific here...
Dear Leonard Rosenthol,
Post by Suresh Amsala
I didn't try using Adobe Acrobat but i want to do through
programmatically not manually why because that is not a fixed size it may
vary and the files should be uploaded by users.
The quality should maintain 70%-80% compare to original pdf.The remaining
things I don't mine like fonts,headers etc.
Post by Leonard Rosenthol
Did you try using Adobe Acrobat (even a trial version) to see if it
can reduce the size of your PDFs? Depending on what is in there, and what
options are important to you (embedded fonts, high quality images, etc.) it
may not be possible to reduce the size.
Leonard
Date: Tuesday, July 8, 2014 at 10:45 AM
Subject: Re: [iText-questions] [SPAM] Re: Reduce PDF file size
I am uploading 20 MB pdf file it contains images and text and i want
to compress this file size to bellow 1 MB using iTextSharp in C#.
How to do this? I tried TVT's Sample code but the file does not
compressing I mean the file size is same before uploading and after
uploading.
Post by TvT
There are several options but mkl is right: You need to be certain
that there are unused things in your pdf.
"File > Save As > Optimized PDF...", and "File > Save As > Reduced Size PDF...".
- enable compression
- remove unused objects
- remove fields, annotations etc. if you don't need those anymore
However you need to be more specific about your situation. Maybe you
merged two PDFs and didn't used PdfCopy instead of PdfSmartCopy - who knows?
PdfStamper stamper = new PdfStamper(reader, fs, PdfWriter.VERSION_1_5);PdfWriter writer = stamper.Writer;
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
writer.CompressionLevel = pdf.PdfStream.BEST_COMPRESSION;
reader.RemoveFields();
reader.RemoveUnusedObjects();
stamper.Reader.RemoveUnusedObjects();
stamper.SetFullCompression();
stamper.Writer.SetFullCompression();
stamper.Close();
Amsala Suresh,
Post by mkl
Post by Suresh Amsala
I want to compress a *PDF file size from MB's to KB's* (if the file
size
Post by Suresh Amsala
is 5 MB then it should be compressed in to KB's like 500 KB or 600
KB).
What information in those PDFs is superfluous in your context and can be
thrown away?
Regards, Michael
PS: Knowing nothing about the PDFs in question it is hard to tell whether or
not they can be compressed at all. There of course are some techniques like
* replacing images with lower-resolution or lower-quality replacements (but
you have not told us whether there are images in those PDFs and whether they
may be downgraded);
* removing embedded fonts if you know they are available to the target
audience PDF viewers and provide the required information (but you have not
told us whether there are such embedded fonts);
* re-compressing the streams at highest compression setting and switching to
object streams (but the files may already use those settings);
* hunting for duplicate objects like identical header images included
separately in the file (but you have not indicated whether there are such
duplicates)...
--
http://itext-general.2136553.n4.nabble.com/Reduce-PDF-file-size-tp4660118p4660119.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
iText-questions mailing list
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a
reference to the iText book: http://www.itextpdf.com/book/
http://itextpdf.com/themes/keywords.php
--
Thanks and Regards
Amsala Suresh
9966151913
Loading...