Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use Stream in Ghostscript.Net and how to reduce pdf size? #110

Open
gyokhanmc opened this issue Mar 8, 2023 · 0 comments

Comments

@gyokhanmc
Copy link

Hello,

I am working with azure blob storage and usually with large sized scanned pdf documents.
I can reduce the size of the documents with GhostscriptProcessor, but first I need to save the document to a physical folder.
Because I'm working with blob storage and I have Stream.
Can I reduce the size of the documents with stream?
Please hep

          // "buffer" is file stream that comming from api post
        var ms = new MemoryStream();
        buffer.CopyTo(ms);

      // save file to temp physical folder
        File.WriteAllBytes(inputFile, ms.ToArray());
        ms.Close();

        GhostscriptVersionInfo gvi = new GhostscriptVersionInfo(libPath);
        GhostscriptProcessor proc = new GhostscriptProcessor(gvi);

        List<string> switches = new List<string>();
        switches.Add("-empty");
        switches.Add("-sDEVICE=pdfwrite");
        switches.Add("-dCompatibilityLevel=1.4");
        switches.Add("-dPDFSETTINGS=/ebook");
        switches.Add("-dNOPAUSE");
        switches.Add("-dQUIET");
        switches.Add("-dBATCH");
        switches.Add(@"-sOutputFile=" + outputFile);
        switches.Add(@"-f");
        switches.Add(inputFile);

      // reduce pdf size and save output to temp physical folder
        proc.Process(switches.ToArray());

     // read output file from temp physical folder
        var newStream=File.OpenRead(outputFile);
       ...
       clear temp physical folder and save output file in blob storage...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant