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