I need your support on the following question, as it has been pulling me for a while. We have a small utility c#that prints using PDFwith GhostScript. This prints as expected, but does not preserve the page format. However, the pages print as expected when I switch Adobe Acrobatinstead GhostScript. Therefore, I assume that I am making an obvious mistake in the GhostScript command line arguments.
c#
PDF
GhostScript
Adobe Acrobat
Background
Below is the basic C # logic that prints a given PDF file with a different style on each page. There are pages in this PDF file;
In a compressed form, the PDF that I am trying to print is nothing more than consolidation (combining individual PDF files into one large pdf) from a large small PDF format with various font types, sizes, margins.
Question
Following the logic, use GhostScript(v9.02)to print a PDF file. Although the following logic prints any given PDF file, it cannot preserve page formatting, including header, footer, font size, margin, orientation (there are pages in my pdf that are both landscape and portrait).
GhostScript(v9.02)
, Acrobat Reader PDF , , , .
PDF-: ,
void PrintDocument() { var psInfo = new ProcessStartInfo(); psInfo.Arguments = String.Format( " -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=\"\\\\spool\\{0}\" \"{1}\"", GetDefaultPrinter(), @"C:\PDFOutput\test.pdf"); psInfo.FileName = @"C:\Program Files\gs\gs9.10\bin\gswin64c.exe"; psInfo.UseShellExecute = false; using (var process= Process.Start(psInfo)) { process.WaitForExit(); } }
- 16/12/2013
, . "KenS", , .
, , , GSView GhostScript PDF, Adobe. :
//PrintParamter is a custom data structure to capture file related info private void PrintDocument(PrintParamter fs, string printerName = null) { if (!File.Exists(fs.FullyQualifiedName)) return; var filename = fs.FullyQualifiedName ?? string.Empty; printerName = printerName ?? GetDefaultPrinter(); //get your printer here var processArgs = string.Format("-dAutoRotatePages=/All -dNOPAUSE -dBATCH -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -dEmbedAllFonts=true -dSubsetFonts=true -dPDFSETTINGS=/prepress -dNOPLATFONTS -sFONTPATH=\"C:\\Program Files\\gs\\gs9.10\\fonts\" -noquery -dNumCopies=1 -all -colour -printer \"{0}\" \"{1}\"", printerName, filename); try { var gsProcessInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = gsViewEXEInstallationLocation, Arguments = processArgs }; using (var gsProcess = Process.Start(gsProcessInfo)) { gsProcess.WaitForExit(); } }
, , , GSView, Ghostscript.
, GSView Ghostscript , , .
PDF, , , , , Ghostscript. (, ), , , , , .
Ghostscript .
, , (, -dPDFSETTINGS), PDF, - (, ).
, , , , ( Ghostscript), . , , , , , .
GSPRINT.
, gsprint.exe/gswin64c.exe/gsdll64.dll .
:
// This uses gsprint (mind the paths) private const string gsPrintExecutable = @"C:\gs\gsprint.exe"; private const string gsExecutable = @"C:\gs\gswin64c.exe"; string pdfPath = @"C:\myShinyPDF.PDF" string printerName = "MY PRINTER"; string processArgs = string.Format("-ghostscript \"{0}\" -copies=1 -all -printer \"{1}\" \"{2}\"", gsExecutable, printerName, pdfPath ); var gsProcessInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = gsPrintExecutable , Arguments = processArgs }; using (var gsProcess = Process.Start(gsProcessInfo)) { gsProcess.WaitForExit(); }