This article is a mirror article of machine translation, please click here to jump to the original article.

View: 467|Reply: 1

[Source] .NET/C# converts PDFs to images based on ImageMagick, GhostScript

[Copy link]
Posted on 2025-9-2 16:28:52 | | | |
Requirements: Each page of the entire PDF file needs to be converted into an image, and the thumbnails of the generated documents are displayed in the foreground.

Magick.NET

ImageMagick is a powerful image processing library that supports over 100 major file formats (excluding subformats). With Magick.NET, you can use ImageMagick in C#/VB.NET/.NET Core applications without having to install ImageMagick on your server or desktop.

Source code address:The hyperlink login is visible.

GhostScript

Ghostscript is an open-source interpreter for handling and manipulating PostScript (PS) and PDF files. It is mainly used to convert these file formats to other formats (such as images, PDFs, PostScript) or to print them out. Ghostscript can be run as a standalone program or embedded in other applications, providing printing, rendering, and conversion capabilities.

Official Website:The hyperlink login is visible.
Download Address:The hyperlink login is visible.

ImageMagick requires GhostScript to parse PDF files. First, the system is installedGhostscript, taking Windows 64-bit system as an example, download address:The hyperlink login is visible.

If it is not installed, the following error will be reported when it is executed:
Unhandled exception. ImageMagick.MagickDelegateErrorException: FailedToExecuteCommand `"gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 - dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" -dPrinted=false  "-sOutputFile=C:/Users/itsvse/AppData/Local/Temp/ magick-HPhqYc77lVjfqnUN0UPHC6fpkhBXbMu6%d" "-fC:/Users/itsvse/AppData/Local/Temp/magick-24IoSVNLhlVqUxyX5TAKlJX2QE9P6VVX" "-fC:/Users/itsvse/AppData/Local/Temp/ magick-OoG2bKCTo5gEIBysNzxLSTvorwe9jp6Z"' (127) @ error/ghostscript-private.h/ExecuteGhostscriptCommand/75

The installation is as follows:



Create a new .NET 8 console app with the following references:

Q8 and Q16 difference

Q8: Each color channel uses 8 bits, the color accuracy is low, suitable for ordinary image processing, and occupies little memory.
Q16: Each color channel uses 16 bits for higher color accuracy, suitable for professional image processing and avoiding color distortion or gradient breakage.

Read PDF files,Each page is converted into an image, the code is as follows:

As shown below:



(End)




Previous:HttpClient in .NET/C# uses the Http/2.0 version protocol
Next:.NET/C# dependency injection service registration Scrutor tool
 Landlord| Posted on 2025-9-2 16:29:59 |
.NET/C# converts PDFs to images based on PDFtoImage
https://www.itsvse.com/thread-10785-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com