Conversion (31)
.NET PDF to JPG Converter: Convert PDF Pages to Images in C#
2025-09-10 03:20:19 Written by Administrator
Working with PDF documents is a common requirement in modern applications. Whether you are building a document management system , an ASP.NET web service , or a desktop viewer application , there are times when you need to display a PDF page as an image. Instead of embedding the full PDF viewer, you can convert PDF pages to JPG images and use them wherever images are supported.
In this guide, we will walk through a step-by-step tutorial on how to convert PDF files to JPG images using Spire.PDF for .NET. We’ll cover the basics of converting a single page, handling multiple pages, adjusting resolution and quality, saving images to streams, and even batch converting entire folders of PDFs.
By the end, you’ll have a clear understanding of how to implement PDF-to-image conversion in your .NET projects.
Table of Contents:
- Install .NET PDF-to-JPG Converter Library
- Core Method: SaveAsImage
- Steps to Convert PDF to JPG in C# .NET
- Convert a Single Page to JPG
- Convert Multiple Pages (All or Range)
- Advanced Conversion Options
- Troubleshooting & Best Practices
- Conclusion
- FAQs
Install .NET PDF-to-JPG Converter Library
To perform the conversion, we’ll use Spire.PDF for .NET , a library designed for developers who need full control over PDFs in C#. It supports reading, editing, and converting PDFs without requiring Adobe Acrobat or any third-party dependencies.
Installation via NuGet
You can install Spire.PDF directly into your project using NuGet Package Manager Console:
Install-Package Spire.PDF
Alternatively, open NuGet Package Manager in Visual Studio, search for Spire.PDF , and click Install.
Licensing Note
Spire.PDF offers a free version with limitations, allowing conversion of only the first few pages. For production use, a commercial license unlocks the full feature set.
Core Method: SaveAsImage
The heart of PDF-to-image conversion in Spire.PDF lies in the SaveAsImage() method provided by the PdfDocument class.
Here’s what you need to know:
-
Syntax (overload 1):
-
Image SaveAsImage(int pageIndex, PdfImageType imageType);
- pageIndex: The zero-based index of the PDF page you want to convert.
- imageType: The type of image to generate, typically PdfImageType.Bitmap.
-
Syntax (overload 2 with resolution):
-
Image SaveAsImage(int pageIndex, PdfImageType imageType, int dpiX, int dpiY);
- dpiX, dpiY: Horizontal and vertical resolution (dots per inch).
Higher DPI = better quality but larger file size.
Supported PdfImageType Values
- Bitmap → returns a raw image.
- Metafile → returns a vector image (less common for JPG export).
Most developers use Bitmap when exporting to JPG.
Steps to Convert PDF to JPG in C# .NET
- Import the Spire.Pdf and System.Drawing namespaces.
- Create a new PdfDocument instance.
- Load the PDF file from the specified path.
- Use SaveAsImage() to convert one or more pages into images.
- Save the generated image(s) in JPG format.
Convert a Single Page to JPG
Here’s a simple workflow to convert a single PDF page to a JPG image:
using Spire.Pdf.Graphics;
using Spire.Pdf;
using System.Drawing.Imaging;
using System.Drawing;
namespace ConvertSpecificPageToPng
{
class Program
{
static void Main(string[] args)
{
// Create a PdfDocument object
PdfDocument doc = new PdfDocument();
// Load a sample PDF document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
// Convert a specific page to a bitmap image
Image image = doc.SaveAsImage(0, PdfImageType.Bitmap);
// Save the image as a JPG file
image.Save("ToJPG.jpg", ImageFormat.Jpeg);
// Disposes resources
doc.Dispose();
}
}
}
Output:

Spire.PDF supports converting PDF to various other image formats like PNG, BMP, SVG, and TIFF. For more details, refer to the documentation: Convert PDF to Image in C#.
Convert Multiple Pages (All or Range)
Convert All Pages
The following loop iterates over all pages, converts each one into an image, and saves it to disk with page numbers in the filename.
for (int i = 0; i < doc.Pages.Count; i++)
{
Image image = doc.SaveAsImage(i, PdfImageType.Bitmap);
string fileName = string.Format("Output\\ToJPG-{0}.jpg", i);
image.Save(fileName, ImageFormat.Jpeg);
}
Convert a Range of Pages
To convert a specific range of pages (e.g., pages 2 to 4), modify the for loop as follows:
for (int i = 1; i <= 3; i++)
{
Image image = doc.SaveAsImage(i, PdfImageType.Bitmap);
string fileName = string.Format("Output\\ToJPG-{0}.jpg", i);
image.Save(fileName, ImageFormat.Jpeg);
}
Advanced Conversion Options
Set Image Resolution/Quality
By default, the output resolution might be too low for printing or detailed analysis. You can set DPI explicitly:
Image image = doc.SaveAsImage(0, PdfImageType.Bitmap, 300, 300);
image.Save("ToJPG.jpg", ImageFormat.Jpeg);
Tips:
- 72 DPI : Default, screen quality.
- 150 DPI : Good for previews and web.
- 300 DPI : High quality, suitable for printing.
Higher DPI results in sharper images but also increases memory and file size.
Save the Converted Images as Stream
Instead of writing directly to disk, you can store the output in memory streams. This is useful in:
- ASP.NET applications returning images to browsers.
- Web APIs sending images as HTTP responses.
- Database storage for binary blobs.
using (MemoryStream ms = new MemoryStream())
{
pdf.SaveAsImage(0, PdfImageType.Bitmap, 300, 300).Save(ms, ImageFormat.Jpeg);
byte[] imageBytes = ms.ToArray();
}
Here, the JPG image is stored as a byte array , ready for further processing.
Batch Conversion (Multiple PDFs)
In scenarios where you need to process multiple PDF documents at once, you can apply batch conversion as shown below:
string[] files = Directory.GetFiles("InputPDFs", "*.pdf");
foreach (string file in files)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(file);
for (int i = 0; i < doc.Pages.Count; i++)
{
Image image = doc.SaveAsImage(i, PdfImageType.Bitmap);
string fileName = Path.GetFileNameWithoutExtension(file);
image.Save($"Output\\{fileName}-Page{i + 1}.jpg", ImageFormat.Jpeg);
}
doc.Dispose();
}
Troubleshooting & Best Practices
Working with PDF-to-image conversion in .NET can come with challenges. Here’s how to address them:
- Large PDFs consume memory
- Use lower DPI (e.g., 150 instead of 300).
- Process in chunks rather than loading everything at once.
- Images are blurry or low quality
- Increase DPI.
- Consider using PNG instead of JPG for sharp diagrams or text.
- File paths cause errors
- Always check that the output directory exists.
- Use Path.Combine() for cross-platform paths.
- Handling password-protected PDFs
- Provide the password when loading:
doc.LoadFromFile("secure.pdf", "password123");
- Dispose objects
- Always call Dispose() on PdfDocument and Image objects to release memory.
Conclusion
Converting PDF to JPG in .NET is straightforward with Spire.PDF for .NET . The library provides the SaveAsImage() method, allowing you to convert a single page or an entire document with just a few lines of code. With options for custom resolution, stream handling, and batch conversion , you can adapt the workflow to desktop apps, web services, or cloud platforms.
By following best practices like managing memory and adjusting resolution, you can ensure efficient, high-quality output that fits your project’s requirements.
If you’re exploring more advanced document processing, Spire also offers libraries for Word, Excel, and PowerPoint, enabling a complete .NET document solution.
FAQs
Q1. Can I convert PDFs to formats other than JPG?
Yes. Spire.PDF supports PNG, BMP, SVG, and other common formats.
Q2. What DPI should I use?
- 72 DPI for thumbnails.
- 150 DPI for web previews.
- 300 DPI for print quality.
Q3. Does Spire.PDF support encrypted PDFs?
Yes, but you need to provide the correct password when loading the file.
Q4. Can I integrate this in ASP.NET?
Yes. You can save images to memory streams and return them as HTTP responses.
Q5. Can I convert images back to PDF?
Yes. You can load JPG, PNG, or BMP files and insert them into PDF pages, effectively converting images back into a PDF.
Get a Free License
To fully experience the capabilities of Spire.PDF for .NET without any evaluation limitations, you can request a free 30-day trial license.
HTML is widely used to present content in web browsers, but preserving its exact layout when sharing or printing can be challenging. PDF, by contrast, is a universally accepted format that reliably maintains document layout across various devices and operating systems. Converting HTML to PDF is particularly useful in web development, especially when creating printable versions of web pages or generating reports from web data.
Spire.PDF for .NET now supports a streamlined method to convert HTML to PDF in C# using the ChromeHtmlConverter class. This tutorial provides step-by-step guidance on performing this conversion effectively.
- Convert HTML to PDF with ChromeHtmlConverter in C#
- Generate Output Logs During HTML to PDF Conversion in C#
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Install Google Chrome
This method requires Google Chrome to perform the conversion. If Chrome is not already installed, you can download it from this link and install it.
Convert HTML to PDF using ChromeHtmlConverter in C#
You can utilize the ChromeHtmlConverter.ConvertToPdf() method to convert an HTML file to a PDF using the Chrome plugin. This method accepts 3 parameters, including the input HTML file path, output PDF file path, and ConvertOptions which allows customization of conversion settings like conversion timeout, PDF paper size and page margins. The detailed steps are as follows.
- Create an instance of the ChromeHtmlConverter class and provide the path to the Chrome plugin (chrome.exe) as a parameter in the class constructor.
- Create an instance of the ConvertOptions class.
- Customize the conversion settings, such as the conversion timeout, the paper size and page margins of the converted PDF through the properties of the ConvertOptions class.
- Convert an HTML file to PDF using the ChromeHtmlConverter.ConvertToPdf() method.
- C#
using Spire.Additions.Chrome;
namespace ConvertHtmlToPdfUsingChrome
{
internal class Program
{
static void Main(string[] args)
{
//Specify the input URL and output PDF file path
string inputUrl = @"https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/C-/VB.NET-Convert-Image-to-PDF.html";
string outputFile = @"HtmlToPDF.pdf";
//Specify the path to the Chrome plugin
string chromeLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
//Create an instance of the ChromeHtmlConverter class
ChromeHtmlConverter converter = new ChromeHtmlConverter(chromeLocation);
// Create an instance of the ConvertOptions class
ConvertOptions options = new ConvertOptions();
//Set conversion timeout
options.Timeout = 10 * 3000;
//Set paper size and page margins of the converted PDF
options.PageSettings = new PageSettings()
{
PaperWidth = 8.27,
PaperHeight = 11.69,
MarginTop = 0,
MarginLeft = 0,
MarginRight = 0,
MarginBottom = 0
};
//Convert the URL to PDF
converter.ConvertToPdf(inputUrl, outputFile, options);
}
}
}
The converted PDF file maintains the same appearance as if the HTML file were printed to PDF directly through the Chrome browser:

Generate Output Logs During HTML to PDF Conversion in C#
Spire.PDF for .NET enables you to generate output logs during HTML to PDF conversion using the Logger class. The detailed steps are as follows.
- Create an instance of the ChromeHtmlConverter class and provide the path to the Chrome plugin (chrome.exe) as a parameter in the class constructor.
- Enable Logging by creating a Logger object and assigning it to the ChromeHtmlConverter.Logger property.
- Create an instance of the ConvertOptions class.
- Customize the conversion settings, such as the conversion timeout, the paper size and page margins of the converted PDF through the properties of the ConvertOptions class.
- Convert an HTML file to PDF using the ChromeHtmlConverter.ConvertToPdf() method.
- C#
using Spire.Additions.Chrome;
namespace ConvertHtmlToPdfUsingChrome
{
internal class Program
{
static void Main(string[] args)
{
//Specify the input URL and output PDF file path
string inputUrl = @"https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/C-/VB.NET-Convert-Image-to-PDF.html";
string outputFile = @"HtmlToPDF.pdf";
// Specify the log file path
string logFilePath = @"Logs.txt";
//Specify the path to the Chrome plugin
string chromeLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
//Create an instance of the ChromeHtmlConverter class
ChromeHtmlConverter converter = new ChromeHtmlConverter(chromeLocation);
//Enable logging
converter.Logger = new Logger(logFilePath);
//Create an instance of the ConvertOptions class
ConvertOptions options = new ConvertOptions();
//Set conversion timeout
options.Timeout = 10 * 3000;
//Set paper size and page margins of the converted PDF
options.PageSettings = new PageSettings()
{
PaperWidth = 8.27,
PaperHeight = 11.69,
MarginTop = 0,
MarginLeft = 0,
MarginRight = 0,
MarginBottom = 0
};
//Convert the URL to PDF
converter.ConvertToPdf(inputUrl, outputFile, options);
}
}
}
Here is the screenshot of the output log file:

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
The need to convert PDF documents into more flexible and editable formats, such as Markdown, has become a common task for developers and content creators. Converting PDFs to Markdown files facilitates easier editing and version control, and enhances content portability across different platforms and applications, making it particularly suitable for modern web publishing workflows. By utilizing Spire.PDF for .NET, developers can automate the conversion process, ensuring that the rich formatting and structure of the original PDFs are preserved in the resulting Markdown files.
This article will demonstrate how to use Spire.PDF for .NET to convert PDF documents to Markdown format with C# code.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF Documents to Markdown Files
With the Spire.PDF for .NET library, developers can easily load any PDF file using the PdfDocument.LoadFromFile(string filename) method and then save the document in the desired format by calling the PdfDocument.SaveToFile(string filename, FileFormat fileFormat) method. To convert a PDF to Markdown format, simply specify the FileFormat.Markdown enumeration as a parameter when invoking the method.
The detailed steps for converting PDF documents to Markdown files are as follows:
- Create an instance of PdfDocument class.
- Load a PDF document using PdfDocument.LoadFromFile(string filename) method.
- Convert the document to a Markdown file using PdfDocument.SaveToFile(string filename, FileFormat.Markdown) method.
- C#
using Spire.Pdf;
namespace PDFToMarkdown
{
class Program
{
static void Main(string[] args)
{
// Create an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
// Load a PDF document
pdf.LoadFromFile("Sample.pdf");
// Convert the document to Markdown file
pdf.SaveToFile("output/PDFToMarkdown.md", FileFormat.Markdown);
// Release resources
pdf.Close();
}
}
}
The PDF Document:

The Result Markdown File:

Convert PDF to Markdown by Streams
In addition to directly reading files for manipulation, Spire.PDF for .NET also supports loading a PDF document from a stream using PdfDocument.LoadFromStream() method and converting it to a Markdown file stream using PdfDocument.SaveToStream() method. Using streams reduces memory usage, supports large files, enables real-time data transfer, and simplifies data exchange with other systems.
The detailed steps for converting PDF documents to Markdown files by streams are as follows:
- Create a Stream object of PDF documents by downloading from the web or reading from a file.
- Load the PDF document from the stream using PdfDocument.LoadFromStream(Stream stream) method.
- Create another Stream object to store the converted Markdown file.
- Convert the PDF document to a Markdown file stream using PdfDocument.SaveToStream(Stream stream, FileFormat.Markdown) method.
- C#
using Spire.Pdf;
using System.IO;
using System.Net.Http;
namespace PDFToMarkdownByStream
{
class Program
{
static async Task Main(string[] args)
{
// Create an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
// Download a PDF document from a url as bytes
using (HttpClient client = new HttpClient())
{
byte[] pdfBytes = await client.GetByteArrayAsync("http://example.com/Sample.pdf");
// Create a MemoryStream using the bytes
using (MemoryStream inputStream = new MemoryStream(pdfBytes))
{
// Load the PDF document from the stream
pdf.LoadFromStream(inputStream);
// Create another MemoryStream object to store the Markdown file
using (MemoryStream outputStream = new MemoryStream())
{
// Convert the PDF document to a Markdown file stream
pdf.SaveToStream(outputStream, FileFormat.Markdown);
outputStream.Position = 0; // Reset the position of the stream for subsequent reads
// Upload the result stream or write it to a file
await client.PostAsync("http://example.com/upload", new StreamContent(outputStream));
File.WriteAllBytes("output.md", outputStream.ToArray());
}
}
}
// Release resources
pdf.Close();
}
}
}
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
If you have multiple images that you want to combine into one file for easier distribution or storage, converting them into a single PDF document is a great solution. This process not only saves space but also ensures that all your images are kept together in one file, making it convenient to share or transfer. In this article, you will learn how to combine several images into a single PDF document in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Combine Multiple Images into a Single PDF in C# and VB.NET
In order to convert all the images in a folder to a PDF, we iterate through each image, add a new page to the PDF with the same size as the image, and then draw the image onto the new page. The following are the detailed steps.
- Create a PdfDocument object.
- Set the page margins to zero using PdfDocument.PageSettings.SetMargins() method.
- Get the folder where the images are stored.
- Iterate through each image file in the folder, and get the width and height of a specific image.
- Add a new page that has the same width and height as the image to the PDF document using PdfDocument.Pages.Add() method.
- Draw the image on the page using PdfPageBase.Canvas.DrawImage() method.
- Save the document using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace ConvertMultipleImagesIntoPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Set the page margins to 0
doc.PageSettings.SetMargins(0);
//Get the folder where the images are stored
DirectoryInfo folder = new DirectoryInfo(@"C:\Users\Administrator\Desktop\Images");
//Iterate through the files in the folder
foreach (FileInfo file in folder.GetFiles())
{
//Load a particular image
Image image = Image.FromFile(file.FullName);
//Get the image width and height
float width = image.PhysicalDimension.Width;
float height = image.PhysicalDimension.Height;
//Add a page that has the same size as the image
PdfPageBase page = doc.Pages.Add(new SizeF(width, height));
//Create a PdfImage object based on the image
PdfImage pdfImage = PdfImage.FromImage(image);
//Draw image at (0, 0) of the page
page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height);
}
//Save to file
doc.SaveToFile("CombinaImagesToPdf.pdf");
doc.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PDF files are great for presenting on different types of devices and sharing across platforms, but it has to admit that editing PDF is a bit challenging. When you receive a PDF file and need to prepare a presentation based on the content inside, it is recommended to convert the PDF file to a PowerPoint document to have a better presentation effect and also to ensure the content can be further edited. This article will demonstrate how to programmatically convert PDF to PowerPoint presentation using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF to PowerPoint Presentation in C# and VB.NET
From Version 8.11.10, Spire.PDF for .NET supports converting PDF to PPTX using PdfDocument.SaveToFile() method. With this method, each page of your PDF file will be converted to a single slide in PowerPoint. Below are the steps to convert a PDF file to an editable PowerPoint document.
- Create a PdfDocument instance.
- Load a sample PDF document using PdfDocument.LoadFromFile() method.
- Save the document as a PowerPoint document using PdfDocument.SaveToFile(string filename, FileFormat.PPTX) method.
- C#
- VB.NET
using Spire.Pdf;
namespace PDFtoPowerPoint
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a sample PDF document
pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.pdf");
//Convert the PDF to PPTX document
pdf.SaveToFile("ConvertPDFtoPowerPoint.pptx", FileFormat.PPTX);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PDF linearization, also known as "Fast Web View", is a way of optimizing PDF files. Ordinarily, users can view a multipage PDF file online only when their web browsers have downloaded all pages from the server. However, if the PDF file is linearized, the browsers can display the first page very quickly even if the full download has not been completed. This article will demonstrate how to convert a PDF to linearized in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
- Package Manager
PM> Install-Package Spire.PDF
Convert PDF to Linearized
The following are the steps to convert a PDF file to linearized:
- Load a PDF file using PdfToLinearizedPdfConverter class.
- Convert the file to linearized using PdfToLinearizedPdfConverter.ToLinearizedPdf() method.
- C#
- VB.NET
using Spire.Pdf.Conversion;
namespace ConvertPdfToLinearized
{
class Program
{
static void Main(string[] args)
{
//Load a PDF file
PdfToLinearizedPdfConverter converter = new PdfToLinearizedPdfConverter("Sample.pdf");
//Convert the file to a linearized PDF
converter.ToLinearizedPdf("Linearized.pdf");
}
}
}
Imports Spire.Pdf.Conversion
Namespace ConvertPdfToLinearized
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Load a PDF file
Dim converter As PdfToLinearizedPdfConverter = New PdfToLinearizedPdfConverter("Sample.pdf")
'Convert the file to a linearized PDF
converter.ToLinearizedPdf("Linearized.pdf")
End Sub
End Class
End Namespace
Open the result file in Adobe Acrobat and take a look at the document properties, you can see the value of “Fast Web View” is Yes which means the file is linearized.

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Converting a PDF with color images to grayscale can help you reduce the file size and print the PDF in a more affordable mode without consuming colored ink. In this article, you will learn how to achieve the conversion programmatically in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
- Package Manager
PM> Install-Package Spire.PDF
Convert PDF to Grayscale
The following are the steps to convert a color PDF to grayscale:
- Load a PDF file using PdfGrayConverter class.
- Convert the PDF to grayscale using PdfGrayConverter.ToGrayPdf() method.
- C#
- VB.NET
using Spire.Pdf.Conversion;
namespace ConvertPdfToGrayscale
{
class Program
{
static void Main(string[] args)
{
//Create a PdfGrayConverter instance and load a PDF file
PdfGrayConverter converter = new PdfGrayConverter(@"Sample.pdf");
//Convert the PDF to grayscale
converter.ToGrayPdf("Grayscale.pdf");
converter.Dispose();
}
}
}
Imports Spire.Pdf.Conversion
Namespace ConvertPdfToGrayscale
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a PdfGrayConverter instance and load a PDF file
Dim converter As PdfGrayConverter = New PdfGrayConverter("Sample.pdf")
'Convert the PDF to grayscale
converter.ToGrayPdf("Grayscale.pdf")
converter.Dispose()
End Sub
End Class
End Namespace
The input PDF:

The output PDF:

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PDF is a versatile file format, but it is difficult to edit. If you want to modify and calculate PDF data, converting PDF to Excel would be an ideal solution. In this article, you will learn how to convert PDF to Excel in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF to Excel in C# and VB.NET
The following are the steps to convert a PDF document to Excel:
- Initialize an instance of PdfDocument class.
- Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
- Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;
namespace ConvertPdfToExcel
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load the PDF document
pdf.LoadFromFile("Sample.pdf");
//Save the PDF document to XLSX
pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX);
}
}
}

Convert a Multi-Page PDF to One Excel Worksheet in C# and VB.NET
The following are the steps to covert a multi-page PDF to one Excel worksheet:
- Initialize an instance of PdfDocument class.
- Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
- Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
- Set PDF to XLSX convert options using PdfDocument.ConvertOptions.SetPdfToXlsxOptions(XlsxLineLayoutOptions) method.
- Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;
namespace ConvertPdfToExcel
{
class Program
{
static void Main(string[] args)
{
//Initialize an instance of PdfDocument class
PdfDocument pdf = new PdfDocument();
//Load the PDF document
pdf.LoadFromFile("Sample1.pdf");
//Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
//The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, true, true, true);
//Set PDF to XLSX convert options
pdf.ConvertOptions.SetPdfToXlsxOptions(options);
//Save the PDF document to XLSX
pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
SVG is a file format for vector graphics, used to create images that can be scaled without loss of quality. However, PDF is more suitable for sharing and printing due to its support for high-quality printing, encryption, digital signatures, and other features. Converting SVG to PDF ensures good image display on different devices and environments, and better protects intellectual property. In this tutorial, we will show you how to convert SVG to PDF and how to add a SVG image to PDF in C# and VB.NET using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for .NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert SVG to PDF in C# and VB.NET
Spire.PDF for .NET provides the PdfDocument.SaveToFile(String, FileFormat) method, which allows users to save an SVG file as a PDF. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample SVG file using PdfDocument.LoadFromFile() method.
- Convert the SVG file to PDF using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
namespace SVGtoPDF
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample SVG file
doc.LoadFromSvg("Sample.svg");
//Save result document
doc.SaveToFile("Result.pdf", FileFormat.PDF);
doc.Dispose();
}
}
}

Add SVG image to PDF in C# and VB.NET
In addition to converting SVG to PDF directly, it also supports adding SVG image files to the specified locations in PDF. Please check the steps as below:
- Create a PdfDocument object and load an SVG file using PdfDocument. LoadFromSvg() method.
- Create a template based on the content of the SVG file using PdfDocument. Pages[].CreateTemplate() method.
- Get the width and height of the template on the page.
- Create another PdfDocument object and load a PDF file using PdfDocument.LoadFromFile() method.
- Draw the template with a custom size at a specified location using PdfDocument.Pages[].Canvas.DrawTemplate() method.
- Save to PDF file using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddSVGImagetoPDF
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc1 = new PdfDocument();
//Load an SVG file
doc1.LoadFromSvg("C:\\Users\\Administrator\\Desktop\\sample.svg");
//Create a template based on the content of the SVG file
PdfTemplate template = doc1.Pages[0].CreateTemplate();
//Get the width and height of the template
float width = template.Width;
float height = template.Height;
//Create another PdfDocument object
PdfDocument doc2 = new PdfDocument();
//Load a PDF file
doc2.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Draw the template with a custom size at a specified location
doc2.Pages[0].Canvas.DrawTemplate(template, new PointF(0, 0), new SizeF(width * 0.8f, height * 0.8f));
//Save to PDF file
doc2.SaveToFile("AddSvgToPdf.pdf", FileFormat.PDF);
doc2.Dispose();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PostScript was developed by Adobe Systems in the 1980s as a way of turning digital graphics or text files into a fixed format ready for printing. With the passage time, although the PostScript (PS) file format is no longer as popular as it once was, now it is still supported by most printers. In this article, you will learn how to how to programmatically convert a PDF file to a PostScript (PS) file using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Convert PDF to PostScript in C# and VB.NET
Converting PDF to PS can improve the quality of the printed output. With Spire.PDF for .NET, you can complete the conversion with only three lines of code. The following are the detailed steps.
- Create a PdfDocument instance.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Save the PDF file as a PS file using PdfDocument.SaveToFile(string filename, FileFormat.POSTSCRIPT) method.
- C#
- VB.NET
using Spire.Pdf;
namespace PDFtoPS
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument document = new PdfDocument();
//Load a sample PDF file
document.LoadFromFile("Test.pdf");
//Save the PDF file as a PS file
document.SaveToFile("toPostScript.ps", FileFormat.POSTSCRIPT);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.