Steps to upgrade to PDFNet SDK v.4.
For the most up-to-date version of this document, please see
-
Download the latest SDK from http://www.pdftron.com/downloads.html
and extract
the archive to any location (e.g. to C:/PDFNet). -
Update your project solution to use the new library:
[.NET Specifics] Remove the old reference to PDFNet11.DLL and add a
new reference
to PDFNet.DLL. Please note that the DLL is renamed from PDFNet11 to
PDFNet.
[C/C++ Specifics] Add a path to ‘C:/PDFNet/Headers’ to your project
‘include’
directories. Replace the previous PDFNet link dependency (‘Linker /
Input /
Additional Dependencies’) with a reference to ‘C:/PDFNet/Lib/
PDFNetC.lib’.
To simplify development you may want to copy the DLL to ‘Windows32’
folder or to
some other location that is included in your application’s DLL
search path. When
you are deploying the application you will most likely want to
include PDFNetC.DLL
in your application’s executable folder.
-
Instruct the library to run in the production mode by passing the
most up-to-date
license key in the call to PDFNet.Initialize("…my license
key…"). If the
license key is not specified, the library will run in the demo
mode. If the
license key is not valid, PDFNet.Initialize("") will throw an
exception (in this case you may need to obtain the new license key
from in…@pdftron.com). -
Resolve the compilation errors.
The compilation errors will fall in one of the following
categories:
A) Simple name changes.
For example, PDFDoc.GetPagesCout() should be replaced with
GetPageCount().
A listing of symbol changes can be found on ‘What’s New’ page:
B) Changes in the Iterator interface (e.g. used to traverse pages
of fields).
Prior to PDFNet v4, a ‘for’ loop used to traverse all pages in
the document
may look as follows:
PageIterator itr = pdfdoc.PageBegin();
PageIterator end = pdfdoc.PageEnd();
for (; itr!=end; itr.Next()) {
Page pg = itr.Current();
}
PDFNet v4 loop would look as follows:
for (PageIterator = pdfdoc.GetPageIterator(); itr.HasNext();
itr.Next()) {
Page pg = itr.Current();
}
The following code snippet used to fetch the first and fifth
page:
Page first_page = pdfdoc.PageBegin().Current();
Page fifth_page = pdfdoc.PageFind(5).Current();
can be rewritten as follows:
Page first_page = pdfdoc.GetPage(1); // or
pdfdoc.GetPageIterator().Current();
Page fifth_page = pdfdoc.GetPage(5);
if (fifth_page != null) …
Similarly a code snippet used to traverse all form-fields in a
PDF/FDF document
would look as follows:
’ Assuming VB.Net:
Dim itr As FieldIterator = doc.GetFieldIterator()
While itr.HasNext()
Console.WriteLine(“Field name: {0:s}”,
itr.Current().GetName())
itr.Next()
End While
C) Changes in the low-level SDF/Cos API. The SDF/Cos API is
refactored to simplify
coding and thus reduce errors during development. The updated
API is the same
in all programming languages, which also simplifies porting code
from one
language to another. Finally, the new SDF/Cos architecture will
allow PDFNet SDK
to deliver further performance improvements in upcoming PDFNet v.
4.x releases.
For example, the following code snippet used to create a text
annotation using
the SDF API:
Obj text_annot = doc.CreateDict();
text_annot.Put(“Subtype”, doc.CreateName(“Text”));
text_annot.Put(“Open”, doc.CreateBool(true));
text_annot.Put(“Contents”, doc.CreateString(“The quick brown fox
ate the lazy mouse.”));
text_annot.Put(“Rect”, Rect.CreateSDFRect(266, 116, 430, 204));
annot_array.PushBack(text_annot);
can be corrected as fllows:
Obj text_annot = annot_array.PushBackArray();
text_annot.PutName(“Subtype”, “Text”);
text_annot.PutBool(“Open”, true);
text_annot.PutString(“Contents”, “The quick brown fox ate the
lazy mouse.”);
text_annot.PutRect(“Rect”, 266, 116, 430, 204);
For more examples illustrating the use of updated SDF/Cos API,
you may want
take a look at SDF and Annotation sample projects.
D) In case you were passing Obj ‘hints’ in the call to
pdftron.PDF.Image.CreateImage()
or pdftron.PDF.PDFDraw.Export(), please make the following
adjustment:
// Note: The only difference is that mono and gray hint are
created in
// ObjSet instead of using Obj.Create
ObjSet hint_set=new ObjSet(); // A collection of rendering
‘hits’.
// Initialize render ‘gray_hint’ parameter, that is used to
control the
// rendering process. In this case we tell the rasterizer to
export the image
// as 1 Bit Per Component (BPC) image.
Obj mono_hint=hint_set.CreateDict();
mono_hint.PutNumber(“BPC”, 1);
draw.Export(page, “mono.tif”, “TIF”, mono_hint);
// ‘gray_hint’ tells the rasterizer to export the image as
grayscale.
Obj gray_hint=hint_set.CreateDict();
gray_hint.PutName(“ColorSpace”, “Gray”);
draw.Export(page, “gray.png”, “PNG”, gray_hint);