This project implements a virtual PostScript printer using C#. It creates a TCP listener that acts as a network printer, intercepts print jobs, saves them as PostScript files, and converts them to PDF format using Ghostscript.NET.
- Acts as a virtual network printer on localhost:8888
- Intercepts print jobs and saves raw PostScript data
- Converts PostScript files to PDF using Ghostscript.NET
- Extracts metadata from print jobs (title, author, filename)
- Logs server activities and individual print job details
- Windows operating system
- .NET 6.0 or later
- Ghostscript installed on the system (required for Ghostscript.NET)
Download and install Ghostscript from the official website: https://www.ghostscript.com/releases/gsdnld.html
Open the project in your code editor and install the following NuGet package:
- Ghostscript.NET
-
Run addprinter.ps1 powershell script as Admin
-
Manual installation
- Go to 'Printers & scanners' in Windows Settings
- Click 'Add a printer or scanner' (and wait a sec)
- Choose 'The printer that I want isn't listed'
- Select 'Add a printer using a an IP address or hostname'
- Enter the following details:
- Device type: TCP/IP Device
- Hostname or IP address: 127.0.0.1
- Port name: 8888
- Click 'Next'
- (windows will try to detect a printer on this port config ... you will get an error, ignore it and keep the setting to General Network Card and click next)*
- For the driver, select 'Microsoft PS Class Driver'
- Choose a printer name (e.g., "Virtual PostScript Printer")
- Complete the wizard
-
Run the application. It will start listening for print jobs on localhost:8888.
-
Send a print job to the virtual printer you set up.
-
The application will:
- Save the raw PostScript file
- Convert the PostScript to PDF
- Extract and log metadata
- Save all files and logs in the 'PrintJobs' directory (by default)
-
Check the 'PrintJobs' directory for:
- Original PostScript files (.ps)
- Converted PDF files (.pdf)
- Job log (job_log.txt)
- Server log (server_log.txt)
- Use the powershell installer script to install the service.
- Make sure it is the same directory as the compiled exe of the service
- To change the output directory, modify the
PrintServer
constructor call inProgram.cs
. - To adjust PDF conversion settings, modify the
ConvertPsToPdf
method inPrintServer.cs
.
- Ensure Ghostscript is properly installed and its bin directory is in your system PATH.
- Check that no other application is using port 8888.
- Review the server_log.txt for any error messages or issues.
- This project uses Ghostscript.NET, which is based on Ghostscript.