Conversion (31)
Spire.PDF allows us to convert a PDF document, a single page or a range of pages in a PDF document to SVG file format. We have introduced how to convert a PDF document to SVG, in this tutorial, we are going to demonstrate how to convert a PDF page to SVG.
Below is the source PDF file we used in this example:

Code snippets:
Step 1: Instantiate an object of PdfDocument class and load the PDF document.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Test.pdf");
Step 2: Convert the first page of the PDF document to SVG using the SaveToFile(string filename, int startIndex, int endIndex, FileFormat fileFormat) method.
doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);
The resultant SVG file looks as follows:

Full code:
using Spire.Pdf;
namespace PDF_Page_to_SVG
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Test.pdf");
doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);
}
}
}
Imports Spire.Pdf
Namespace PDF_Page_to_SVG
Class Program
Private Shared Sub Main(args As String())
Dim doc As New PdfDocument()
doc.LoadFromFile("Test.pdf")
doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG)
End Sub
End Class
End Namespace
We have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.
Here comes to the code snippets:
Step 1: Create a PDF instance.
PdfDocument pdf = new PdfDocument();
Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.
pdf.UseHighQualityImage = true;
Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().
pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
Step 4: Save the document to file.
pdf.SaveToFile("result.pdf");
Effective screenshot of the high quality image after saving XPS as PDF file format:

Full codes:
using Spire.Pdf;
namespace ConvertXPStoPDF
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.UseHighQualityImage = true;
pdf.LoadFromFile("Sample.xps", FileFormat.XPS);
//pdf.LoadFromXPS("Sample.xps");
pdf.SaveToFile("result.pdf", FileFormat.PDF);
}
}
}
SVG (Scalable Vector Graphics) is an image file format used for rendering two-dimensional images on the web. Comparing with other image file formats, SVG has many advantages such as supporting interactivity and animation, allowing users to search, index, script, and compress/enlarge images without losing quality. Occasionally, you may need to convert PDF files to SVG file format, and this article will demonstrate how to accomplish this task using Spire.PDF for .NET.
- Convert a PDF File to SVG in C#/VB.NET
- Convert Selected PDF Pages to SVG in C#/VB.NET
- Convert a PDF File to SVG with Custom Width and Height in C#/VB.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 a PDF File to SVG in C#/VB.NET
Spire.PDF for .NET offers the PdfDocument.SaveToFile(String, FileFormat) method to convert each page in a PDF file to a single SVG file. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert the PDF file to SVG using PdfDocument.SaveToFile(String, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
namespace ConvertPDFtoSVG
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument document = new PdfDocument();
//Load a sample PDF file
document.LoadFromFile("input.pdf");
//Convert PDF to SVG
document.SaveToFile("PDFtoSVG.svg", FileFormat.SVG);
}
}
}

Convert Selected PDF Pages to SVG in C#/VB.NET
The PdfDocument.SaveToFile(String, Int32, Int32, FileFormat) method allows you to convert the specified pages in a PDF file to SVG files. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Convert selected PDF pages to SVG using PdfDocument.SaveToFile(String, Int32, Int32, FileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
namespace PDFPagetoSVG
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
doc.LoadFromFile("input.pdf");
//Convert selected PDF pages to SVG
doc.SaveToFile("PDFPagetoSVG.svg", 1, 2, FileFormat.SVG);
}
}
}

Convert a PDF File to SVG with Custom Width and Height in C#/VB.NET
The PdfConvertOptions.SetPdfToSvgOptions() method offered by Spire.PDF for .NET allows you to specify the width and height of output SVG file. The detailed steps are as follows.
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.LoadFromFile() method.
- Set PDF convert options using PdfDocument.ConvertOptions property.
- Specify the width and height of output SVG file using PdfConvertOptions.SetPdfToSvgOptions() method.
- Convert the PDF file to SVG using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
namespace PDFtoSVG
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument document = new PdfDocument();
//Load a sample PDF file
document.LoadFromFile("input.pdf");
//Specify the width and height of output SVG file
document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f);
//Convert PDF to SVG
document.SaveToFile("result.svg", FileFormat.SVG);
}
}
}

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.
Spire.PDF supports to save the PDF files into different image file formats, such as BMP, JPG, PNG, GIF and TIFF. It also supports to save the PDF files as the Enhanced Metafile (EMF) image file format. This article will demonstrate how to save the PDF file as the EMF image file format in C#. With the help of Spire.PDF, we only need three lines of codes to finish the conversion function.
Note: Before Start, please download the latest version of Spire.PDF and add Spire.Pdf.dll in the bin folder as the reference of Visual Studio.
Here comes to the steps of how to export the PDF file to EMF in C#:
Step 1: Create a new PDF document and load from file.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
Step 2: Call to use the SaveAsImage method to save all the PDF pages as System.Drawing.Imaging.ImageFormat.Emf file format.
for (int i = 0; i < doc.Pages.Count; i++)
{
String fileName = String.Format("Sample-img-{0}.emf", i);
using (Image image = doc.SaveAsImage(i, Spire.Pdf.Graphics.PdfImageType.Metafile, 300, 300))
{
image.Save(fileName, System.Drawing.Imaging.ImageFormat.Emf);
}
}
Effective screenshot:

Full codes:
using Spire.Pdf;
using System;
using System.Drawing;
namespace ConvertPDFtoEMF
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
for (int i = 0; i < doc.Pages.Count; i++)
{
String fileName = String.Format("Sample-img-{0}.emf", i);
using (Image image = doc.SaveAsImage(i, Spire.Pdf.Graphics.PdfImageType.Metafile, 300, 300))
{
image.Save(fileName, System.Drawing.Imaging.ImageFormat.Emf);
}
}
}
}
}
PDF/A is an ISO-standardized version of PDF that supports archiving of files for future use. Documents in PDF/A format can be reproduced in exactly the same way regardless of the software used. Due to its advantages in long-term preservation of digital documents, it may sometimes be necessary to convert PDF to PDF/A. In this article, you will learn how to programmatically convert PDF to PDF/A-1A, 2A, 3A, 1B, 2B and 3B compliant PDF 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 PDF/A
The detailed steps are as follows.
- Specify the input file path and output folder
- Create a PdfStandardsConverter instance and pass in the input file as a parameter.
- Convert the input file to PdfA1A conformance level using PdfStandardsConverter.ToPdfA1A() method.
- Convert the input file to PdfA1B conformance level using PdfStandardsConverter.ToPdfA1B() method.
- Convert the input file to PdfA2A conformance level using PdfStandardsConverter.ToPdfA2A() method.
- Convert the input file to PdfA2B conformance level using PdfStandardsConverter.ToPdfA2B() method.
- Convert the input file to PdfA3A conformance level using PdfStandardsConverter.ToPdfA3A() method.
- Convert the input file to PdfA3B conformance level using PdfStandardsConverter.ToPdfA3B() method.
- C#
- VB.NET
using System;
using Spire.Pdf.Conversion;
namespace ConvertPdf2Pdfa
{
class Program
{
static void Main(string[] args)
{
//Specify input file path
String inputFile = @"C:\Users\Administrator\Desktop\sample.pdf";
//Specify output folder
String outputFolder = @"C:\Users\Administrator\Desktop\Output\";
//Create a PdfStandardsConverter instance, passing in the input file as a parameter
PdfStandardsConverter converter = new PdfStandardsConverter(inputFile);
//Convert to PdfA1A
converter.ToPdfA1A(outputFolder + "ToPdfA1A.pdf");
//Convert to PdfA1B
converter.ToPdfA1B(outputFolder + "ToPdfA1B.pdf");
//Convert to PdfA2A
converter.ToPdfA2A(outputFolder + "ToPdfA2A.pdf");
//Convert to PdfA2B
converter.ToPdfA2B(outputFolder + "ToPdfA2B.pdf");
//Convert to PdfA3A
converter.ToPdfA3A(outputFolder + "ToPdfA3A.pdf");
//Convert to PdfA3B
converter.ToPdfA3B(outputFolder + "ToPdfA3B.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 format is the best choice in many cases, but Word is more flexible when editing or modification is needed. PDF files are typically used for online sharing, printing and archiving, while Word documents are used for creating, editing and formatting documents. Converting a PDF to Word is a good option if you want to re-edit the PDF document. In this article, you will learn how to programmatically convert PDF to Word 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
Background Knowledge
Spire.PDF for .NET provides two modes of conversion. The advantages and disadvantages of these two modes are as follows:
- Fixed Layout Mode: The fixed layout mode has fast conversion speed and is conducive to maintaining the original appearance of PDF files to the greatest extent. However, the editability of the resulting document will be limited since each line of text in PDF will be presented in a separate frame in the generated Word document.
- Flow Recognition Mode: The flow recognition mode is a full recognition mode. The converted content will not be presented in frames, and the structure of the resulting document is flowable. The generated Word document is easy to re-edit but may look different from the original PDF file.
Convert PDF to Fixed-Layout Doc/Docx in C#, VB.NET
By default, the PdfDcoument.SaveToFile() method will convert PDF to Word with fixed layout. The following are the detailed steps.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Convert the PDF document to a Doc or Docx format file using PdfDocument.SaveToFile(String fileName, FileFormat fileFormat) method.
- C#
- VB.NET
using Spire.Pdf;
namespace ConvertPdfToFixedLayoutWord
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Convert PDF to Doc and save it to a specified path
doc.SaveToFile("output/ToDoc.doc", FileFormat.DOC);
//Convert PDF to Docx and save it to a specified path
doc.SaveToFile("output/ToDocx.docx", FileFormat.DOCX);
doc.Close();
}
}
}

Convert PDF to Flexible-Structured Doc/Docx in C#, VB.NET
In addition to the default conversion engine, Spire.PDF for .NET provides another engine called Ps mode, which works better with the flow recognition mode. To enable Ps conversion engine and flow recognition mode, pass (true, true) as the parameters of the PdfDocument.ConvertOptions.SetPdfToDocOptions(bool usePsMode, bool useFlowRecognitionMode) method. The entire steps are as follows.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Enable Ps conversion engine and flow recognition mode using PdfDocument.ConvertOptions.SetPdfToDocOptions(true, true) method.
- Convert the PDF document to a Doc or Docx format file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
namespace ConvertPdfToFlexibleLayoutWord
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF document
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Specify the PDF to Word conversion options
doc.ConvertOptions.SetPdfToDocOptions(true, true);
//Convert PDF to Doc
doc.SaveToFile("output/ToDoc.doc", FileFormat.DOC);
//Convert PDF to Docx
doc.SaveToFile("output/ToDocx.docx", FileFormat.DOCX);
doc.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.
PDF files are widely used for sharing and viewing documents across different platforms, while TIFF files are preferred for storing high-quality images with detailed graphics or photographs. Converting a PDF file to TIFF can maintain the quality of images within the file. Similarly, converting a TIFF image to PDF ensures that the image can be easily viewed, shared, and printed without compatibility issues. In this article, you will learn how to programmatically convert PDF to TIFF or TIFF to PDF in C# 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 TIFF in C#
The TIFF format allows multiple images to be stored in a single file. With Spire.PDF for .NET, you can convert each page of a PDF file into a separate image, and then call the custom method JoinTiffImages() to combine these images and save them as a single TIFF image.
The following are the steps to convert a PDF into a multi-page TIFF file using C#.
- Create a PdfDocument object.
- Load a PDF file using PdfDocument.LoadFromFile() method.
- Call custom method SaveAsImage() to convert each page of the PDF to a separate image.
- Call custom method JoinTiffImages() to merge the converted images into a multi-page TIFF image.
- C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using Spire.Pdf;
namespace SavePdfAsTiff
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a PDF document
pdf.LoadFromFile("Report.pdf");
//Convert PDF pages to images
Image[] images = SaveAsImage(pdf);
//Combine the images and save them as a multi-page TIFF file
JoinTiffImages(images, "result.tiff", EncoderValue.CompressionLZW);
}
private static Image[] SaveAsImage(PdfDocument document)
{
//Create a new image array
Image[] images = new Image[document.Pages.Count];
//Iterate through all pages in the document
for (int i = 0; i < document.Pages.Count; i++)
{
//Convert a specific page to an image
images[i] = document.SaveAsImage(i);
}
return images;
}
private static ImageCodecInfo GetEncoderInfo(string mimeType)
{
//Get the image encoders
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
for (int j = 0; j < encoders.Length; j++)
{
//Find the encoder that matches the specified MIME type
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
throw new Exception(mimeType + " mime type not found in ImageCodecInfo");
}
public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder)
{
//Set the encoder parameters
Encoder enc = Encoder.SaveFlag;
EncoderParameters ep = new EncoderParameters(2);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
ep.Param[1] = new EncoderParameter(Encoder.Compression, (long)compressEncoder);
//Get the first image
Image pages = images[0];
//Initialize a frame
int frame = 0;
//Get an ImageCodecInfo object for processing TIFF image codec information
ImageCodecInfo info = GetEncoderInfo("image/tiff");
//Iterate through each Image
foreach (Image img in images)
{
//If it's the first frame, save it to the output file with specified encoder parameters
if (frame == 0)
{
pages = img;
pages.Save(outFile, info, ep);
}
else
{
//Save the intermediate frames
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
pages.SaveAdd(img, ep);
}
//If it's the last frame, flush the encoder parameters and close the file
if (frame == images.Length - 1)
{
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
pages.SaveAdd(ep);
}
frame++;
}
}
}
}

Convert TIFF to PDF in C#
To convert a multi-page TIFF image to a PDF file, you need to convert each frame of the TIFF image to a separate PDF image. Then draw each image at a specified location on a PDF page through the PdfPageBase.Canvas.DrawImage() method.
The following are the steps to convert a TIFF image to a PDF file using C#.
- Create a PdfDocument object.
- Load a TIFF image using Image.FromFile() method.
- Call custom method SplitTiffImage() to split the TIFF image into separate images.
- Iterate through the split images, and then convert each into a PDF image.
- Add a page to the PDF document using PdfDocument.Pages.Add() method.
- Draw the PDF image at a specified location on the page using PdfPageBase.Canvas.DrawImage() method.
- Save the result PDF file using PdfDocument.SaveToFile() method.
- C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace TiffToPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load a TIFF image
Image tiffImage = Image.FromFile("result.tiff");
//Split the Tiff image into separate images
Image[] images = SplitTiffImage(tiffImage);
//Iterate through the images
for (int i = 0; i < images.Length; i++)
{
//Convert a specified image into a PDF image
PdfImage pdfImg = PdfImage.FromImage(images[i]);
//Get image width and height
float width = pdfImg.Width;
float height = pdfImg.Height;
//Add a page with the same size as the image
SizeF size = new SizeF(width, height);
PdfPageBase page = pdf.Pages.Add(size);
//Draw the image at a specified location on the page
page.Canvas.DrawImage(pdfImg, 0, 0, width, height);
}
//Save the result file
pdf.SaveToFile("TiffToPdf.pdf");
}
public static Image[] SplitTiffImage(Image tiffImage)
{
//Get the number of frames in the Tiff image
int frameCount = tiffImage.GetFrameCount(FrameDimension.Page);
//Create an image array to store the split tiff images
Image[] images = new Image[frameCount];
//Gets the GUID of the first frame dimension
Guid objGuid = tiffImage.FrameDimensionsList[0];
//Create a FrameDimension object
FrameDimension objDimension = new FrameDimension(objGuid);
//Iterate through each frame
for (int i = 0; i < frameCount; i++)
{
//Select a specified frame
tiffImage.SelectActiveFrame(objDimension, i);
//Save the frame in TIFF format to a memory stream
MemoryStream ms = new MemoryStream();
tiffImage.Save(ms, ImageFormat.Tiff);
//Load an image from memory stream
images[i] = Image.FromStream(ms);
}
return images;
}
}
}

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.
Besides convert HTML URL to PDF and HTML file to PDF, now Spire.PDF starts to support converting HTML string to PDF. This article will show you how to convert HTML string into PDF file in C#. We support tables, text and Hyperlinks in the HTML strings. Please check the steps as below:
- Download Spire.PDF for .NET (Version 3.0.27 above) and install it correctly. The Spire.PDF installation is clean, professional and wrapped up in a MSI installer.
- Add Spire.Pdf.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Pdf\Bin\NET4.0\ Spire.Pdf.dll".
- Here comes to the codes:
Step 1: Create a new PDF document.
PdfDocument pdf = new PdfDocument();
Step 2: Set the layout and page setting
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); //webBrowser load html whether Waiting htmlLayoutFormat.IsWaiting = false; //page setting PdfPageSettings setting = new PdfPageSettings(); setting.Size = PdfPageSize.A4;
Step 3: Load the HTML string code and generate the PDF file.
string htmlCode = File.ReadAllText("..\\..\\2.html");
//use single thread to generate the pdf from above html code
Thread thread = new Thread(() =>
{ pdf.LoadFromHTML(htmlCode, false, setting, htmlLayoutFormat);});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
Step 4: Save the file to PDF and preview it.
pdf.SaveToFile("output.pdf");
System.Diagnostics.Process.Start("output.pdf");
Please check the effective screenshot:

Full codes:
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
namespace LoadFromHTML
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = false;
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;
string htmlCode = File.ReadAllText("..\\..\\2.html");
Thread thread = new Thread(() =>
{ pdf.LoadFromHTML(htmlCode, false, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
pdf.SaveToFile("output.pdf");
System.Diagnostics.Process.Start("output.pdf");
}
}
}
Convert PDF Page to Image with Specified Resolution
2013-11-15 08:01:20Spire.PDF is an easy-to-use and powerful .NET PDF library. It can do a lot of conversions, and one of them is converting PDF page to image. As to converting PDF page to image, it works conveniently and flexibly. It has 6 overloaded functions named SaveAsImage that can make sure you find one meeting your need.
You can use Spire.PDF to convert any specific page of PDF document to BMP and Metafile image. Check it here.
In this article, we will discuss conversion with specified resolution.
public Image SaveAsImage(int pageIndex, int dpiX, int dpiY)
- pageIndex: specify which page to convert, 0 indicates the first page.
- dpiX: specify the resolution of x coordinate axis in PDF page when converting.
- dpiX: specify the resolution of y coordinate axis in PDF page when converting.
Image image = documemt.SaveAsImage(0, PdfImageType.Bitmap, false, 400, 400)
In the sample code, the size of PDF page is Width = 612.0, Height = 792.0. We set the resolution to 400, 400. And we will get an image with width = 3400, height = 4400.
Here is sample code:
PdfDocument documemt = new PdfDocument(); documemt.LoadFromFile(@"..\..\EnglishText.pdf"); Image image = documemt.SaveAsImage(0, PdfImageType.Bitmap, false, 400, 400); image.Save(@"..\..\result.jpg"); documemt.Close();
Effect Screentshot:

For the function of converting image to PDF, Spire.PDF can handle it quickly and effectively. This .NET PDF library can not only convert images of commonly used formats to PDF document such as jpg, bmp, png, but also convert gif, tif and ico images to PDF. Just download it here.
To convert multipage image to a PDF file with Spire.PDF, just copy the following code to your application and call method ConvertImagetoPDF and you will get it done.
Step 1: Method to split multipage image
Spire.Pdf has a method called DrawImage to convert image to PDF. But it cannot handle multipage image directly. So before conversion, multipage image need to be split into several one-page images.
Guid guid = image.FrameDimensionsList[0]; FrameDimension dimension = new FrameDimension(guid); int pageCount = image.GetFrameCount(dimension);
This step is to get the total number of frames (pages) in the multipage image.
image.SelectActiveFrame(dimension, i);
And this step is to select one frame of frames within this image object.
image.Save(buffer, format);
Save the selected frame to the buffer.
Step 2: Convert image to PDF
After splitting multipage image, Spire.Pdf can draw these split images directly to PDF using method DrawImage.
PdfImage pdfImg = PdfImage.FromImage(img[i])
Load image file as PdfImage.
page.Canvas.DrawImage(pdfImg, x, 0, width, height);
Draw PdfImage to PDF. The only thing to do is to specify the location of image on PDF. Width and height is the size of area that image will be drawn on. Sometimes we need to scale up or down the size of the original size of image until it fit the PDF page. x and 0 locate the coordinate.
Check the effective screenshots for the original TIF file.
The target PDF file:
Full demo:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace ConvertMultipageImagetoPDF
{
class Program
{
static void Main(string[] args)
{
{
ConvertImagetoPDF(@"..\..\Chapter1.tif");
}
}
public static void ConvertImagetoPDF(String ImageFilename)
{
using (PdfDocument pdfDoc = new PdfDocument())
{
Image image = Image.FromFile(ImageFilename);
Image[] img = SplitImages(image, ImageFormat.Png);
for (int i = 0; i < img.Length; i++)
{
PdfImage pdfImg = PdfImage.FromImage(img[i]);
PdfPageBase page = pdfDoc.Pages.Add();
float width = pdfImg.Width * 0.3f;
float height = pdfImg.Height * 0.3f;
float x = (page.Canvas.ClientSize.Width - width) / 2;
page.Canvas.DrawImage(pdfImg, x, 0, width, height);
}
string PdfFilename = "result.pdf";
pdfDoc.SaveToFile(PdfFilename);
System.Diagnostics.Process.Start(PdfFilename);
}
}
public static Image[] SplitImages(Image image, ImageFormat format)
{
Guid guid = image.FrameDimensionsList[0];
FrameDimension dimension = new FrameDimension(guid);
int pageCount = image.GetFrameCount(dimension);
Image[] frames = new Image[pageCount];
for (int i = 0; i < pageCount; i++)
{
using (MemoryStream buffer = new MemoryStream())
{
image.SelectActiveFrame(dimension, i);
image.Save(buffer, format);
frames[i] = Image.FromStream(buffer);
}
}
return frames;
}
}
}