How to use “PDF Creator Pilot” on x64 systems with Microsoft Visual Studio.

There are two methods you can use to accomplish this in your .NET projects. Let’s suppose we have a C# project, and that “PDF Creator Pilot x64” is already installed.

Method #1

1) Open your project (or create a new one) and choose “Add Reference” in the Solution Manager (you can also do this from the main menu -> Project -> Add Reference…) and then select the “COM” tab.

2) In the component list find “PDFCreatorPilot Type Library” and press the “OK” button.

3) In the code file (*.cs) add this line:

using PDFCreatorLib;

and declare a variable somewhere in your code:

PDFDocument4 pdf = new PDFDocument4();
pdf.SetLicenseData("demo", "demo");
// more code...

4) You may set project target type to “x64” or leave it as “Any CPU”.

If all is done correctly, the PDF Creator Pilot now will be available to you in your project.

In some cases developers may not be able to add a reference as shown in the example above. In that case we recommend that you manually register the COM dll (PDFCreatorPilot.dll) with an administrator’s credentials:

regsvr32 PDFCreatorPilot.dll

After this please restart the Visual Studio and try to add the reference again. If this does not help, then please use Method #2.

Method #2

1) We need to manually create an interop wrapper library for .NET from the “PDF Creator Pilot x64” COM library. Find please where the “PDFCreatorPilot.dll” (x64 version) is located and create a simple batch file with the following line:

"C:\Program Files\Microsoft SDKs\Windows\v6.xx\bin\TlbImp.exe" "full\path\to\PDFCreatorPilot.dll" /out:"Interop.PDFCreatorPilotLib.dll" /namespace:PDFCreatorLib /machine:X64

2) Launch this file. This will produce the “Interop.PDFCreatorPilotLib.dll” file which is an interop library for the COM dll.

Note: the TlbImp.exe is a standard Windows SDK utility. If you do not have it on your machine,  please install the Windows SDK from the Microsoft website.

3) Open your project (or create a new one) and choose “Add Reference” in the Solution Manager (you can also do this from the main menu -> Project -> Add Reference…) and select the “Browse” tab. In the file list find “Interop.PDFCreatorPilotLib.dll” created in the previous step and press the “OK” button.

4) In the code file (*.cs) add this line:

using PDFCreatorLib;
/* PDFCreatorLib is a namespace you've specified as a parameter for TlbImp.exe. */

and declare a variable somewhere in your code:

PDFDocument4 pdf = new PDFDocument4();
pdf.SetLicenseData("demo", "demo");
// more code...

5) You may set the project target type to “x64” or leave it as “Any CPU”.

If all is done correctly, the PDF Creator Pilot now will be available to you in your project.

Max Filimonov

Merge and Split PDFs with PDF Creator Pilot

Do you need to split or merge PDF files and reorganize pages in your PDF documents? If yes, then PDF Creator Pilot library can help you do this. PDF Creator Pilot allows you to not only split, merge, and reorganize pages in your PDFs, but also to create tree-like outlines (bookmarks), annotations, watermarks, thumbnails, and interactive AcroForm elements for your PDF documents.

PDF Library has the following methods for splitting, merging, and reorganizing pages:

  • Append– This method appends the contents of a previously saved PDF file (not a BLOB) to a newly created (or opened) PDF document.
  • Open – This method opens an existing PDF document, then reads and parses its contents.
  • AddPage – This method creates a new PDF page, appending it to the end of the PDF document. It does not set the new page as current.
  • DeletePage – This method removes the specified page from a PDF document.

With the help of PDF Creator Pilot, you can easily and quickly manage your PDFs, reduce the size of PDF files, and quickly combine a group of files using the merge feature.

Artem Golubnichenko

DjVu Converter

The electronic DjVu format is becoming more and more popular. It is intended for storage of scanned documents (forms, electronic books and so on). DjVu is positioned as an alternative to the PDF format. An advantage of DjVu is the lighter size of the DjVu files in comparison to PDF file sizes.

Two Pilots has released a new freeware product for creating DjVu documents. DjVu Printer Pilot is an application based on a virtual printer. After installation of the program, the <DjVu Printer Pilot> virtual printer will be installed in your system. Now you can “print to” this printer any document you wish to be converted into DjVu. While printing, the document is automatically opened  in the DjVu Printer Pilot window. From here you can save the converted DjVu document or combine it with another document created earlier.

For DjVu creation, the DjVuLibre free library is used.

Artem Golubnichenko

Rounding Effect

Look at the picture of the line before inexact rounding of floating points, and at the
picture after rounding:

The problem arose while converting an EMF into a PDF or while drawing an HDC-context taken from a PDF. The problem was connected to the Polyline(To) function. The function transformed an array of points with close value coordinates. Then, to draw a set of lines in a PDF, transformation of the coordinates from HDC to PDF coordinates was necessary. For this transformation the LPtoDP function was used. But LPtoDP returns integer values. For example, this function transforms the (160, 74) and (159, 60) coordinates from EMF to (1, 1) and (1, 2) for a PDF. So a set of lines was generated as shown in the left picture. To improve the results, we have stopped using the LPtoDP function. Now Polyline(To) function gives the correct results.

Artem Golubnichenko

PDF/A is a format for long-term preservation

PDF/A is a electronic document file format for long-term preservation. Standards to address the growing need to maintain information in electronic documents over archival time spans. The feature-rich nature of PDF can create difficulties in preserving information over the long-term, and some useful features of the PDF file format are incompatible with the demands of long-term preservation. For example, PDF documents are not necessarily self-contained, drawing on system fonts and other content stored external to the original file. As time passes, and especially as technology changes, these external connections can be broken, and the dependencies cause information to be lost.

The PDF/A-1 standard is based on Adobe’s PDF Reference 1.4, and specifies how to use a subset of PDF components to develop software that creates, renders and otherwise process a flavor of PDF that is more suitable for archival preservation than traditional PDF. PDF/A-1 aims to preserve the static visual appearance of electronic documents over time and also aims to support future access and future migration needs by providing frameworks for: 1) embedding metadata about electronic documents, and 2) defining the logical structure and semantic properties of electronic documents. The result is a file format, based on PDF 1.4 that is more suitable for long term preservation.
PDF/A-1 files must include:

* Embedded fonts
* Device-independent color
* XMP metadata

The PDF Creator Pilot has property gets or sets the value indicating whether to produce a PDF/A compatible output file. There is ProducePDFA. Setting ProducePDFA to VARIANT_TRUE means that the output PDF file will be built compatible to the PDF/A standard. You should set this property before any text or graphics output.

If you need long-term preservation documents, use the PDF/A docs. With PDF Creator Pilot, you can create such documents easy.

Artem Golubnichenko

New PDF to Image Converter from Two Pilots Company

In the area of circulation of electronic documents, often we need to modify PDF documents into PNG or multipage TIFF images. Two Pilots, has just released a new converter called PDF2Image Pilot, a program for converting PDF files into high-quality BMP, EMF, GIF, JPEG, PNG, or TIFF images. (Multipage TIFF is supported as well.)

The PDF to Image converter is based on PDF Rasterization Pilot. PDF Rasterization Pilot is a library for developers. Using this tool, developers can add to their products such features as export PDF to graphic format and output PDF to a device context (display or printer).

The new PDF2Image Pilot uses only PDF Rasterization Pilot for saving PDF into graphic files and outputting PDF content to a preview window. In PDF2Image Pilot, we tried to connect the features of the PDF Rasterization library and our many years experience in the development of easy and useful interfaces. We hope that PDF2Image converter helps you to solve your tasks. We await your responses and proposals!

Artem Golubnichenko

Layers (Optional Content Groups)

Layers or as they are more formally known Optional Content Groups (OCG) is representing a collection of graphics that can be made visible or invisible dynamically by users of viewer applications. (This ca­pability is useful in items such as CAD drawings, maps, and multi-language documents) With the introduction of PDF version 1.5 came the concept of Layers. Form and image and annotations can be made optional too.

A group is assigned a state, which is either ON or OFF. States can be set programmatically or through the viewer user interface to change the visibility of content. In the typical case, content belonging to a group is visible when the group is ON and invisible when it is OFF. When a piece of optional content in a PDF file is determined to be hidden, the content is not drawn.

You may see all layers in PDF document on Layers tab. (for Adobe Reader) Go into the “View” menu and select “Navigation Tabs” and then choose “Layers”.

So this gives us an instruction on how to create Layered PDFs within PDF Creator Pilot. In our example we’ve created a PDF with several layers. (example for VBScript)

' create pdf library object
Set PDF = CreateObject("PDFCreatorPilot.PDFDocument4")

' initialize PDF Engine
PDF.SetLicenseData "demo@demo", "demo"

' set document title
PDF.SetTitle "PDF with Layers", 1

'  For creating PDF with layers, we need create named content group. For every layer –
' individual group:
groupIndex = PDF.CreateContentGroup("Text Optional Content Group")

' Then you need to add content in layer. Sections of content in the PDF document can be made
' optional by enclosing between the marked-content operators BeginMarkedContent and
' EndMarkedContent. Between this operators you may draw graphic shapes, images, forms,
' annotations or text:

'  Text content group example:
PDF.BeginMarkedContent groupIndex
PDF.ShowTextAt 10, 40, "Hello, optional content group!"
PDF.EndMarkedContent

'  Image content group example:
img = PDF.AddImageFromFile(L"image.jpg")
PDF.BeginMarkedContent groupIndex
PDF.ShowImage img, 150, 100
PDF.EndMarkedContent

'  Annotation content group example:
PDF.BeginMarkedContent groupIndex
PDF.AddUnicodeTextAnnotation 10, 10, "Title", "Some text goes here..."
PDF.EndMarkedContent

'   You may combine content of this group. For example,
PDF.BeginMarkedContent groupIndex
PDF.ShowTextAt 10, 40, "Hello, optional content group!"
PDF.AddEditBox 50, 210, 150, 250, "edt1"
PDF.SetColor 0.0, 0.9f, 0.0, 0.0
PDF.ResetPath
PDF.DrawEllipse 100, 200, 200, 300
PDF.FillAndStroke
PDF.EndMarkedContent

' finalize document generation
PDF.SaveToFile "PdfWithContentGroups.pdf", true


' disconnect from library
Set PDF = Nothing

Hopefully from the example code and the example PDFs you should see how useful Layers can be.

Artem Golubnichenko

PDF Creator Project News

Hello,

Today I want to talk about important improvements in the current version of the PDF Creator Pilot library.

It was always one of the weakest things about the Library – it demanded huge amounts of memory to work with larger documents. Quite often clients were not able to create a document consisting of more than 100 pages, because they did not have enough memory. In this version, we have managed to open up a bottleneck, which helped us significantly reduce memory requirements. In short, if a page contains a lot of graphics, it also contains a lot of page operation commands. Keeping all these commands in memory was the bottleneck. We cached the commands into a temporary file, and that solved the problem.

The other improvement concerns conversion of EMF files to PDF files. We’ve improved the processing of paths and clipping regions. This was no trivial task, because the path processing toolset of the PDF format isn’t as rich as required by GDI. Clipping regions are the worst supported; there are no other region operations in a PDF except intersection. To adequately process an EMF, we had to support all operations defined in Set theory. For a long time the problem remained unsolved, however we have now left the problem behind us. Now these kinds of EMF files converted correctly.

This last bit of news should be of interest to those who use “non-standard” versions of the Library, such as the 64-bit variant or the static variant (which is for C++ only). We’ve found that the x64 build failed to convert EMF files, and the static library refused to work from VS2005. All of these problems have also been fixed.

You can download the current builds from PDF Creator Pilot page.

In the next release, we plan both to improve processing of TIFF files and to add support for CMYK TIFFs.

Vitaly Shibaev

COM: The First Steps

Let me show you the process of creating of a COM component with Visual Studio 2008 using ATL and C++.

First, let’s create a Visual C++/ATL project:

Continue reading

PDF Creator – about project and development process

This article describes the organization of the PDF Creator project and the tools that we use to develop and promote the product.

Development Tools

1. Subversion (SVN) Control

The life of a programmer would be unbearable without a source control manager :-). As of this writing, we have executed 2387 commits in the PDF Creator project using the Tortoise SVN, (http://tortoisesvn.tigris.org/). Since every mistake would cost a lot, we try to follow this rule – one that we would recommend to everyone: Always commit smaller portions of the code. Every commit must correspond to a single task!

This way it is (a) easier to find an error during rollbacks (every commit changes a small amount of source code), (b) often easy to discover an error before the commit just by looking at it, and (c) easier for colleagues to be aware of the changes in the source code, since all they have to do is read the comments and look at the smaller portions of the code.

Of course, this is not possible in all cases, and sometimes we do have to perform huge commits. Still this is a rule worth following. After all, it is one of the refactoring rules: Change smaller portions of the code, preserving its workability between sessions.

Two more source-control rules:

  1. There must always be two versions in the SVN – a version that compiles and a workable version. It is easy to create code that compiles, but the real aim is its correctness.
  2. Text comments should be supplied to every commit. This is also a good way to check whether the commit implements only a single task. If a comment describes several targets instead of just one, the rule has been violaled.

2. Bug Tracker

We use Mantis (http://www.mantisbt.org/). PDF Creator is the base for a number of other products – converters, virtual printer, etc. The number of its users is much higher than the count of those who purchased the base product. We needed to simplify communications between the developers and the users of the products.

To make the things clear for those who have never used a bug tracker, here is a sample of how it works. The virtual printer developers receive (from the users of their product) information about an incorrect conversion into a PDF. The Virtual Printer gets an EMF file from input, then our library converts it. The information from the user is used to create a “ticket” for the library developers. The ticket is accompanied by a description of the problem and the problematic EMF file. Then we investigate the degree of severity of the problem to find out how critical it is and appoint a specific developer to work on a fix. After the problem has been resolved, the ticket gets closed. Everybody concerned is notified and may keep an eye on what is going on.

3. Development Environment

We use Visual Studio 2008, C++, and C#.

4. Refactoring Tools

There are no built-in tools for C++ refactoring in Visual Assist X (http://www.wholetomato.com/), so we have to use a third party plug-in for Visual Studio.

5. Unit Tests in C++

Here we use UnitTest++ (https://sourceforge.net/).

 

Project Organization

PDF Creator is a library for PDF processing: creation, reading, modification, text extraction, etc. Currently, the project exists as a solution with 18 sub-projects in Visual Studio 2008. There are five general types of sub-projects.

1. The Library Core

Here we define all the logic of PDF processing. This project is always in the process of modification. One of our old dreams (and still a dream today) is to make the core cross-platform. The biggest obstacle is the fact that EMF is a private Windows format. To make our dream come true, we should separate the conversion from the cross-platform part.

2. Client Interfaces

Two of the projects implement the client interfaces. One of them implements the COM interface; the other one implements a static library. The COM interface delegates its tasks to the static library; the static library forwards them to the core. No code is duplicated.

The static library isn’t advertised on our site, however every client may receive it together with the COM version. The static library contains some undocumented features that allow users to get some additional information about a document. If you are a developer and your product is intended to view PDFs, these features may be very useful for you.

3. Test Projects

  1. Non-automated tests for the COM interface. A set of APIs that form and render PDF documents immediately after their launch.
  2. Unit tests for the static library and the core. In addition to those described immediately above, the unit tests check the internal state of the classes, handle errors, etc.
  3. Projects that check the EMF-conversion. The first one (written in WTL) converts the specified EMF file into a PDF. Its interafce is minimalistic.
    The second one (written in C#) are a work in progress. However, it is already possible to convert all PDFs from a folder and to instantly review the results. This provides a significant speed increase during the testing process, which is especially great since we’ve got hundreds of test metafiles already.

4. Auxiliary Projects

These include a font-processing library (that parses TrueType and Type1 fonts, works with encodings, and modifies the TrueType fonts), font installer, working with the keys, etc.

5. Third Party Open-Source Products

PDF is a complex format. It is based on many areas of science, multiple algorithms, and formats. It involves compression and encryption algorithms, various image and font formats, color spaces, etc. A big part of our implementation is based on open source projects with a free license, for instance, CxImage, ZLib, LibJPEG, Lcms, and UnitTest++.