Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







In an earlier article, we learned how to export PDF documents to Windows metafiles. This was a bit complicated because .NET does not have an encoder for EMF or WMF, and we had to manage with some unmanaged calls. EMF files are useful only Windows. For wider use, we may need BMP, JPEG, PNG or other raster image formats.
Exporting PDF page content to a raster image format is much more simpler. (In the older article, there were code comments that hinted as much.) The example source code in this article shows us how.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using Gnostice.PDFOne;
namespace PDFOne_dotNET_Examples {
class Convert_PDF_To_Images {
static void Main(string[] args) {
// Create a metafile
Metafile metafile;
// Load a PDF document
PDFDocument doc =
new PDFDocument("Your license key");
// Load the input document and get its page count
doc.Load("input_doc.pdf");
Console.WriteLine("Document loaded.");
// Iterate through all pages in the document
for (int i = 1; i <= doc.GetPageCount(); i++) {
// Export current page as a metafile
metafile = doc.GetPageMetafile(i);
// Save metafile to PNG and JPEG formats
metafile.Save(
"image_of_page_#" + i.ToString() + ".png",
ImageFormat.Png);
metafile.Save(
"image_of_page_#" + i.ToString() + ".jpg",
ImageFormat.Jpeg);
Console.Write("\rPage #1-" + i + " exported.");
// Release any resources used by the metafile
metafile.Dispose();
}
// Clean up
doc.Close();
Console.WriteLine("\nDocument closed.");
doc.Dispose();
Console.WriteLine("Press Enter to exit.");
Console.In.ReadLine();
}
}
}
What we do here is iterate through all the pages, export page contents as a metafile, and save the metafile as a PNG and JPEG image. That's it. (The program would have been smaller if it were not for the obsession with console output. ☺)
---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).