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) |