简体   繁体   中英

Ghostscript PDF to TIFF setting output size c#

I have a pdf of 22 pages. I am using GhostScript to convert the PDF to TIFF to be used by Tesseract. I did this...

  string filename=openFileDialog1.FileName;

  using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
            {
                rasterizer.Open(filename, _lastInstalledVersion, false);
                for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
                {
                  Image img = rasterizer.GetPage(400, 400, pageNumber);  
                }

I want to set the img size before I pass it to be used by Tesseract but I cant.. Is there any way?

There is this example: but idk if I can pass each image from the pdf to be used by Tesseract

  GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion();

        using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
        {
            processor.Processing += new GhostscriptProcessorProcessingEventHandler(processor_Processing);

            List<string> switches = new List<string>();
            switches.Add("-empty");
            switches.Add("-dSAFER");
            switches.Add("-dBATCH");
            switches.Add("-dNOPAUSE");
            switches.Add("-dNOPROMPT");
            switches.Add(@"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts));
            switches.Add("-dFirstPage=" + pageFrom.ToString());
            switches.Add("-dLastPage=" + pageTo.ToString());
            switches.Add("-sDEVICE=png16m");
            switches.Add("-r96");
            switches.Add("-dTextAlphaBits=4");
            switches.Add("-dGraphicsAlphaBits=4");

            //switches.Add("-sDEVICE=pdfwrite");

            switches.Add(@"-sOutputFile=" + outputFile);
            switches.Add(@"-f");
            switches.Add(inputFile);

            processor.StartProcessing(switches.ToArray(), null);
        }
    }

-dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS, along with -dFIXEDMEDIA will set a specific media size. You'll probably want to set -dPDFFitPage as well to scale the content onto the new media.

You can't be using Ghostscript directly, are you using jhabjan's Ghostscript.net ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM