Ghostscript.NET - (written in C#) is the most completed managed wrapper library around the Ghostscript library (32-bit & 64-bit), an interpreter for the PostScript language, PDF, related software and documentation.
Note: This project currently only works with versions of Ghostscript < 10, see release versions.
NuGet: PM> Install-Package Ghostscript.NET
Contains
- GhostscriptViewer - View PDF, EPS or multi-page PostScript files on the screen
- GhostscriptRasterizer - Rasterize PDF, EPS or multi-page PostScript files to any common image format.
- GhostscriptProcessor - An easy way to call a Ghostscript library with a custom arguments / switches.
- GhostscriptInterpreter - The PostScript interpreter.
Other features
- allows you to rasterize files in memory without storing the output to disk.
- supports zoom-in and zoom-out.
- supports progressive update.
- allows you to run multiple Ghostscript instances simultaneously within a single process.
- compatible with 32-bit and 64-bit Ghostscript native library.
Latest changes - 2021-03-09 - v.1.2.3.
- fixed GhostscriptRasterizer/GhostscriptViewer and Ghostscript v.9.50+ compatibility issues.
Latest changes - 2021-02-04 - v.1.2.2.
- fixed Ghostscript v.9.26 + (all later versions) compatibility.
- fixed problem when opening path/file that contains non ASCII characters.
- fixed "Arithmetic operation resulted in an overflow" when using multithread instance.
- changed Y and Y DPI settings to match GhostscriptViewer.
- fixed CurrentPage -> TotalPages logging.
- fixed watermark transparency bug for PDF.
Samples built on the top of the Ghostscript.NET library
Direct postscript interpretation via Ghostscript.NET:
Ghostscript.NET.Viewer (supports viewing of the PDF, EPS and multi-page PS files):
The Ghostscript.NET.PDFA3Converter
extension of the Ghostscript.NET library simplifies converting existing PDF files into PDF/A-3 format. This format is particularly useful for embedding XML-based representations of invoices, such as those used in XRechnung and Factur-X standards.
- Supports the embedding of XML-based invoices into PDF/A-3 format.
- Includes necessary ICC profiles and pdfMark templates for compliance with PDF/A-3 standards.
- Designed to support electronic invoicing initiatives such as XRechnung and Factur-X.
To convert an existing PDF file to PDF/A-3, the following code snippet demonstrates the process:
PDFA3Converter converter = new PDFA3Converter(@"%PROGRAM FILES%\gs\gs9.56.1\bin\gsdll64.dll"); // Specify the Ghostscript DLL path
converter.ConvertToPDFA3(@"sample-invoice.pdf", @"sample-invoice-pdfa3.pdf"); // Convert input PDF to PDF/A-3
This method will generate a plain PDF/A-3 file without any embedded XML invoice.
The primary use case for PDF/A-3 in Europe involves embedding XML invoices within a PDF document, providing both machine-readable (XML) and human-readable (PDF) representations. This includes initiatives such as XRechnung and Factur-X.
To understand how the Ghostscript.NET.PDFA3Converter extension works, the Ghostscript.NET.PDFA3Converter.Samples project includes a couple of samples along with a sample implementation of a ZUGFeRD generator, generated out of the Mustang project. More ZUGFeRD/ XRechnung generators are available, for example ZUGFeRD-csharp.
You can generate an XML invoice using either the Mustang sample implementation or the ZUGFeRD-csharp library.
In order to generate the xml invoice, you can use either the Mustang sample implementation like this:
Invoice i = (new Invoice()).setDueDate(DateTime.Now).setIssueDate(DateTime.Now).setDeliveryDate(DateTime.Now).setSender((new TradeParty("Test company", "Test Street 1", "55232", "Test City", "DE")).addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test", "+49123456789", "[email protected]")).addBankDetails(new BankDetails("DE12500105170648489890", "COBADEFXXX"))).setRecipient(new TradeParty("Franz Müller", "Test Steet 12", "55232", "Entenhausen", "DE")).setReferenceNumber("991-01484-64").setNumber("123").
addItem(new Item(new Product("Test product", "", "C62", 19m), 1.0m, 1.0m));
ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();
zf2p.setProfile(Profiles.getByName("XRechnung"));
zf2p.generateXML(i);
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
string outfilename = "factur-x.xml";
File.WriteAllBytes(outfilename, zf2p.getXML());
Using ZUGFeRD-csharp:
string outFilename = "factur-x.xml";
InvoiceDescriptor invoice = CreateInvoice(); // please see the sample project for details on how the invoice structure is created
invoice.Save(outFilename, ZUGFeRDVersion.Version23, s2industries.ZUGFeRD.Profile.Comfort);
Both examples output the XML invoice as factur-x.xml
.
Once the XML invoice is generated, it can be embedded into a PDF/A-3 file using the PDFA3Converter
class. The converter also supports tagging the file with the correct ZUGFeRD profile and version:
PDFA3Converter converter = new PDFA3Converter(@"%PROGRAM FILES%\gs9.56.1\bin\gsdll64.dll");
converter.SetZUGFeRDProfile(...);
converter.SetZUGFeRDVersion("2.3");
converter.SetEmbeddedXMLFile(outfilename); // the xml invoice file that was just generated
converter.ConvertToPDFA3(@"sample-invoice.pdf", @"sample-invoice-pdfa3.pdf");
Available under both, open-source AGPL and commercial license agreements.
Please read the full text of the AGPL license agreement (which is also included here in file COPYING) to ensure that your use case complies with the guidelines of this license. If you determine you cannot meet the requirements of the AGPL, please contact Artifex for more information regarding a commercial license.
Artifex is the exclusive commercial licensing agent for Ghostscript.