private void Start2() { string inputFile = @"E:\__test_data\i1.pdf"; string outputFile = @"E:\gss_test\output\page-%03d.png"; GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); using (GhostscriptProcessor processor = new GhostscriptProcessor()) { //"C:\Program Files\gs\gs9.15\bin\gswin64.exe" -sDEVICE=tiff24nc -r300 -dNOPAUSE -dBATCH -sOutputFile="Invoice 1_%03ld.tiff" "Invoice 1.pdf" List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-dPrinted"); switches.Add("-sDEVICE=pdfwrite"); //switches.Add("-sDEVICE=tiffsep1"); switches.Add("-sOutputFile=" + outputPipeHandle); //switches.Add("-q"); switches.Add("-f"); switches.Add(inputFile); try { processor.Process(switches.ToArray()); byte[] rawDocumentData = gsPipedOutput.Data; var memStream = new MemoryStream(rawDocumentData); //var image = new Bitmap(memStream); //image.Save(@"Invocie 1.tiff"); //if (writeToDatabase) //{ // Database.ExecSP("add_document", rawDocumentData); //} //else if (writeToDisk) //{ // File.WriteAllBytes(@"E:\gss_test\output\test_piped_output.pdf", rawDocumentData); //} } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { gsPipedOutput.Dispose(); gsPipedOutput = null; } } }
public void Start() { string inputFile = @"E:\gss_test\test.pdf"; string outputFile = @"E:\gss_test\output\page-%03d.png"; int pageFrom = 1; int pageTo = 50; using (GhostscriptProcessor ghostscript = new GhostscriptProcessor()) { ghostscript.Processing += new GhostscriptProcessorProcessingEventHandler(ghostscript_Processing); List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); 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(@"-sOutputFile=" + outputFile); switches.Add(@"-f"); switches.Add(inputFile); ghostscript.Process(switches.ToArray()); } }
public void Start() { // For users who distribute their gsdll32.dll or gsdll64.dll with their application: Ghostscript.NET by default // peeks into the registry to collect all installed Ghostscript locations. If you want to use ghostscript dll from // a custom location, it's recommended to do something like this: GhostscriptVersionInfo gvi = new GhostscriptVersionInfo( new Version(0, 0, 0), @"e:\dumyfolder\myapplication\gsdll32.dll", string.Empty, GhostscriptLicense.GPL); // and then pass that GhostscriptVersionInfo to required constructor or method // sample #1 GhostscriptProcessor proc = new GhostscriptProcessor(gvi); // sample #2 GhostscriptRasterizer rast = new GhostscriptRasterizer(); rast.Open("test.pdf", gvi, true); // sample #3 GhostscriptViewer view = new GhostscriptViewer(); view.Open("test.pdf", gvi, true); }
public void Start() { string inputFile = @"E:\gss_test\test_postscript.ps"; GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); // pipe handle format: %handle%hexvalue string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPROMPT"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-o" + outputPipeHandle); switches.Add("-q"); switches.Add("-f"); switches.Add(inputFile); try { processor.StartProcessing(switches.ToArray(), null); byte[] rawDocumentData = gsPipedOutput.Data; //if (writeToDatabase) //{ // Database.ExecSP("add_document", rawDocumentData); //} //else if (writeToDisk) //{ // File.WriteAllBytes(@"E:\gss_test\output\test_piped_output.pdf", rawDocumentData); //} } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { gsPipedOutput.Dispose(); gsPipedOutput = null; } } }
private void SaveImage() { GhostscriptVersionInfo _gs_version_info = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL); GhostscriptProcessor processor = new GhostscriptProcessor(_gs_version_info, true); List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dQUIET"); switches.Add("-dSAFER"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dEPSCrop"); switches.Add("-sDEVICE=pdfwrite"); // switches.Add("-sOutputFile=" + variantPath); switches.Add("-f"); //switches.Add(originalPath); processor.StartProcessing(switches.ToArray(), null); }
public void Start() { string inputFile = @"E:\gss_test\test.pdf"; string outputFile = @"E:\gss_test\output\page-%03d.png"; //string inputFile = @"E:\gss_test\multipage.ps"; //string outputFile = @"E:\gss_test\output\multipage.pdf"; int pageFrom = 1; int pageTo = 50; 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); } }
public void Start() { // YOU NEED TO HAVE ADMINISTRATOR RIGHTS TO RUN THIS CODE string printerName = "YourPrinterName"; string inputFile = @"E:\__test_data\test.pdf"; using (GhostscriptProcessor processor = new GhostscriptProcessor()) { List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-dPrinted"); switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOSAFER"); switches.Add("-dNumCopies=1"); switches.Add("-sDEVICE=mswinpr2"); switches.Add("-sOutputFile=%printer%" + printerName); switches.Add("-f"); switches.Add(inputFile); processor.StartProcessing(switches.ToArray(), null); } }
/// <summary> /// Returns Ink coverage for specified page range. /// The result is ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally). /// This function is supported only in Ghostscript v9.05 or newer. /// </summary> /// <param name="path">PDF file path.</param> /// <param name="firstPage">Designated start page of the document. Pages of all documents in PDF collections are numbered sequentionally.</param> /// <param name="lastPage">Designated end page of the document. Pages of all documents in PDF collections are numbered sequentionally.</param> /// <param name="versionInfo">GhostscriptVersionInfo instance that tells which Ghostscript library to use.</param> /// <returns>A dictionary of a page numbers with the ink coverage.</returns> public static Dictionary<int, GhostscriptPageInkCoverage> GetInkCoverage(string path, int firstPage, int lastPage, GhostscriptVersionInfo versionInfo) { GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput(); string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2"); List<string> switches = new List<string>(); switches.Add("-empty"); switches.Add("-q"); if (firstPage != 0 && lastPage != 0) { switches.Add("-dFirstPage=" + firstPage.ToString()); switches.Add("-dLastPage=" + lastPage.ToString()); } switches.Add("-o" + outputPipeHandle); switches.Add("-sDEVICE=inkcov"); switches.Add(path); GhostscriptProcessor proc = new GhostscriptProcessor(versionInfo, false); proc.StartProcessing(switches.ToArray(), null); byte[] data = gsPipedOutput.Data; gsPipedOutput.Dispose(); gsPipedOutput = null; string output = Encoding.ASCII.GetString(data); if (output.Length > 0) { Dictionary<int, GhostscriptPageInkCoverage> result = new Dictionary<int, GhostscriptPageInkCoverage>(); string[] outputLines = output.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); int pageNumber = firstPage == 0 ? 1 : firstPage; foreach(string line in outputLines) { GhostscriptPageInkCoverage pic = new GhostscriptPageInkCoverage(); pic.Page = pageNumber; pic.IsValid = false; string[] lineParts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineParts.Length == 6) { pic.C = Math.Round(float.Parse(lineParts[0], CultureInfo.InvariantCulture) * 100, 2); pic.M = Math.Round(float.Parse(lineParts[1], CultureInfo.InvariantCulture) * 100, 2); pic.Y = Math.Round(float.Parse(lineParts[2], CultureInfo.InvariantCulture) * 100, 2); pic.K = Math.Round(float.Parse(lineParts[3], CultureInfo.InvariantCulture) * 100, 2); if (lineParts[5] == "OK") { pic.IsValid = true; } } result.Add(pageNumber, pic); pageNumber++; } return result; } else { return null; } }
private void Add_Watermark_To_PDF_Document() { string inputFile = @"E:\gss_test\test.pdf"; string outputFile = @"E:\gss_test\output\test-watermarked.pdf"; List<string> switches = new List<string>(); switches.Add(string.Empty); // set required switches switches.Add("-dBATCH"); switches.Add("-dNOPAUSE"); switches.Add("-dNOPAUSE"); switches.Add("-sDEVICE=pdfwrite"); switches.Add("-sOutputFile=" + outputFile); switches.Add("-c"); switches.Add(POSTSCRIPT_APPEND_WATERMARK); switches.Add("-f"); switches.Add(inputFile); // create a new instance of the GhostscriptProcessor using (GhostscriptProcessor processor = new GhostscriptProcessor()) { // start processing pdf file processor.StartProcessing(switches.ToArray(), null); } // show new pdf Process.Start(outputFile); }
public void Process(GhostscriptVersionInfo ghostscriptVersion, bool fromMemory, GhostscriptStdIO stdIO_callback) { if (ghostscriptVersion == null) { throw new ArgumentNullException("ghostscriptVersion"); } using (GhostscriptProcessor processor = new GhostscriptProcessor(ghostscriptVersion, fromMemory)) { processor.StartProcessing(this.GetSwitches(), stdIO_callback); } }