ImageGear for .NET User Guide > Getting Started > ImageGear for .NET Visual Studio 2008/2005 Tutorials > ImageGear for .NET C# WPF Tutorial > Adding PDF Support |
Once the base of the tutorial application is completed, you can extend it with PDF support using the following steps:
You should now have the ImageGear21.Formats.Pdf assembly listed under References in the Solution Explorer.
C# |
Copy Code |
---|---|
using ImageGear.Formats.PDF; |
C# |
Copy Code |
---|---|
ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat()); ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePSFormat()); ImGearPDF.Initialize(); |
This will add PDF and PS formats to the ImageGear formats list and initialize the PDF engine. ImGearPDF.Initialize() must be called once per process, unless you are using multi-threading.
Example Title |
Copy Code |
---|---|
ImGearPDF.Terminate(); |
C# |
Copy Code |
---|---|
void DisposePDFObjects() { if (imGearPage != null && imGearPage is ImGearPDFPage) { imGearPageView1.Display = null; ((ImGearPDFPage)imGearPage).Dispose(); } } |
In Window1 class, add the following field:
C# |
Copy Code |
---|---|
private ImGearDocument igDocument = null; |
In OpenExecuted find the following code:
C# |
Copy Code |
---|---|
// Load the image into the page
igPage = ImGearFileFormats.LoadPage(fileContent, 0); |
C# |
Copy Code |
---|---|
igDocument = ImGearFileFormats.LoadDocument(fileContent, 0, 1); igPage = igDocument.Pages[0]; |
It does the same thing, but using the ImGearDocument API.
Note that ImGearPDFDocument must be disposed just like the ImGearPDFPage. To do it, replace the implementation of DisposePDFObjects() method with the following:
C# |
Copy Code |
---|---|
void DisposePDFObjects() { if (igDocument != null && igDocument is ImGearPDFDocument) { imGearPageView1.Display = null; ((ImGearPDFDocument) igDocument).Dispose(); } } |