User Guide > How to Work with... > Formats with Additional Functionality > PDF > Getting Started with ImageGear PDF |
This section provides information about the following:
Our suite of PDF samples will help you get started using ImageGear's PDF capabilities.
This section also provides step-by-step PDF tutorials, which show you how to create a new ImageGear project using the PDF component:
The ImageGear.Formats.PDF namespace allows you to load, save, and process native PDF and PostScript documents. It also allows rasterization of PDF and PostScript documents, by converting them to bitmaps, and provides you with the ability to extract text from loaded PDF and PostScript documents.
The ImageGear.Formats.PDF namespace provides full multi-page read and write support for the entire document as well as a specified set of pages. You can detect, read, write, append, insert, replace, swap, and delete a specified page in the PDF document as well as to edit its content.
To enable the ImageGear.Formats.PDF Namespace in your project, specify the following directive:
Copy Code | |
---|---|
using ImageGear.Formats.PDF; |
You can use our NuGet packages to ensure you have met all required dependencies or run the Deployment Packaging Wizard (DPW) specifying the exact dependencies needed.
NuGet packages make it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework. See NuGet Packages for more information.
https://www.microsoft.com/en-us/download/details.aspx?id=5555
https://www.microsoft.com/en-us/download/details.aspx?id=14632
https://www.microsoft.com/en-us/download/details.aspx?id=8328
https://www.microsoft.com/en-us/download/details.aspx?id=13523
For more information, see Distributing PDF and PS Fonts and Libraries with an Application.
Copy Code | |
---|---|
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePDFFormat(@"C:\Users\Public\Documents\Accusoft\ImageGear.NET v23\Bin")); ImGearPDF.Initialize(@"C:\Users\Public\Documents\Accusoft\ImageGear.NET v23\Bin"); |
Copy Code | |
---|---|
<appSettings> ...... <add key="igPdfResources" value="C:\Users\Public\Documents\Accusoft\ImageGear.NET v23\Bin" /> <add key="igBinaries" value="C:\Users\Public\Documents\Accusoft\ImageGear.NET v23\Bin" /> </appSettings> |
For more information about working with the web.config file, see Using the ASP.NET Web.Config Editor Application for Configuring Your Web Application.
All PDF objects, such as ImGearPDEColorspace, ImGearPDFPage, and ImGearPDEContent, are based on underlying low-level PDF objects, which are not controlled by .NET resource manager and garbage collector. Due to complex dependencies between these objects, it is not possible to wrap these objects with a fully-automated .NET lifecycle management. For example, disposing an ImGearPDFPage object whose content was obtained with the GetContent method and was not released with ReleaseContent can lead to an internal PDF exception.
So, each PDF object that is obtained or created from scratch should be disposed explicitly using its Dispose() method (as an alternative, “using” syntax can be applied).
Failure to dispose of PDF Documents and Pages can cause significant memory issues in the running application and lingering issues, in the form of abandoned temp files, after the application has terminated. |
Also, an ImGearPDEContent object obtained from ImGearPDFPage should be released using the ImGearPDFPage.ReleaseContent() method in all cases.
An ImGearPDEContent object obtained from a Container, Group, or Form does not need to be released, so ImGearPDEContainer, ImGearPDEForm, and ImGearPDEGroup do not have such a method. |
Here is sample code to illustrate this:
C# |
Copy Code |
---|---|
public void IterateElements(ImGearDocument imageDocument) { ImGearPDFDocument pdfDocument = (ImGearPDFDocument)imageDocument; for (int index = 0; index < pdfDocument.Pages.Count; index++) { try { ImGearPage page = pdfDocument.Pages[index]; // content should be disposed ImGearPDEContent content = ((ImGearPDFPage)page).GetContent(); for (int elementIndex = 0; elementIndex < content.ElementCount; elementIndex++) { ImGearPDEElement element = content.GetElement(elementIndex); if (!TryLoadElement(element)) { throw new Exception(); } element.Dispose(); } // ReleaseContent should be called for a page ((ImGearPDFPage)page).ReleaseContent(); // dispose content content.Dispose(); } catch (Exception ex) { MessageBox.Show("Error”); } } // ImGearPDFDocument object should be disposed too. We’ve left it to caller. } |
The ImageGear.Formats.PDF namespace loads PostScript files by converting them to PDF first and applying a set of default conversion settings. To adjust the results of that conversion, ImageGear .NET PDF namespace implements JobOptionsFile PostScript filter control parameter that can be pointed to one of the .joboptions files distributed with the product. A .joboptions file contains settings that control the conversion from PostScript or EPS to PDF performed on-the-fly for rendering PostScript and EPS in ImageGear .NET. If you encounter any problems with PostScript or EPS rendering or conversion to PDF, such as color or layout differences, you can use the provided "Bin\Resource\PS\Settings\Standard.joboptions" by setting the value of JobOptionsFile PostScript filter control parameter to the full path of the location of that file.