From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a PDF report with both text and graphics in CVI using HARU Pdf library

Overview

PDF file format has become a de-facto standard in creation and distribution of printed documentation: nowadays every application must be able to save its reports in this format that makes filing and distributing informations an easy task. While it is possible to install in the system one of the several virtual PDF printers available on the market and obtain PDF generation this way, this option usually relies on operator's activities to produce the PDF. It would be better to integrate a PDF creation utility inside the application instead, and have PDF reports produced automatically without need to rely on external software. 

 

Description

After reading this suggestion from ebalci I started looking at HARU Pdf library to generate text reports for my applications. Besides offering a powerful and complete set of instructions to create virtually whatever report you want, its licence permits its usage for free in commercial applications.

 

This library integrates very easily in a CVI project: you only have to add the proper include file and library to it and be sure libhpdh.dll is in the search path for DLLs.

I have additionally created an enum for error codes returned from library functions, to help in error checking activities (I decided not to use suggested error handling method based on aerror handler function and to rely on function return codes to handle abnormal situations). 

 

Steps to implement or Execute Code

Attached is a sample project that demonstrates creation of a text report in PDF format using this library: a sample data file and a graphical logo are included to illustrate how to manage multi-page reports and add some graphical element to them. The created PDF is then displayed using the default PDF viewer installed in the system.

 

The example is intended as a conceptual framework to illustrate some possibilities of the library rather than a complete report creator tool. It makes use of a UIR panel as a template for main report elements: this choice is absolutely not needed but I have found it handy to develop general page aspect and framework. It also integrates some basic error checking functions:

 

To implement the library in your applications, you must #include hpdf.h file in your source code, add libhpdf.lib to the project and be sure libhpdf.dll is in dll search path. From this moment on you can proceed including HaruPDF instructions in the code.

 

Requirements

This example has been developed using CVI 2009 FDS (SP1); integrating the library in older versions of CVI is possible as it does not makes use of any special CVI function (I have started using it in CVI 8). For the same reason it should be possible to use it in the base version of CVI, but I cannot test this as I am using the Full Development System version. 

 

Updates

Update 1 - I have updated this example to demonstrate how a bitmap in memory can be appended to the report. When dealing with images in memory, the pixel depth must be taken into consideration, as the library treats only 24-bit images while it is now normal to have screen resolutions of 32-bit: since when a botmap is created in memory it matches the screen resolution, you must convert the image from one format to the other to be able to insert the image in the report. This is done in PrintReport () function.

 Ability to incorporate images taken from a file to disk was already included in the example (see NewPage function)

 

Update 2 - Updated link to developer homepage



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Comments
vix
Active Participant
Active Participant
on

Hi Roberto,

the link you provided to HARU pdf library points to a page that starts with this message "Haru development is moved to libharu.org. Please update your bookmarks".

In the download section of this new site there are some different versions (stable version, previous releases, release candidate), and I'm not sure which of them should I use.

Did you download the Win32 dll (version 2.0.8, that seems quite old) or did you create a newer dll compiling the sources of a newer version?

If this is the case, did you use CVI to recompile the sources? Did you need some special makefile?

Vix
-------------------------------------------
In claris non fit interpretatio

-------------------------------------------
Using LV from 7
Using LW/CVI from 6.0
RobertoBozzolo
Proven Zealot
Proven Zealot
on

Thank you Vix, I'll update the link.

Regarding the release I'm using, after a few unsuccesful attempts to compile from the sources, I resolved to download the DLL for Windows. Yes, it's relaease 2.0.8 but it includes all that is normally needed to create optimal reports. I found no errors in the functions I am normally using (writing text, adding images, personalizing document properties and so on) so I see no real need to look for more recent releases (if you look at the changelog, you'll see that almost all updates refer to new bindings for various programming languages, which I'm not using).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
hadjrami
Member
Member
on

Hello Mr Roberto Think you for the post.

I have problem instaling the libhpdf.lib it doesn't exist in the project directory and I tryed to install it but it doesn't work yet. it shows me that error message.

The file format of "libhpdf.lib" does not match that used by the current compatibility mode. Think you for your help

RobertoBozzolo
Proven Zealot
Proven Zealot
on

Hello hadjrami,

which version of CVI are you using? Are you using other libs in your application other than the Haru one?

Compatibility mode is the ability to link against objects created in other programming environments. Older versions of CVI could be set with compatibility modes Visual C/Borland/Watcom. As of CVI7 the product is no more compatible with Watcom, and starting from release 2009 the compatibility mode is adjusted automatically by the IDE. I was using Visual C compatibility mode when I first started using HARU in CVI 8 and didn't move from that even in more recent versions. Compatibility mode can be set in Options >> Build options panel (up to CVI8.5) and implies restarting CVI environment.

You cannot use objects and libraries from different compilers in a single application, as the compatibility mode is set at system level.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
hadjrami
Member
Member
on

Thinks Mr Roberto

I just tried to compile attached project above. I thought that using CVI 2012 will not cause problems.  I think that the problem  is related to the installation of the module HARU. the first error I have got, was unable to find the libhpdf.lib than I brought it from the Internet and I get the Compatibility error (I think that the problem is caused by this file). I searched for tutorial, but it was like Chinese for me. especially because I didn't find CVI in the configuration example (I didn't know for the multiple compatibility mode)

RobertoBozzolo
Proven Zealot
Proven Zealot
on

Which package have you downloaded from the internet? If you download "dll_win" package you will find both the dll and the lib to link against and you should have no compatibility problems (at least I hadn't in any CVI release I used HARU with). Next you simply have to set include path to the haru include folder in Options >> Environment >> Include paths window, include hpdf.h in source files, add libhpdf.lib to your project and have the dll in the application directory at runtime (or in windows\system folder to have it available to all programs).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
beitzer
Member
Member
on

Hello, Mr. Roberto

after quite a bit of searching I don't find a way to download dll or lib libraries for WIN. All I get are several zip-files with source codes I cannot compile (and as I understood, even you have failed doing it yourself).

Can you please quote an URL for downloading the libraries?

Thank you, HWB

RobertoBozzolo
Proven Zealot
Proven Zealot
on

I am still using version 2.0.8 dll, which is correctly working for me up to Win7 machines.

I see that the new page does not offer a visible link to download previous versions, but you can stil find it in old SourceForce page. The direct link is this one.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
beitzer
Member
Member
on

Thank you very much for your quick and helpful answer.

The direct link was fine, whereas I still had to do some searching until I found it via the old SourceForge page.

HWB

shy8_79
Member
Member
on

Dear RobertoBozzolo,

I am trying to use PDf as report output, but I do NOT know how to gererate the *.dll,*.lib,my application enviroment is below: win7 32 or 64 and XP, CVI2010, could you attached lib 2.0.8 to this web, then I can try it with the project named "PDFTextReport". thanks a lot!

sunhaiyan
Member
Member
on

Dear robert,

I find the lib and dll in your link, that give me great support, thanks for your contribution.

wwilliams
Member
Member
on

Thanks Roberto very helpful.

karol42
Member
Member
on

I'm searching for a version of the library for a 64 bit environment.

Do you know how to make a DLL oder where to download a pre compiled one?

RobertoBozzolo
Proven Zealot
Proven Zealot
on

Sorry for answering so late. AFAIK there is no DLL built for 64-bit IDE on Haru site and I dind't bothered to build one myself from sources since I'm working in 32-bit only.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Contributors