### Rinkj Setup File Example - 2200 Configuration Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html A sample setup file for the EPSON 2200, adaptable to the 7600 by changing the 'Model' line. ```text Manufacturer:EPSON Model:Stylus Photo 2200 Resolution:1440x720 Dither:2 Aspect:2 Microdot:1 Unidirectional:0 AddLut:Cc 2 0.0 0.0 1.0 1.0 AddLut:Mm 2 0.0 0.0 1.0 1.0 AddLut:Yy 2 0.0 0.0 1.0 1.0 AddLut:Kk 2 0.0 0.0 1.0 1.0 ``` -------------------------------- ### Setting Device Properties with a Setup File Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Use a PostScript setup file to configure device properties that cannot be set via the command line. Do not specify the -sDEVICE option on the command line when using a setup file. ```bash gs ... setup.ps ... ``` ```postscript << /NoCancel true % don't show the cancel dialog /BitsPerPixel 4 % force 4 bits/pixel /UserSettings << /DocumentName (Ghostscript document) % name for the Windows spooler /MaxResolution 360 % maximum document resolution >> /OutputDevice /mswinpr2 % select the Windows device driver >> setpagedevice setdevice ``` -------------------------------- ### Ghostscript Job Server Example 2 Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Alternative example usage of the -dJOBSERVER parameter, piping input from a file. ```bash cat inputfile.ps | gs ... -dJOBSERVER - ``` -------------------------------- ### Distill PostScript to PDF Example (C#) Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Example method demonstrating how to set up parameters and run a PostScript to PDF distillation task using GhostAPI. ```csharp public gsStatus DistillPS(String fileName, int resolution) { gsParamState_t gsparams = new gsParamState_t(); gsparams.args = new List(); gsparams.inputfile = fileName; gsparams.args.Add("gs"); gsparams.args.Add("-dNOPAUSE"); gsparams.args.Add("-dBATCH"); gsparams.args.Add("-I%rom%Resource/Init/"); gsparams.args.Add("-dSAFER"); gsparams.args.Add("-sDEVICE=pdfwrite"); gsparams.outputfile = Path.GetTempFileName(); gsparams.args.Add("-o" + gsparams.outputfile); gsparams.task = GS_Task_t.PS_DISTILL; return RunGhostscriptAsync(gsparams); } ``` -------------------------------- ### Example: Set Disk0 Root Directory Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html An example demonstrating how to set the root directory for the '%disk0' device to '/tmp/disk0'. ```ghostscript mark /Root (/tmp/disk0/) (%disk0) .putdevparams ``` -------------------------------- ### Example uniprint Driver Usage on Linux Source: https://ghostscript.readthedocs.io/en/gs10.02.1/UnsupportedDevices.html An example demonstrating how to use the uniprint driver on a Linux system to send output to a printer device. ```bash gs @stc.upp -sOutputFile=/dev/lp1 tiger.eps -c quit ``` -------------------------------- ### CIDFont System Info Example Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Example of a `CIDFontSystem` dictionary specifying registry, ordering, and supplement for font substitution. ```postscript /CIDSystemInfo << /Registry (Adobe) /Ordering (CNS1) /Supplement 1 >> ``` -------------------------------- ### Install Ghostscript Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Make.html After building, this command installs the Ghostscript executables, support files, and documentation, but not fonts. Refer to the installation documentation for more details. ```makefile make install ``` -------------------------------- ### Ghostscript Job Server Example 1 Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Example usage of the -dJOBSERVER parameter, reading input from stdin. ```bash gs ... -dJOBSERVER - < inputfile.ps ``` -------------------------------- ### my_callout_handler Example Source: https://ghostscript.readthedocs.io/en/gs10.02.1/API.html An example implementation of a callout handler for the display device, demonstrating how to respond to `DISPLAY_CALLOUT_GET_CALLBACK`. ```APIDOC ## my_callout_handler ### Description An example callout handler function that processes events from the Ghostscript display device. It specifically handles the `DISPLAY_CALLOUT_GET_CALLBACK` event to provide callback details. ### Parameters - `instance` (void *): Pointer to the Ghostscript instance. - `callout_handle` (void *): The `state` value passed during `gsapi_register_callout`. - `device_name` (const char *): The name of the device generating the callout. - `id` (int): The specific callout identifier. - `size` (int): The size of the `data` buffer. - `data` (void *): A pointer to a buffer for data exchange. ### Handler Logic - Checks if `device_name` is "display". - If `id` is `DISPLAY_CALLOUT_GET_CALLBACK`, it populates the `gs_display_get_callback_t` structure pointed to by `data` with the user's callback function and `callout_handle`. ### Response - `0`: On successful handling of `DISPLAY_CALLOUT_GET_CALLBACK` for the display device. - `-1`: If the callout is not for the display device or not a recognized `id`. ``` -------------------------------- ### Device Setup and Output Operators Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Lib.html Procedures for device setup and output operations. ```APIDOC ## Device Setup and Output Operators ### Description Procedures for configuring devices and performing output operations. ### Headers - `gsdevice.h` ### Operators - `gs_getdeviceparams` - `gs_putdeviceparams` ### Notes These operators use a `gs_param_list` for specifying or receiving parameter values. Refer to `gsparam.h` for more details. ``` -------------------------------- ### Example DEVICES Definition in lprsetup.sh Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Unix-lpr.html Defines the printer devices, their bit depths, color capabilities, and queue types for the lprsetup.sh script. Edit this line to match your printer setup. ```shell DEVICES="cdj550.24.dq cdj550.3.dq cdj550.1.dq deskjet djet500.dq" ``` -------------------------------- ### Typical Rinkj Command Line Invocation Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Example of how to invoke the Rinkj driver with specific settings for resolution, output file, setup file, and ICC profile. ```bash gs -r1440x720 -sDEVICE=rinkj -sOutputFile=/dev/usb/lp0 -sSetupFile=lib/rinkj-2200-setup -sProfileOut=2200-cmyk.icm -dNOPAUSE -dBATCH file.ps ``` -------------------------------- ### Example: Applying Trapping with psdcmyk Device Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html This example demonstrates how to use the psdcmyk device with specific trapping parameters, including TrapX, TrapY, and TrapOrder, to process an EPS file and output a PSD file. ```bash gs -sDEVICE=psdcmyk -dTrapX=2 -dTrapY=2 -o out.psd -c "<< /TrapOrder [ 4 5 3 1 0 2 ] >> setpagedevice" -f examples\tiger.eps ``` -------------------------------- ### Install Transparency Compositor Device Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html Installs the transparency compositor device into the graphics state. The depth parameter should currently be zero. ```ghostscript .pushpdf14devicefilter - ``` -------------------------------- ### Example: Output to JPEG using jpeg device Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html This example demonstrates how to use the 'jpeg' output device to produce a color JPEG file from a PostScript file. ```bash gs -sDEVICE=jpeg -sOutputFile=foo.jpg foo.ps ``` -------------------------------- ### Install Autoconf and Automake on MacOS/Linux Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Make.html Use Homebrew to install autoconf and automake, which are required for running the autogen.sh script. ```bash brew install autoconf automake ``` -------------------------------- ### DistillPS Method Example Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Example of how to use the `DistillPS` method to convert a PostScript file to PDF. ```APIDOC ## Method: DistillPS ### Description Converts a PostScript file to a PDF document. ### Signature `public gsStatus DistillPS(String fileName, int resolution)` ### Parameters - **fileName** (String): The path to the input PostScript file. - **resolution** (int): The desired resolution for the output PDF. ### Example Usage ```csharp public gsStatus DistillPS(String fileName, int resolution) { gsParamState_t gsparams = new gsParamState_t(); gsparams.args = new List(); gsparams.inputfile = fileName; gsparams.args.Add("gs"); gsparams.args.Add("-dNOPAUSE"); gsparams.args.Add("-dBATCH"); gsparams.args.Add("-I%rom%Resource/Init/"); gsparams.args.Add("-dSAFER"); gsparams.args.Add("-sDEVICE=pdfwrite"); gsparams.outputfile = Path.GetTempFileName(); gsparams.args.Add("-o" + gsparams.outputfile); gsparams.task = GS_Task_t.PS_DISTILL; return RunGhostscriptAsync(gsparams); } ``` ``` -------------------------------- ### Install Subclassing Device in TIFF Open Method Source: https://ghostscript.readthedocs.io/en/gs10.02.1/DeviceSubclassing.html In the `tiff_open` function, check if `ForceBlackText` is enabled and if the handler is not already pushed. If conditions are met, use `gx_device_subclass` to install the `gs_black_text_device`. ```c int tiff_open(gx_device *pdev) { gx_device_printer * const ppdev = (gx_device_printer *)pdev; gx_device_tiff *tfdev = (gx_device_tiff *)pdev; int code; bool update_procs = false; /* Use our own warning and error message handlers in libtiff */ tiff_set_handlers(); if (!tfdev->BlackTextHandlerPushed && (tfdev->ForceBlackText != 0)) { gx_device *dev; gx_device_subclass(pdev, (gx_device *)&gs_black_text_device, sizeof(black_text_subclass_data)); tfdev = (gx_device_tiff *)pdev->child; tfdev->BlackTextHandlerPushed = true; while(pdev->child) pdev = pdev->child; pdev->is_open = true; update_procs = true; } ``` -------------------------------- ### Build 64-bit Self-Extracting Installer Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Make.html Create a self-extracting installer for 64-bit Windows by using the 'nsis' makefile target in addition to the WIN64 define. ```makefile nmake -f psi/msvc.mak WIN64= nsis ``` -------------------------------- ### File Path Matching Examples Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Demonstrates how file paths are matched in SAFER mode. Exact matches are required, and path separators are platform-dependent. ```text "/path/to/file" ``` ```text "/path/to/directory/" ``` ```text "/path/to/directory/*" ``` -------------------------------- ### OCR PDF Output Example Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Example command to generate an OCR-enabled PDF. This command uses the 'ocr' device, sets a resolution, specifies English and Arabic languages for OCR, and outputs to 'out.txt'. ```bash gs -sDEVICE=ocr -r200 -sOCRLanguage="eng+ara" -o out.txt\ zlib/zlib.3.pdf ``` -------------------------------- ### Example Source Object ICC Configuration Source: https://ghostscript.readthedocs.io/en/gs10.02.1/GhostscriptColorManagement.html An example of a tab-delimited file used with `-sSourceObjectICC` to define object-specific color management parameters including ICC profile, rendering intent, black point compensation, and black preservation. ```text Image_CMYK ./gs/toolbin/color/src_color/profiles/ISOcoated_v2_eci.icc 1 1 1 1 Image_RGB ./gs/toolbin/color/src_color/profiles/sRGB.icc 0 0 0 0 Vector_CMYK ./gs/toolbin/color/src_color/profiles/ISOcoated_v2_eci.icc 2 1 1 1 Vector_RGB ./gs/toolbin/color/src_color/profiles/sRGB.icc 0 0 0 0 Text_CMYK ./gs/toolbin/color/src_color/profiles/ISOcoated_v2_eci.icc 1 1 1 1 Text_RGB ./gs/toolbin/color/src_color/profiles/sRGB.icc 0 0 0 0 ``` -------------------------------- ### Run gsviewer.jar on Linux Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Ensure the Ghostscript library is in the gsviewer directory. Make the start script executable and then run it. ```bash chmod +x start_linux.sh ./start_linux.sh ``` -------------------------------- ### Run gsviewer.jar on MacOS Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Ensure the Ghostscript library is in the gsviewer directory. Make the start script executable and then run it. ```bash chmod +x start_darwin.sh ./start_darwin.sh ``` -------------------------------- ### GSMONO Instantiation and Callback Setup Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Demonstrates how to instantiate the GSMONO class and attach callback handlers for different asynchronous events. This includes setting up handlers for progress, standard I/O, DLL problems, and page rendering. ```APIDOC ## GSMONO Instantiation and Callback Setup This section shows how to initialize the `GSMONO` class and subscribe to its various callback events. These callbacks are crucial for monitoring and reacting to the progress and outcomes of Ghostscript operations. ### Method ```csharp // Instantiate GSMONO and set up callbacks m_ghostscript = new GSMONO(); m_ghostscript.ProgressCallBack += new GSMONO.Progress(gsProgress); m_ghostscript.StdIOCallBack += new GSMONO.StdIO(gsIO); m_ghostscript.DLLProblemCallBack += new GSMONO.DLLProblem(gsDLL); m_ghostscript.PageRenderedCallBack += new GSMONO.PageRendered(gsPageRendered); m_ghostscript.DisplayDeviceOpen(); ``` ### Callback Stubs Example implementations for the callback methods: ```csharp private void gsProgress(gsThreadCallBack asyncInformation) { Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); if (asyncInformation.Completed) // task complete { // Handle task completion based on asyncInformation.Params.task // and check asyncInformation.Params.result for success or failure. } else // task is still running { // Handle ongoing task based on asyncInformation.Params.task } } private void gsIO(String message, int len) { Console.WriteLine($"gsIO().message:{message}, length:{len}"); } private void gsDLL(String message) { Console.WriteLine($"gsDLL().message:{message}"); } private void gsPageRendered(int width, int height, int raster, IntPtr data, gsParamState_t state) { // Handle page rendered event }; ``` ``` -------------------------------- ### GSNET Initialization and Callback Setup Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Demonstrates how to initialize the GSNET object and attach callback methods for handling progress, I/O, DLL problems, and page rendering events. ```APIDOC ## GSNET Initialization and Callback Setup ### Description This snippet shows the basic setup for using the Ghostscript .NET bindings. It involves creating an instance of the `GSNET` class and assigning handler methods to its various callback events. ### Code Example ```csharp /* Set up ghostscript with callbacks for system updates */ m_ghostscript = new GSNET(); m_ghostscript.ProgressCallBack += new GSNET.Progress(gsProgress); m_ghostscript.StdIOCallBack += new GSNET.StdIO(gsIO); m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL); m_ghostscript.PageRenderedCallBack += new GSNET.PageRendered(gsPageRendered); m_ghostscript.DisplayDeviceOpen(); ``` ``` -------------------------------- ### Instance Management and Initialization Source: https://ghostscript.readthedocs.io/en/gs10.02.1/API.html Demonstrates the basic workflow of creating a Ghostscript instance, setting up standard input/output, and initializing with arguments. ```APIDOC ## gsapi_new_instance ### Description Creates a new Ghostscript instance. ### Method C function call ### Parameters - **minst** (*void **) - **caller_handle** (*void *) ## gsapi_set_stdio ### Description Sets the standard input, output, and error callback functions for the Ghostscript instance. ### Method C function call ### Parameters - **minst** (*void *) - **stdin_callback** (*gsapi_input_callback_fn *) - **stdout_callback** (*gsapi_output_callback_fn *) - **stderr_callback** (*gsapi_output_callback_fn *) ## gsapi_set_arg_encoding ### Description Sets the encoding for arguments passed to Ghostscript. ### Method C function call ### Parameters - **minst** (*void *) - **encoding** (*int *) ## gsapi_init_with_args ### Description Initializes the Ghostscript interpreter with command-line arguments. ### Method C function call ### Parameters - **minst** (*void *) - **argc** (*int *) - **argv** (*char **) ## gsapi_exit ### Description Exits the Ghostscript interpreter. ### Method C function call ### Parameters - **minst** (*void *) ## gsapi_delete_instance ### Description Deletes a Ghostscript instance and frees associated resources. ### Method C function call ### Parameters - **minst** (*void *) ``` -------------------------------- ### SPARCprinter Installation Script Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html This shell script is an example for printing to a SPARCprinter after adding 'sparc.dev' to DEVICE_DEVS and compiling Ghostscript. Modify {GSPATH} with the full pathname of the Ghostscript executable. ```shell outcmd1='/vol/local/lib/troff2/psxlate -r' outcmd2='{GSPATH} -sDEVICE=sparc -sOUTPUTFILE=/dev/lpvi0 -' if [ $# -eq 0 ] then $outcmd1 | $outcmd2 else cat $* | $outcmd1 | $outcmd2 fi ``` -------------------------------- ### Build gsviewer.jar on Linux Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Navigate to the specified directory, make the build script executable, and then run it to build gs_jni.so, gsjava.jar, and gsviewer.jar. ```bash chmod +x build_linux.sh ./build_linux.sh ``` -------------------------------- ### Install Ghostscript on Unix Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Install.html Command to install Ghostscript after building. This may require superuser privileges. The installation directory can be customized using the --prefix option during configuration. ```bash make install ``` -------------------------------- ### Ghostscript CIDFont Mapping Examples Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Examples of CIDFont mappings for different font formats and languages. ```postscript /Ryumin-Medium /ShinGo-Bold ; /Ryumin-Light /MS-Mincho ; ``` ```postscript /Batang << /FileType /TrueType /Path (C:/WINDOWS/fonts/batang.ttc) /SubfontID 0 /CSI [(Korea1) 3] >> ; /Gulim << /FileType /TrueType /Path (C:/WINDOWS/fonts/gulim.ttc) /SubfontID 0 /CSI [(Korea1) 3] >> ; /Dotum << /FileType /TrueType /Path (C:/WINDOWS/fonts/gulim.ttc) /SubfontID 2 /CSI [(Korea1) 3] >> ; ``` ```postscript /SimSun << /FileType /TrueType /Path (C:/WINDOWS/fonts/simsun.ttc) /SubfontID 0 /CSI [(GB1) 2] >> ; /SimHei << /FileType /TrueType /Path (C:/WINDOWS/fonts/simhei.ttf) /SubfontID 0 /CSI [(GB1) 2] >> ; /STSong-Light /SimSun ; /STHeiti-Regular /SimHei ; Format 3: /PMingLiU (/usr/local/share/font/cidfont/PMingLiU.cid) ; ``` ```postscript /Ryumin-Light /PMingLiU ; /PMingLiU (/usr/local/share/font/cidfont/PMingLiU.cid) ; ``` -------------------------------- ### DisplayDeviceOpen Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Initializes the display device, setting up Ghostscript and configuring encoding and callbacks. ```APIDOC ## DisplayDeviceOpen ### Description Sets up the display device ahead of time. ### Method Signature ```csharp public gsParamState_t DisplayDeviceOpen() ``` ### Sample Code ```csharp m_ghostscript.DisplayDeviceOpen(); ``` ### Notes Calling this method instantiates Ghostscript and configures the encoding and the callbacks for the display device. ``` -------------------------------- ### Example Filing System Implementation Source: https://ghostscript.readthedocs.io/en/gs10.02.1/API.html Demonstrates how to implement a custom filing system, such as one that encrypts data, by defining a derived `gp_file` structure and providing the necessary function pointers in a `gsapi_fs_t` instance. ```APIDOC ## Example: Crypt Filing System ### Derived `gp_file` Structure Consider a hypothetical filing system that encrypts data on write and decrypts on read. This requires maintaining state between calls, necessitating a derived `gp_file` structure. ```c typedef struct { gp_file base; /* State private to the implementation of this file for encryption/decryption */ /* For example: */ int foo; char *bar; } gp_file_crypt; ``` ### `gsapi_fs_t` Instance for Crypt System An implementation of `gsapi_fs_t` for the 'crypt' filing system, providing only the `open_file` handler. ```c /* Assume crypt_open_file is defined elsewhere */ /* int crypt_open_file(const gs_memory_t *mem, void *secret, const char *fname, const char *mode, gp_file **file); */ gsapi_fs_t gs_fs_crypt = { crypt_open_file, NULL, /* open_pipe */ NULL, /* open_scratch */ NULL, /* open_printer */ NULL /* open_handle */ }; ``` ``` -------------------------------- ### Prototype Device Text Begin Procedure Source: https://ghostscript.readthedocs.io/en/gs10.02.1/DeviceSubclassing.html Prototyping the `text_begin` method for a device, which is specific to text-based operations. ```c /* Device procedures */ static dev_proc_text_begin(black_text_text_begin); ``` -------------------------------- ### Initialize Ghostscript and Set Up Callbacks in C# Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Set up the Ghostscript instance and assign callback methods for system updates and asynchronous operations. Ensure all necessary callback stubs are defined. ```csharp /* Set up ghostscript with callbacks for system updates */ m_ghostscript = new GSNET(); m_ghostscript.ProgressCallBack += new GSNET.Progress(gsProgress); m_ghostscript.StdIOCallBack += new GSNET.StdIO(gsIO); m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL); m_ghostscript.PageRenderedCallBack += new GSNET.PageRendered(gsPageRendered); m_ghostscript.DisplayDeviceOpen(); /* example callback stubs for asynchronous operations */ private void gsProgress(gsEventArgs asyncInformation) { Console.WriteLine($"gsProgress().progress:{asyncInformation.Progress}"); if (asyncInformation.Completed) // task complete { // what was the task? switch (asyncInformation.Params.task) { case GS_Task_t.CREATE_XPS: Console.WriteLine($"CREATE_XPS.outputfile:"); Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); break; case GS_Task_t.PS_DISTILL: Console.WriteLine($"PS_DISTILL.outputfile:"); Console.WriteLine($"{asyncInformation.Params.result.outputfile}"); break; case GS_Task_t.SAVE_RESULT: break; case GS_Task_t.DISPLAY_DEV_THUMBS: break; case GS_Task_t.DISPLAY_DEV_RUN_FILE: break; case GS_Task_t.DISPLAY_DEV_PDF: break; case GS_Task_t.DISPLAY_DEV_NON_PDF: break; default: break; } // task failed if (asyncInformation.Params.result == GS_Result_t.gsFAILED) { switch (asyncInformation.Params.task) { case GS_Task_t.CREATE_XPS: break; case GS_Task_t.PS_DISTILL: break; case GS_Task_t.SAVE_RESULT: break; default: break; } return; } // task cancelled if (asyncInformation.Params.result == GS_Result_t.gsCANCELLED) { } } else // task is still running { switch (asyncInformation.Params.task) { case GS_Task_t.CREATE_XPS: break; case GS_Task_t.PS_DISTILL: break; case GS_Task_t.SAVE_RESULT: break; } } } private void gsIO(String message, int len) { Console.WriteLine($"gsIO().message:{message}, length:{len}"); } private void gsDLL(String message) { Console.WriteLine($"gsDLL().message:{message}"); } private void gsPageRendered(int width, int height, int raster, IntPtr data, gsParamState_t state) { }; ``` -------------------------------- ### Initialize and Run Ghostscript as PDF Converter Source: https://ghostscript.readthedocs.io/en/gs10.02.1/API.html Example C code demonstrating how to use the Ghostscript DLL to convert a PostScript file to a PDF. It initializes a Ghostscript instance, sets arguments for PDF conversion, runs the conversion, and cleans up the instance. ```c /* Example of using GS DLL as a ps2pdf converter. */ #if defined(_WIN32) && !defined(_Windows) # define _Windows #endif #ifdef _Windows /* add this source to a project with gsdll32.dll, or compile it directly with: * cl -D_Windows -Isrc -Febin\ps2pdf.exe ps2pdf.c bin\gsdll32.lib */ # include # define GSDLLEXPORT __declspec(dllimport) #endif #include "ierrors.h" #include "iapi.h" void *minst = NULL; int main(int argc, char *argv[]) { int code, code1; const char * gsargv[7]; int gsargc; gsargv[0] = ""; gsargv[1] = "-dNOPAUSE"; gsargv[2] = "-dBATCH"; gsargv[3] = "-dSAFER"; gsargv[4] = "-sDEVICE=pdfwrite"; gsargv[5] = "-sOutputFile=out.pdf"; gsargv[6] = "input.ps"; gsargc=7; code = gsapi_new_instance(&minst, NULL); if (code < 0) return 1; code = gsapi_set_arg_encoding(minst, GS_ARG_ENCODING_UTF8); if (code == 0) code = gsapi_init_with_args(minst, gsargc, gsargv); code1 = gsapi_exit(minst); if ((code == 0) || (code == gs_error_Quit)) code = code1; gsapi_delete_instance(minst); if ((code == 0) || (code == gs_error_Quit)) return 0; return 1; } ``` -------------------------------- ### Set Printer Properties via Command Line Source: https://ghostscript.readthedocs.io/en/gs10.02.1/UnsupportedDevices.html This example shows how to set printer properties such as BitsPerPixel and Shingling directly from the command line. ```bash gs -dBitsPerPixel=32 -dShingling=1 ... ``` -------------------------------- ### Open Display Device (C#) Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Sets up the display device and instantiates Ghostscript, configuring encoding and callbacks. This must be called before rendering. ```csharp public gsParamState_t DisplayDeviceOpen() ``` ```csharp m_ghostscript.DisplayDeviceOpen(); ``` -------------------------------- ### Install Ghostscript Shared Object on Unix Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Install.html Use this command instead of 'make install' if you have built Ghostscript as a shared object. Refer to the build documentation for more details. ```bash make soinstall ``` -------------------------------- ### Rinkj Setup File Configuration - Dither Options Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Selects the dither algorithm. Use 1 for one-bit dither and 2 for a 2-bit variable dot dither. ```text Dither:{int} ``` -------------------------------- ### Rinkj Setup File Configuration - Resolution Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Sets the printer resolution in DPI within the Rinkj setup file. Should typically match the Ghostscript -r switch. ```text Resolution:{x-dpi}x{y-dpi} ``` -------------------------------- ### Initialize Smurf Device Procedures Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Drivers.html Example of an initialize_device_procs procedure for a derived printer device. It calls a base class helper and overrides specific procedures. ```c static void smurf_initialize_device_procs(gx_device *dev) { /* We are derived from a prn device, and can print in the background */ gdev_prn_initialize_bg(dev); /* Override functions for our specifics */ set_dev_proc(dev, map_color_rgb, smurf_map_color_rgb); set_dev_proc(dev, map_rgb_color, smurf_map_rgb_color); ... } ``` -------------------------------- ### Start Job Server in Ghostscript Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Defines a character to start a new encapsulated job for compatibility with Adobe PS Interpreters. Requires input from stdin and ignores -dNOOUTERSAVE. ```bash -dJOBSERVER ``` -------------------------------- ### Get Profile Connection Space Channel Count Source: https://ghostscript.readthedocs.io/en/gs10.02.1/GhostscriptColorManagement.html Get the channel count for the profile connection space (PCS). Typically three, but can be larger for device link profiles. ```c int gscms_get_pcs_channel_count(gcmmhprofile_t profile); ``` -------------------------------- ### Select Output Device using Command Line Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html Use the -sDEVICE option to specify the output device. This option must precede the input file name. If not provided, the default device is used. ```bash gs -sDEVICE=epson myfile.ps ``` -------------------------------- ### Initialize Device Procedures Source: https://ghostscript.readthedocs.io/en/gs10.02.1/DeviceSubclassing.html Initializes the device procedures, setting default subclass methods and overriding specific methods like `text_begin`. ```c void black_text_init_dev_procs(gx_device *dev) { default_subclass_initialize_device_procs(dev); set_dev_proc(dev, text_begin, black_text_text_begin); } ``` -------------------------------- ### Initialize Display Device in C# Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Sets up the display device ahead of time. Calling this method instantiates Ghostscript and configures the encoding and callbacks for the display device. ```csharp public gsParamState_t DisplayDeviceOpen() ``` ```csharp m_ghostscript.DisplayDeviceOpen(); ``` -------------------------------- ### Rinkj Setup File Configuration - Manufacturer and Model Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Devices.html Specifies the manufacturer and model of the printer within the Rinkj setup file. Currently supports EPSON Stylus Photo 2200 and 7600. ```text Manufacturer:{name} Model:{name} ``` -------------------------------- ### DisplayDeviceOpen Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Sets up the display device ahead of time. This method instantiates Ghostscript and configures the encoding and callbacks for the display device. ```APIDOC ## DisplayDeviceOpen ### Description Sets up the display device ahead of time. Calling this method instantiates Ghostscript and configures the encoding and the callbacks for the display device. ### Method Signature ```csharp public gsParamState_t DisplayDeviceOpen() ``` ### Sample Code ```csharp m_ghostscript.DisplayDeviceOpen(); ``` ``` -------------------------------- ### Install Ghostscript on Linux using RPM Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Install.html Commands to install or upgrade Ghostscript on Linux systems using precompiled RPM packages. Note that these RPMs are not officially created or supported by the Ghostscript project. ```bash rpm -U ghostscript-N.NN-1.i386.rpm rpm -U ghostscript-fonts-N.NN-1.noarch.rpm ``` -------------------------------- ### FAPI CID Font Map Record Example Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Fonts.html An example of a record within the FAPI CID font map file, defining how a specific CID font should be rendered using a third-party engine. ```ghostscript /HeiseiKakuGo-W5 << /Path (/WIN2000/Fonts/PMINGLIU.TTF) /CIDFontType 0 /FAPI /UFST /CSI [(Japan1) 2] >> ; ``` -------------------------------- ### Get Help for Ghostscript Configuration Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Make.html To see a complete list of available configuration options for the `configure` script, run this command. Note that this option is only available with the Unix `.tar` distributions. ```bash ./configure --help ``` -------------------------------- ### Build gsviewer.jar on MacOS Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Navigate to the specified directory and make the build script executable before running it to build gs_jni.dylib, gsjava.jar, and gsviewer.jar. ```bash chmod +x build_darwin.sh ./build_darwin.sh ``` -------------------------------- ### Initialize and Run Ghostscript Source: https://ghostscript.readthedocs.io/en/gs10.02.1/API.html Basic initialization and execution of a Ghostscript command string. Ensure proper instance creation and cleanup. ```c #include #include "ierrors.h" #include "iapi.h" /* stdio functions */ static int GSDLLCALL gsdll_stdin(void *instance, char *buf, int len) { int ch; int count = 0; while (count < len) { ch = fgetc(stdin); if (ch == EOF) return 0; *buf++ = ch; count++; if (ch == '\n') break; } return count; } static int GSDLLCALL gsdll_stdout(void *instance, const char *str, int len) { fwrite(str, 1, len, stdout); fflush(stdout); return len; } static int GSDLLCALL gsdll_stderr(void *instance, const char *str, int len) { fwrite(str, 1, len, stderr); fflush(stderr); return len; } void *minst = NULL; const char start_string[] = "systemdict /start get exec\n"; int main(int argc, char *argv[]) { int code, code1; int exit_code; code = gsapi_new_instance(&minst, NULL); if (code < 0) return 1; gsapi_set_stdio(minst, gsdll_stdin, gsdll_stdout, gsdll_stderr); code = gsapi_set_arg_encoding(minst, GS_ARG_ENCODING_UTF8); if (code == 0) code = gsapi_init_with_args(minst, argc, argv); if (code == 0) code = gsapi_run_string(minst, start_string, 0, &exit_code); code1 = gsapi_exit(minst); if ((code == 0) || (code == gs_error_Quit)) code = code1; gsapi_delete_instance(minst); if ((code == 0) || (code == gs_error_Quit)) return 0; return 1; } ``` -------------------------------- ### Get Current Device Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html Retrieves the current device from the graphics state. ```postscript - currentdevice ``` -------------------------------- ### Get Ghostscript Status in C# Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Returns the current status of the Ghostscript instance. ```csharp public gsStatus GetStatus() ``` ```csharp gsStatus status = m_ghostscript.GetStatus(); ``` -------------------------------- ### Get Ghostscript Status (C#) Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html Retrieves the current operational status of the Ghostscript instance. ```csharp public gsStatus GetStatus() ``` ```csharp gsStatus status = m_ghostscript.GetStatus(); ``` -------------------------------- ### gsPageRendered Callback Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html An example implementation of the `PageRenderedCallBack` delegate, which is invoked once a page has been successfully rendered by Ghostscript. ```APIDOC ## gsPageRendered Callback ### Description This method is a handler for the `PageRenderedCallBack` event. It is called after a page has been rendered, providing details about the rendered page and its data. ### Method Signature ```csharp private void gsPageRendered(int width, int height, int raster, IntPtr data, gsParamState_t state) ``` ### Example Usage ```csharp private void gsPageRendered(int width, int height, int raster, IntPtr data, gsParamState_t state) { // Callback logic for a rendered page }; ``` ``` -------------------------------- ### Begin Transparency Group Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html Starts a new transparency group with specified bounding box and optional parameters like Isolated and Knockout. Default for Isolated and Knockout is false. ```PostScript .begintransparencygroup - ``` -------------------------------- ### gsDLL Callback Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsCSharp.html An example implementation of the `DLLProblemCallBack` delegate, which is triggered if any issues arise with the Ghostscript DLL. ```APIDOC ## gsDLL Callback ### Description This method is a handler for the `DLLProblemCallBack` event. It is called if there is a problem detected with the Ghostscript DLL itself. ### Method Signature ```csharp private void gsDLL(String mess) ``` ### Example Usage ```csharp private void gsDLL(String message) { Console.WriteLine($"gsDLL().message:{message}"); } ``` ``` -------------------------------- ### Run String Begin Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Wraps gsapi_run_string_begin to start processing a string without executing it immediately. ```java public int run_string_begin(int userErrors, Reference pExitCode); ``` -------------------------------- ### GPDL: Post Arguments Initialization Source: https://ghostscript.readthedocs.io/en/gs10.02.1/GPDL.html A placeholder function for post-argument initialization. ```c typedef int (*pl_interp_proc_post_args_init_t) (pl_interp_implementation_t *); ``` -------------------------------- ### Print Multiple Files with Different Copy Counts Source: https://ghostscript.readthedocs.io/en/gs10.02.1/SavedPages.html This example shows how to print a specified number of copies for different files sequentially. It uses the 'copies' keyword before each print command. ```shell gs -sDEVICE=pgmraw -o /dev/lp0 --saved-pages="begin" examples/annots.pdf \ --saved-pages="copies=2 print normal flush" \ examples/colorcir.ps \ --saved-pages="copies=5 print normal" ``` -------------------------------- ### Get Current Overprint Mode Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html Retrieves the current overprint mode setting from the graphics state. ```PostScript - .currentoverprintmode ``` -------------------------------- ### Set up X Windows display on VMS Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Use.html When using X Windows on VMS, set up the display with the node name and network transport before running Ghostscript. ```vms $ set display/create/node="doof.city.com"/transport=tcpip ``` -------------------------------- ### Get Current Blending Mode Source: https://ghostscript.readthedocs.io/en/gs10.02.1/Language.html Returns the current graphics state blend mode on the stack. ```ghostscript - .currentblendmode ``` -------------------------------- ### Build gsjava JAR on Windows Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Execute the batch script to build the gsjava JAR file on Windows. ```batch build_win32.bat ``` -------------------------------- ### Get Parameter Source: https://ghostscript.readthedocs.io/en/gs10.02.1/LanguageBindingsJava.html Wraps gsapi_get_param to retrieve a Ghostscript parameter. Overloaded for byte arrays and Strings. ```java public int get_param(byte[] param, long value, int paramType); ``` ```java public int get_param(String param, long value, int paramType); ```