public StartProcessing ( GhostscriptDevice device, GhostscriptStdIO stdIO_callback ) : void | ||
device | GhostscriptDevice | |
stdIO_callback | GhostscriptStdIO | |
리턴 | void |
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); } }