1

I have a pdf template of size 230KB. In my WebAPI for multiple users, taking copy of that template pushing data to it, and merging using iTextsharp library. For 1500 users, total file size is reaching up to 320 MB.

I tried using BitMiracle, it reduced the file size to 160 MB. But it is still a large file.

I used acrobat Pro and used Save as Other option Reduced Size PDF, it reduced file size to 25 MB.

I want to decrease the file size to 25MB in my WebAPI using C# which will be hosted on server later.

As user is not supposed to edit that PDF, he will just store it as a record. Can i generate a post script file and then use acrobat distiller to decrease the size?If yes, how can I do it?

I am using ghostscript.Net. Wrote this method, it is not throwing any error. But i am unable to find the path of generated postscript file

    public void convertToPs(string file)
    {
        try
        {
            Process printProcess = new Process();

            printProcess.StartInfo.FileName = file;
            printProcess.StartInfo.Verb = "printto";
            printProcess.StartInfo.Arguments = "\"Ghostscript PDF\"";
            printProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            printProcess.StartInfo.CreateNoWindow = true;
            printProcess.Start();

            // Wait until the PostScript file is created
            try
            {
                printProcess.WaitForExit();
            }
            catch (InvalidOperationException) { }

            printProcess.Dispose();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Please help

trailmax
  • 34,305
  • 22
  • 140
  • 234
AkankshaGupta
  • 121
  • 1
  • 10
  • 1
    So you have 1500 users all writing into a single PDF? - One solution is to not do that. (i.e. generating on-demand only) – Alex K. Jul 20 '17 at 14:03
  • Actually WebAPI code writing to PDF. So 1500 copies being generated, merged into single PDF as output – AkankshaGupta Jul 20 '17 at 14:12
  • What kind of data is pushing into the pdfs? – Ben Jul 20 '17 at 14:12
  • As it is a template, using key value pair, integer and strings getting pushed to PDF – AkankshaGupta Jul 20 '17 at 14:14
  • Is there a change to reduce the size of the template (reduce images,...)? – Ben Jul 20 '17 at 14:16
  • No, we do not have any image in template. – AkankshaGupta Jul 20 '17 at 14:27
  • 1
    I think without any code it is hard to help you. Please add your code and what you have tried. – Ben Jul 20 '17 at 15:06
  • Converting a PDF to PostScript has inherent risks, since the graphics model is not identical. You could try using Ghostsctript to take the PDF as an input and write a new PDF as output. That often reduces the size of files and doesn't involve a conversion to PostScript. Note that GS is licensed under the AGPL, in case that has implications for your usage. You should probably also look at Ghostscript.NET rather than Ghostscript itself, since you want to use C# – KenS Jul 20 '17 at 16:28
  • @Ben,@KenS edited the question and added my code. Help me out – AkankshaGupta Jul 24 '17 at 13:16
  • I can not find generated post script file. I am not sure whether postscript getting generated or not. – AkankshaGupta Jul 27 '17 at 11:29

1 Answers1

0

Does the template has embedded Fonts? Probably the merging doesn't combine those fonts. If you don't need embedded Fonts you could remove them. Adobe does some good work in combining embedded fonts.

If you want you can send me such a big pdf document, so that i can understand, why this file is getting so big. I am a developer of a PDF library and getting the smallest PDF is one interesting usecase i am working on.

PatrickF
  • 594
  • 2
  • 11