### Configure Expat Build with Custom Prefix Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/README.md Specify a custom installation directory using the --prefix option. This example sets the installation path to /home/me/mystuff. ```bash ./configure --prefix=/home/me/mystuff ``` -------------------------------- ### Install Programs and Man Pages (Makefile) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/jpeg/install.txt Use 'make install' to install programs and man pages. Use 'make -n install' to preview installation locations. ```bash make install ``` ```bash make -n install ``` -------------------------------- ### Configure TIFF with Custom Installation Prefix Source: https://github.com/artifexsoftware/ghostpdl/blob/master/tiff/doc/html-prebuilt/_sources/build.rst.txt Example of specifying a custom installation directory using the --prefix option during configuration. ```shell ./configure --prefix=$HOME ``` -------------------------------- ### Set Device Properties with PostScript Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Devices.md Use a PostScript setup file to configure device-specific options that are not available via command-line arguments. This example sets the cancel dialog behavior, bits per pixel, and user settings. ```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 ``` -------------------------------- ### Build Shared ZLIB Example and Minigzip Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/test/CMakeLists.txt Configures the build for shared ZLIB library, creating example executables and linking against ZLIB::ZLIB. Includes setup for MSVC, MSYS, MINGW, and CYGWIN environments. ```cmake if(ZLIB_BUILD_SHARED) add_executable(zlib_example example.c) target_link_libraries(zlib_example ZLIB::ZLIB) target_compile_definitions(zlib_example PRIVATE ZLIB_BUILD) add_test(NAME zlib_example COMMAND zlib_example) add_executable(minigzip minigzip.c) target_compile_definitions( minigzip PRIVATE $<$:HAVE_HIDDEN>) target_link_libraries(minigzip ZLIB::ZLIB) if(MSVC OR MSYS OR MINGW OR CYGWIN) zlib_findtestenv(zlib_example) endif( MSVC OR MSYS OR MINGW OR CYGWIN) if(HAVE_OFF64_T) add_executable(zlib_example64 example.c) target_compile_definitions( zlib_example64 PRIVATE ZLIB_BUILD $<$:HAVE_HIDDEN>) target_link_libraries(zlib_example64 ZLIB::ZLIB) add_test(NAME zlib_example64 COMMAND zlib_example64) if(MSVC OR MSYS OR MINGW OR CYGWIN) zlib_findtestenv(zlib_example64) endif( MSVC OR MSYS OR MINGW OR CYGWIN) endif(HAVE_OFF64_T) endif(ZLIB_BUILD_SHARED) ``` -------------------------------- ### Install Documentation and Changelog Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/CMakeLists.txt Installs the AUTHORS file and the generated changelog to the documentation directory. ```cmake configure_file(Changes changelog COPYONLY) expat_install( FILES AUTHORS ${CMAKE_CURRENT_BINARY_DIR}/changelog DESTINATION ${CMAKE_INSTALL_DOCDIR}) ``` -------------------------------- ### Build Static ZLIB Example and Minigzip Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/test/CMakeLists.txt Configures the build for static ZLIB library, creating example executables and linking against ZLIB::ZLIBSTATIC. This section also includes setup for coverage testing with GCC and Clang. ```cmake if(ZLIB_BUILD_STATIC) add_executable(zlib_static_example example.c) target_link_libraries(zlib_static_example ZLIB::ZLIBSTATIC) target_compile_definitions( zlib_static_example PRIVATE ZLIB_BUILD $<$:HAVE_HIDDEN>) add_test(NAME zlib_static_example COMMAND zlib_static_example) add_executable(static_minigzip minigzip.c) target_link_libraries(static_minigzip ZLIB::ZLIBSTATIC) if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") set(CFLAGS_OLD ${CMAKE_C_FLAGS}) set(CMAKE_C_FLAGS "" CACHE STRING "" FORCE) if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") find_program(GCOV_EXECUTABLE gcov) endif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang") set(llvm_names llvm_cov) list(APPEND llvm_names llvm-cov) foreach(ver RANGE 11 99) list(APPEND llvm_names llvm-cov-${ver}) endforeach(ver RANGE 11 99) find_program(GCOV_EXECUTABLE NAMES ${llvm_names}) set(llvm_option "gcov") endif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang") add_executable(infcover infcover.c) target_link_libraries(infcover ZLIB::ZLIBSTATIC) target_compile_options(infcover PRIVATE -coverage) target_link_options(infcover PRIVATE -coverage) target_compile_definitions( infcover PRIVATE $<$:HAVE_HIDDEN>) add_test(NAME zlib_coverage COMMAND infcover) set(INFCOVER_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/infcover.dir) add_test( NAME zlib_coverage-summary COMMAND ${GCOV_EXECUTABLE} ${llvm_option} ${CMAKE_CURRENT_SOURCE_DIR}/infcover.c -o ${INFCOVER_DIR}/infcover.c.gcda) set_tests_properties(zlib_coverage-summary PROPERTIES DEPENDS zlib-coverage) set(CMAKE_C_FLAGS ${CFLAGS_OLD} CACHE STRING "" FORCE) endif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") if(HAVE_OFF64_T) add_executable(zlib_static_example64 example.c) target_compile_definitions( zlib_static_example64 PRIVATE ZLIB_BUILD $<$:HAVE_HIDDEN>) target_link_libraries(zlib_static_example64 ZLIB::ZLIBSTATIC) add_test(NAME zlib_static_example64 COMMAND zlib_static_example64) endif(HAVE_OFF64_T) endif(ZLIB_BUILD_STATIC) ``` -------------------------------- ### Install IJG Library (Makefile) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/jpeg/install.txt Use 'make install-lib' to install the IJG library files. ```bash make install-lib ``` -------------------------------- ### Install Pre-built HTML Documentation Source: https://github.com/artifexsoftware/ghostpdl/blob/master/tiff/doc/CMakeLists.txt Installs pre-built HTML documentation to the installation directory. This is used when Sphinx is not configured to build the documentation. ```cmake install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/html-prebuilt/" DESTINATION "${CMAKE_INSTALL_DOCDIR}/manual/html" COMPONENT "runtime") ``` -------------------------------- ### Build and Install OpenJPEG on Unix/Linux/macOS Source: https://github.com/artifexsoftware/ghostpdl/blob/master/openjpeg/INSTALL.md Standard build and installation process using CMake for Unix-like systems. Ensure you have root privileges for the 'make install' step. ```bash mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make make install make clean ``` -------------------------------- ### Build and Install Ghostscript Source: https://github.com/artifexsoftware/ghostpdl/blob/master/contrib/japanese/doc/cdj880.txt Compile and install the Ghostscript software after integrating the custom driver. 'make install' requires root privileges. ```bash make make install ``` -------------------------------- ### Installation Rules Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/contrib/iostream3/CMakeLists.txt Defines installation rules for the shared library, including runtime, archive, and export files. ```cmake if(ZLIB_IOSTREAM3_INSTALL) if(ZLIB_IOSTREAM3_BUILD_SHARED) install( TARGETS zlib_iostream3_iostreamv3 COMPONENT Runtime EXPORT zlibiostream3SharedExport RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") install( EXPORT zlibiostream3SharedExport FILE iostreamv3-shared.cmake NAMESPACE IOSTREAMV3:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3) if(MSVC) install( ``` -------------------------------- ### Install Configuration Scripts Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/CMakeLists.txt Installs libpng-config scripts for different ABI versions. This is conditional on not skipping executable installation and not being on Windows. ```cmake if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL) if(NOT WIN32 OR CYGWIN OR MINGW) install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/libpng${PNGLIB_ABI_VERSION}-config" DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() endif() ``` -------------------------------- ### Build and Install Brotli with CMake Source: https://github.com/artifexsoftware/ghostpdl/blob/master/brotli/README.md Basic CMake commands to build and install Brotli from source. Specify build type and installation prefix as needed. ```bash mkdir out && cd out cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed .. cmake --build . --config Release --target install ``` -------------------------------- ### Install Man Pages Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/CMakeLists.txt Installs the man pages for libpng into the man3 and man5 directories. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL) # Install the man pages. install(FILES libpng.3 libpngpf.3 DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") install(FILES png.5 DESTINATION "${CMAKE_INSTALL_MANDIR}/man5") ``` -------------------------------- ### Build and Install TIFF (In-Tree) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/tiff/doc/html-prebuilt/_sources/build.rst.txt Standard build and installation procedure when configuring within the source directory. ```shell % cd ./tiff-4.0.5 % ./configure ...lots of messages... % make ...lots of messages... % make check ...lots of messages... # make install ``` -------------------------------- ### Install Brotli from Source Source: https://github.com/artifexsoftware/ghostpdl/blob/master/brotli/python/README.md Installs the Python brotli module directly from the source code. ```bash make install ``` -------------------------------- ### Install Development Libraries on Debian/Ubuntu Source: https://github.com/artifexsoftware/ghostpdl/blob/master/openjpeg/INSTALL.md Installs necessary development libraries for OpenJPEG on Debian-based systems using apt-get. ```bash sudo apt-get install liblcms2-dev libtiff-dev libpng-dev libz-dev ``` -------------------------------- ### Conditional Build Directory and Install Setup Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/contrib/blast/test/CMakeLists.txt Sets the working directory and install setup command based on the ZLIB_BUILD_BLAST definition. This determines the installation target and prefix for tests. ```cmake if(DEFINED ZLIB_BUILD_BLAST) set(WORK_DIR ${zlib_BINARY_DIR}) set(inst_setup zlib_install) else(DEFINED ZLIB_BUILD_BLAST) set(WORK_DIR ${blast_BINARY_DIR}) set(inst_setup zlib_blast_install) set(ZLIB_ARG "-DZLIB_DIR=${ZLIB_DIR}") add_test( NAME zlib_blast_install COMMAND ${CMAKE_COMMAND} --install ${blast_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $ WORKING_DIRECTORY ${blast_BINARY_DIR}) set_tests_properties(zlib_blast_install PROPERTIES FIXTURES_SETUP zlib_blast_install) endif(DEFINED ZLIB_BUILD_BLAST) ``` -------------------------------- ### PS2PDF Converter Example Setup Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/API.md Example setup for using the GS DLL as a PS2PDF converter on Windows. It includes preprocessor directives for Windows compatibility and compilation instructions. ```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 ``` -------------------------------- ### On-the-fly Device Switching Example Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/pclxps/ghostpdl.txt Demonstrates switching between output devices and resolutions for the same PCL file within a single command. The file is first rendered at 72dpi on a monochrome X11 device, then at 100dpi on a color X11 device. ```bash pcl6 -r72 -sDEVICE=x11mono mypcl.pcl -r100 -sDEVICE=x11 mypcl.pcl ``` -------------------------------- ### Initialize PNG I/O Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/libpng-manual.txt Sets up the input I/O for libpng using a standard C FILE pointer. The file must be opened in binary mode. ```c png_init_io(png_ptr, fp); ``` -------------------------------- ### Conditional Build Configuration Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/contrib/minizip/test/CMakeLists.txt Sets build directories and installation setup based on whether minizip is built with zlib. Defines a test for minizip installation. ```cmake if(DEFINED ZLIB_BUILD_MINIZIP) set(WORK_DIR ${zlib_BINARY_DIR}) set(inst_setup zlib_install) else(DEFINED ZLIB_BUILD_MINIZIP) set(WORK_DIR ${minizip_BINARY_DIR}) set(inst_setup minizip_install) set(ZLIB_ARG "-DZLIB_DIR=${ZLIB_DIR}") add_test( NAME minizip_install COMMAND ${CMAKE_COMMAND} --install ${minizip_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $ WORKING_DIRECTORY ${minizip_BINARY_DIR}) set_tests_properties(minizip_install PROPERTIES FIXTURES_SETUP minizip_install) endif(DEFINED ZLIB_BUILD_MINIZIP) ``` -------------------------------- ### Display Configure Script Help Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Make.md Execute this command to view a complete list of configuration options available for the `./configure` script. These options allow customization of settings like installation location. ```bash ./configure --help ``` -------------------------------- ### Equivalent Command with -sOutputFile Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Use.md This demonstrates the equivalent command to the -o option example, explicitly showing the -sOutputFile, -dBATCH, and -dNOPAUSE switches. ```bash gs -sDEVICE=jpeg -sOutputFile=out-%d.jpg -dBATCH -dNOPAUSE somefile.ps ``` -------------------------------- ### Input/Output Setup Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/libpng-manual.txt Configures the input source for libpng. By default, it uses `fread` with a `FILE` pointer, but custom I/O methods can be implemented. ```APIDOC ## Input/Output Setup ### Description Configures the input source for libpng. By default, it uses `fread` with a `FILE` pointer, but custom I/O methods can be implemented. ### Functions - `png_init_io(png_ptr, fp)`: Sets up the input stream using a `FILE` pointer. - `png_set_sig_bytes(png_ptr, number)`: Informs libpng about the number of signature bytes already read from the file. - `png_set_compression_buffer_size(png_ptr, buffer_size)`: Sets the zlib compression buffer size for reading compressed data. The default is 8192 bytes. - `png_set_crc_action(png_ptr, crit_action, ancil_action)`: Configures how CRC errors are handled for critical and ancillary chunks, and for ADLER32 errors in IDAT chunks (from libpng-1.6.26). ### Parameters - `png_ptr`: A pointer to the `png_struct`. - `fp`: A valid `FILE` pointer opened in binary mode. - `number`: The number of signature bytes already read. - `buffer_size`: The desired size of the compression buffer. - `crit_action`: Action to take for CRC errors in critical chunks. - `ancil_action`: Action to take for CRC errors in ancillary chunks. ### CRC Action Choices Choices for `crit_action` and `ancil_action`: - `PNG_CRC_DEFAULT` (0): error/quit - `PNG_CRC_ERROR_QUIT` (1): error/quit - `PNG_CRC_WARN_USE` (3): warn/use data - `PNG_CRC_QUIET_USE` (4): quiet/use data - `PNG_CRC_NO_CHANGE` (5): use the current value Additional choice for `ancil_action`: - `PNG_CRC_WARN_DISCARD` (2): warn/discard data ``` -------------------------------- ### Conditional Build Directory Setup Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/contrib/puff/test/CMakeLists.txt Sets the working directory and installation setup based on whether zlib is built with puff. Configures arguments for zlib if puff is not built with it. ```cmake if(DEFINED ZLIB_BUILD_PUFF) set(WORK_DIR ${zlib_BINARY_DIR}) set(inst_setup zlib_install) else(DEFINED ZLIB_BUILD_PUFF) set(WORK_DIR ${puff_BINARY_DIR}) set(inst_setup zlib_puff_install) set(ZLIB_ARG "-DZLIB_DIR=${ZLIB_DIR}") add_test( NAME zlib_puff_install COMMAND ${CMAKE_COMMAND} --install ${puff_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $ WORKING_DIRECTORY ${puff_BINARY_DIR}) set_tests_properties(zlib_puff_install PROPERTIES FIXTURES_SETUP zlib_puff_install) endif(DEFINED ZLIB_BUILD_PUFF) ``` -------------------------------- ### Expat Start Element Handler Example Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/doc/reference.html This handler is called when an element starts. It prints the element name and attributes, then increments the depth. Use this to process element openings and their attributes. ```c int Depth; void XMLCALL start(void *data, const char *el, const char **attr) { int i; for (i = 0; i < Depth; i++) printf(" "); printf("%s", el); for (i = 0; attr[i]; i += 2) { printf(" %s='%s'", attr[i], attr[i + 1]); } printf("\n"); Depth++; } /* End of start handler */ ``` -------------------------------- ### Example: bdftops Command Usage Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Fonts.md An example demonstrating the usage of the `bdftops` command with specific arguments for converting a BDF font and creating a PostScript font file. ```postscript bdftops pzdr.bdf ZapfDingbats.afm pzdr.gsf ZapfDingbats 4100000 1000000.1.41 ``` -------------------------------- ### Get Pass Start Row (libpng) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/libpng-manual.txt Macro to retrieve the starting row in the output image for the first pixel of a given pass in the Adam7 interlacing scheme. 'pass' is in the range 0 to 6. ```c png_uint_32 y = PNG_PASS_START_ROW(pass); ``` -------------------------------- ### Setup C++Builder Project Files Source: https://github.com/artifexsoftware/ghostpdl/blob/master/jpeg/install.txt Use this command to prepare makefiles for C++Builder. It renames configuration files and copies makefiles to be used as project files. Repeatable if using setupcopy-cb. ```makefile make -fmakefile.b32 setup-cb ``` ```makefile make -fmakefile.b32 setupcopy-cb ``` -------------------------------- ### Get Pass Start Column (libpng) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/libpng/libpng-manual.txt Macro to retrieve the starting column in the output image for the first pixel of a given pass in the Adam7 interlacing scheme. 'pass' is in the range 0 to 6. ```c png_uint_32 x = PNG_PASS_START_COL(pass); ``` -------------------------------- ### Build HTML Documentation Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/HowToBuildTheDocs.txt Run this command from the 'doc' directory to build the HTML version of the documentation. The output will be placed in the 'doc/build' folder. ```bash sphinx-build -b html src build ``` -------------------------------- ### Integrate OpenJPEG with CMake Source: https://github.com/artifexsoftware/ghostpdl/blob/master/openjpeg/INSTALL.md Example CMakeLists.txt to find and link the OpenJPEG library for your application. Ensure OpenJPEG is installed and its CMake export file is accessible. ```cmake $ cat CMakeLists.txt find_package(OpenJPEG REQUIRED) include_directories(${OPENJPEG_INCLUDE_DIRS}) add_executable(myapp myapp.c) target_link_libraries(myapp ${OPENJPEG_LIBRARIES}) ``` -------------------------------- ### Initialize Smurf Device Procedures Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Drivers.md Example of an `initialize_device_procs` procedure for a printer device. It calls base class initialization and overrides specific functions. ```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); ... ``` -------------------------------- ### Conditional Build Configuration for iostream3 Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/contrib/iostream3/test/CMakeLists.txt Sets build directory and installation setup based on the ZLIB_BUILD_IOSTREAM3 flag. Defines ZLIB_ARG for passing zlib directory if not built with it. ```cmake if(DEFINED ZLIB_BUILD_IOSTREAM3) set(WORK_DIR ${zlib_BINARY_DIR}) set(inst_setup zlib_install) else(DEFINED ZLIB_BUILD_IOSTREAM3) set(WORK_DIR ${iostreamV3_BINARY_DIR}) set(inst_setup zlib_iostream3_install) set(ZLIB_ARG "-DZLIB_DIR=${ZLIB_DIR}") add_test( NAME zlib_iostream3_install COMMAND ${CMAKE_COMMAND} --install ${iostreamV3_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $ WORKING_DIRECTORY ${iostreamV3_BINARY_DIR}) set_tests_properties(zlib_iostream3_install PROPERTIES FIXTURES_SETUP zlib_iostream3_install) endif(DEFINED ZLIB_BUILD_IOSTREAM3) ``` -------------------------------- ### Rinkj Driver Command Line Invocation Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Devices.md 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 ``` -------------------------------- ### DisplayDeviceOpen Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/LanguageBindingsCSharp.md Sets up the display device in advance. ```APIDOC ## DisplayDeviceOpen ### Description Sets up the [display device](Devices.md#devices-display-devices) ahead of time. ### Signature ```csharp public gsParamState_t DisplayDeviceOpen() ``` ### Sample Code ```csharp m_ghostscript.DisplayDeviceOpen(); ``` ### Note Calling this method instantiates Ghostscript and configures the encoding and the callbacks for the display device. ``` -------------------------------- ### Namespace Declaration Handler Example Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/doc/reference.html Illustrates setting namespace declaration handlers using XML_SetNamespaceDeclHandler. The StartNamespaceDeclHandler is called before the start tag handler, and EndNamespaceDeclHandler after the corresponding end tag. ```c static void XMLCALL start_namespace_decl_handler(void *userData, const XML_Char *prefix, const XML_Char *uri) { /* Handle namespace declaration */ } static void XMLCALL end_namespace_decl_handler(void *userData, const XML_Char *prefix) { /* Handle end of namespace scope */ } ``` -------------------------------- ### Configure and Build Expat on Unix Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/doc/reference.html Run the configure script to set up Makefiles and headers for your system. Then, build and install Expat using make. This assumes default installation paths. ```bash ./configure make make install ``` -------------------------------- ### Decode Table Example: Table Y (Second Level) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/doc/algorithm.txt Presents the second-level decode table, 'Table Y', for codes starting with '111'. It uses 3-bit entries to decode symbols that extend beyond the initial 3-bit lookup. ```text 000: F,2 001: F,2 010: G,2 011: G,2 100: H,2 101: H,2 110: I,3 111: J,3 ``` -------------------------------- ### `DisplayDeviceOpen` Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/LanguageBindingsCSharp.md Initializes the display device, instantiating Ghostscript and configuring encoding and callbacks for the display device. ```APIDOC ### `DisplayDeviceOpen` Sets up the [display device](Devices.md#devices-display-devices) ahead of time. ```csharp public gsParamState_t DisplayDeviceOpen() ``` **Sample code:** ```csharp m_ghostscript.DisplayDeviceOpen(); ``` #### NOTE Calling this method instantiates Ghostscript and configures the encoding and the callbacks for the display device. ``` -------------------------------- ### Decode Table Example: Table X (Second Level) Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/doc/algorithm.txt Details the second-level decode table, 'Table X', which handles codes starting with '110'. This table uses 2-bit entries to resolve symbols that require more than 3 bits from the initial lookup. ```text 00: C,1 01: C,1 10: D,2 11: E,2 ``` -------------------------------- ### OpenVMS Add Help Instructions Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Install.md Integrate Ghostscript help instructions into the system-wide help file on OpenVMS. ```bash $ lib/help sys$help:HELPLIB.HLB DISK1:[DIR.GHOSTSCRIPT.DOC]GS-VMS.HLP ``` -------------------------------- ### IJS Command Line Example Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Devices.md A typical command line for using the IJS device with Ghostscript. This example demonstrates how to specify the IJS server, device manufacturer and model, and output file. ```bash gs -dSAFER -sDEVICE=ijs -sIjsServer=hpijs -sDeviceManufacturer=HEWLETT-PACKARD -sDeviceModel='DESKJET 990' -dIjsUseOutputFD -sOutputFile=/dev/usb/lp1 -dNOPAUSE -- examples/tiger.eps ``` -------------------------------- ### Write Multi-Page TIFF with SubIFDs in C Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/multi_page.md This C code example illustrates writing a multi-page TIFF file. It shows how to configure and write main IFDs and optionally include SubIFDs for each main IFD, useful for thumbnails or associated data. Ensure libtiff is installed and linked. ```c #include int main(int argc, const char **argv) { TIFF *tiff; /* Define the number of pages/images (main-IFDs) you are going to write */ int number_of_images = 3; /* Define the number of sub - IFDs you are going to write */ #define NUMBER_OF_SUBIFDs 2 int number_of_sub_IFDs = NUMBER_OF_SUBIFDs; toff_t sub_IFDs_offsets[NUMBER_OF_SUBIFDs] = { 0UL}; /* array for SubIFD tag */ int blnWriteSubIFD = 0; if (!(tiff = TIFFOpen("multiPageTiff2.tif", "w"))) return 1; for (int i = 0; i < number_of_images; i++) { char pixel[1] = {128}; TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1); TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1); TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); /* For the last but one multi-page image, add a SubIFD e.g. for a * thumbnail */ if (number_of_images - 2 == i) blnWriteSubIFD = 1; if (blnWriteSubIFD) { /* Now here is the trick: the next n directories written * will be sub-IFDs of the main-IFD (where n is number_of_subIFDs * specified when you set the TIFFTAG_SUBIFD field. * The SubIFD offset array sub_IFDs_offsets is filled automatically * with the proper offset values by the following number_of_subIFDs * TIFFWriteDirectory() calls and updated in the related main-IFD * with the last call. */ if (!TIFFSetField(tiff, TIFFTAG_SUBIFD, number_of_sub_IFDs, sub_IFDs_offsets)) return 1; } /* Write dummy pixel to image */ if (TIFFWriteScanline(tiff, pixel, 0, 0) < 0) return 1; /* Write image / directory to file */ if (!TIFFWriteDirectory(tiff)) return 1; if (blnWriteSubIFD) { /* A SubIFD tag has been written for that main-IFD and this * triggers that previous TIFFWriteDirectory() to switch to the * SubIFD-chain for the next number_of_sub_IFDs writings. * Thus, only the thumbnail images need to be * set up and written to file using TIFFWriteDirectory(). * The last of this TIFFWriteDirectory() calls will setup * the next fresh main-IFD. */ for (int i = 0; i < number_of_sub_IFDs; i++) { TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, 1); TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, 1); TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 1); TIFFSetField(tiff, TIFFTAG_BITSPERAMPLE, 8); TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); /* SUBFILETYPE tag is not mandatory for SubIFD writing, but a * good idea to indicate thumbnails */ if (!TIFFSetField(tiff, TIFFTAG_SUBFILETYPE, FILETYPE_REDUCEDIMAGE)) return 1; /* Write dummy pixel to thumbnail image */ pixel[0] = 64; if (TIFFWriteScanline(tiff, pixel, 0, 0) < 0) return 1; /* Writes now in the SubIFD chain */ if (!TIFFWriteDirectory(tiff)) return 1; blnWriteSubIFD = 0; } } } TIFFClose(tiff); return 0; } ``` -------------------------------- ### Example: PNG Output with Downscaling Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/Devices.md This example demonstrates using the png16m device with a resolution of 600dpi and a downscale factor of 3 to produce a 200dpi output file. ```bash gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o tiger.png\ examples/tiger.eps ``` -------------------------------- ### Example Usage of TIFFOpenOptions Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/functions/TIFFOpenOptions.md Demonstrates allocating options, setting memory limits and custom handlers, opening a TIFF file with extended options, and then freeing the options structure. ```c #include "tiffio.h" #include typedef struct MyErrorHandlerUserDataStruct { /* ... any user data structure ... */ } MyErrorHandlerUserDataStruct; static int myErrorHandler(TIFF *tiff, void *user_data, const char *module, const char *fmt, va_list ap) { MyErrorHandlerUserDataStruct *errorhandler_user_data = (MyErrorHandlerUserDataStruct *)user_data; /*... code of myErrorHandler ...*/ return 1; } main() { tmsize_t limit = (256 * 1024 * 1024); MyErrorHandlerUserDataStruct user_data = { /* ... any data ... */}; TIFFOpenOptions *opts = TIFFOpenOptionsAlloc(); TIFFOpenOptionsSetMaxSingleMemAlloc(opts, limit); TIFFOpenOptionsSetErrorHandlerExtR(opts, myErrorHandler, &user_data); TIFF *tif = TIFFOpenExt("foo.tif", "r", opts); TIFFOpenOptionsFree(opts); /* ... go on here ... */ TIFFClose(tif); } ``` -------------------------------- ### Install Expat with DESTDIR Source: https://github.com/artifexsoftware/ghostpdl/blob/master/expat/README.md Use the DESTDIR variable during 'make install' to override the installation path, useful for creating staged installations or images. ```bash make install DESTDIR=/path/to/image ``` -------------------------------- ### Configure ZLIB Installation Test Source: https://github.com/artifexsoftware/ghostpdl/blob/master/zlib/test/CMakeLists.txt Sets up a test to verify the installation of the ZLIB library by running 'cmake --install'. This test is configured to run after the installation is complete. ```cmake add_test( NAME zlib_install COMMAND ${CMAKE_COMMAND} --install ${zlib_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install --config $ WORKING_DIRECTORY ${zlib_BINARY_DIR}) set_tests_properties(zlib_install PROPERTIES FIXTURES_SETUP zlib_install) ``` -------------------------------- ### Configure TIFF with Fine-Tuned Installation Directories Source: https://github.com/artifexsoftware/ghostpdl/blob/master/tiff/doc/html-prebuilt/_sources/build.rst.txt Demonstrates using specific options to control the installation locations of executables, libraries, and data files. ```shell ./configure --bindir=/opt/tiff/bin --libdir=/opt/tiff/lib ``` -------------------------------- ### Install TIFF Library and Headers Source: https://github.com/artifexsoftware/ghostpdl/blob/master/tiff/libtiff/CMakeLists.txt Installs the tiffxx library and its associated headers to the specified installation directories. This is typically used when building and installing the library for use in other projects. ```cmake install(TARGETS tiffxx RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${tiffxx_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") ``` -------------------------------- ### uniprint Driver Example on Linux Source: https://github.com/artifexsoftware/ghostpdl/blob/master/doc/src/UnsupportedDevices.md This example demonstrates how to use the uniprint driver on a Linux system to print a PostScript file to a specific printer device. ```bash gs @stc.upp -sOutputFile=/dev/lp1 tiger.eps -c quit ```