User Guide > How to Work with... > Formats with Additional Functionality > PDF > Getting Started with ImageGear PDF > Tutorial: Create Your First PDF Project > Console Application |
In this tutorial, you will configure a C# or VB.NET project for a console application and use ImageGear .NET PDF capabilities. You will also learn how to open a PDF or PS file and save it as a new file.
The following tutorial refers specifically to 64-bit installations; for 32-bit installations:
|
Using the desired version of Visual Studio (2010 or later):
Your output target directory should be set to $YOURLOCALPROJ\bin\x64\Debug\ . |
C# |
Copy Code |
---|---|
using System.IO; using ImageGear.Core; using ImageGear.Formats; using ImageGear.Formats.PDF; using ImageGear.Evaluation; namespace my_first_PDF_project { class Program { public void SaveAs(string fileIn, string fileOut) { // Initialize evaluation license. ImGearEvaluationManager.Initialize(); ImGearEvaluationManager.Mode = ImGearEvaluationMode.Watermark; // Initialize common formats. ImGearCommonFormats.Initialize(); // Add support for PDF and PS files. ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat()); ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePSFormat()); ImGearPDF.Initialize(); using (FileStream inStream = new FileStream(fileIn, FileMode.Open)) { using (FileStream outStream = new FileStream(fileOut, FileMode.Create)) { // Load PDF document. ImGearDocument igDocument = ImGearFileFormats.LoadDocument(inStream); // Save PDF. ImGearPDFSaveOptions pdfOptions = new ImGearPDFSaveOptions(); ImGearFileFormats.SaveDocument(igDocument, outStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, pdfOptions); } } // Dispose of the PDF component. ImGearPDF.Terminate(); } static void Main(string[] args) { Program myProgram = new Program(); myProgram.SaveAs(@"C:\PATHTOPDF\FILENAME.pdf",@"C:\PATHTOPDF\NEWNAME.pdf"); } } } |
VB.NET |
Copy Code |
---|---|
Imports System.IO Imports ImageGear.Core Imports ImageGear.Formats Imports ImageGear.Formats.PDF Imports ImageGear.Evaluation Module Module1 Public Sub SaveAs(fileIn As String, fileOut As String) ' Initialize evaluation license. ImGearEvaluationManager.Initialize() ImGearEvaluationManager.Mode = ImGearEvaluationMode.Watermark ImGearCommonFormats.Initialize() ' Add support for PDF and PS files. ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat()) ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePSFormat()) ImGearPDF.Initialize() Using inStream As New FileStream(fileIn, FileMode.Open) Using outStream As New FileStream(fileOut, FileMode.Create) ' Load PDF document. Dim igDocument As ImGearDocument = ImGearFileFormats.LoadDocument(inStream) ' Save PDF. Dim pdfOptions As New ImGearPDFSaveOptions() ImGearFileFormats.SaveDocument(igDocument, outStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, pdfOptions) End Using End Using ' Dispose of the PDF component. ImGearPDF.Terminate() End Sub Sub Main() SaveAs("C:\PATHTOPDF\FILENAME.pdf", "C:\PATHTOPDF\NEWNAME.pdf.pdf") End Sub End Module |
C# |
Copy Code |
---|---|
// Initialize evaluation license. ImGearEvaluationManager.Initialize(); ImGearEvaluationManager.Mode = ImGearEvaluationMode.Watermark; // Initialize common formats. ImGearCommonFormats.Initialize(); // Add support for PDF and PS files. ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat()); ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePSFormat()); ImGearPDF.Initialize(); |
VB.NET |
Copy Code |
---|---|
' Initialize evaluation license. ImGearEvaluationManager.Initialize() ImGearEvaluationManager.Mode = ImGearEvaluationMode.Watermark ' Initialize common formats. ImGearCommonFormats.Initialize() ' Add support for PDF and PS files. ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat()) ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePSFormat()) ImGearPDF.Initialize() |
C# |
Copy Code |
---|---|
// Save PDF. ImGearPDFSaveOptions pdfOptions = new ImGearPDFSaveOptions(); ImGearFileFormats.SaveDocument(igDocument, outStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, pdfOptions); |
VB.NET |
Copy Code |
---|---|
' Save PDF.
Dim pdfOptions As New ImGearPDFSaveOptions()
ImGearFileFormats.SaveDocument(igDocument, outStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, pdfOptions) |
This sample project was created as a simple introduction to using the PDF functionality in ImageGear. For systems designed for production environments, you need to configure your projects more efficiently by only adding the resources that you need. For more information, refer to Deploying Your Product. |