PdfLib on linux

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

PdfLib on linux

Post by tinycla »

I need to generate some pdf docs and I thought I'd use the pdflib, but I've discovered that it doesn't work on Linux (the lib is missing from distribution files, and the site does'nt say anything about a linux version).
Somebody knows how to make pdflib work in linux, or what other libraries could I use instead?
Boris the Old
Posts: 139
Joined: Feb 04, 2011 20:34
Location: Ontario, Canada

Re: PdfLib on linux

Post by Boris the Old »

I use the CUPS-PDF virtual printer for creating PDF files on Linux. It's simple to use - just direct printed output to the virtual printer instead of a real printer.

Many of our customers prefer to receive invoices via email, so for those customers we just direct the printed output to the virtual printer, then email the PDF files to them. Our billing software didn't require any special code to handle PDF output, since it already had the ability to print to multiple printers.

Rod
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: PdfLib on linux

Post by ike »

http://free-basic.ru/

18.04.2015


It is in russian, I guess you can not read cyrilic, but you dont need it: just click 3rd link from the top.

Library is called LIBHARU follow link and save libharu.zip - and then when you download it will be in english
I don use that lib, but I tested examples and it works ...

OR

Save file as SVG () and use rsvg-convert (google it) to covert it to pdf, png etc


P.S.
HERE IS DIRECT LINK:


http://free-basic.ru/user-files/LibHaru.zip



EXAMPLE

Code: Select all


'****************************************************************************** 
'*  Program name: hpdftest
'*  Version:      0.1
'*
'*  Author:       Copyright (c) 2008 Klaus Siebke
'*                Siebke Unternehmensberatung
'*                URL http://www.siebke.com
'*
'*  Description:
'*  -----------
'*
'*  Program to test the creation of a PDF file using the Haru Free PDF Library
'*
'*  License:
'*  -------
'*
'* Permission to use, copy, modify, distribute and sell this software
'* and its documentation for any purpose is hereby granted without fee,
'* provided that the above copyright notice appear in all copies and
'* that both that copyright notice and this permission notice appear
'* in supporting documentation.
'* It is provided "as is" without express or implied warranty.
'*
'*
'* External libraries used by the program:
'* --------------------------------------
'*
'* << Haru Free PDF Library 2.0.8 >>
'* URL http://libharu.sourceforge.net/
'* Copyright (c) 1999-2006 Takeshi Kanno
'*
'****************************************************************************** 
'****************************************************************************** 
'* Includes for Haru Free PDF Library 
'****************************************************************************** 
#include "crt/errno.bi"
#include "zlib.bi"       

#ifndef __mod_hpdf_bi__
#define __mod_hpdf_bi__
#include once "hpdf_consts.bi"
#include once "hpdf_types.bi"
#include once "hpdf.bi"
#endif

'****************************************************************************** 
'* Declarations of subroutines and functions
'****************************************************************************** 
declare sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr )

'****************************************************************************** 
'* Constants
'****************************************************************************** 
#define NULL 0 
const page_title = "PDF test document"

'****************************************************************************** 
'* Variables
'****************************************************************************** 
dim shared pdf          as HPDF_Doc 'ptr 
dim shared fname        as string * 256   
dim shared page         as HPDF_Page
dim shared def_font     as HPDF_Font
dim shared txt_font     as HPDF_Font
dim shared tw           as HPDF_REAL
dim shared doc_height   as HPDF_REAL
dim shared doc_width    as HPDF_REAL 
dim shared i            as HPDF_UINT
'dim shared errno        as HPDF_STATUS ptr
dim shared detno        as HPDF_STATUS ptr
dim shared userdat      as any ptr


'****************************************************************************** 
'* Begin of main program
'****************************************************************************** 
'print "let's go"
'let's go ... (initialize hpdf)
pdf = HPDF_New(@error_handler, NULL)
'print "after hpdf_new"
'add a new page object
page = HPDF_AddPage (pdf)
'print "after hpdf_AddPage"
doc_height = HPDF_Page_GetHeight (page)
'print "after hpdf_GetHeight"
doc_width = HPDF_Page_GetWidth (page)

'print a frame
HPDF_Page_SetLineWidth (page, .5)
HPDF_Page_Rectangle (page, 50, 50, doc_width - 100, doc_height - 110)
HPDF_Page_Stroke (page)

'print the title of the page (with positioning center) with font Helvetica
def_font = HPDF_GetFont (pdf, "Helvetica", NULL)
HPDF_Page_SetFontAndSize (page, def_font, 24)
tw = HPDF_Page_TextWidth (page, page_title)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, (doc_width - tw) / 2, doc_height - 50, page_title)
HPDF_Page_EndText (page)

'print some text inside the frame 
HPDF_Page_BeginText (page)

'first line with font Times Roman 14
txt_font = HPDF_GetFont (pdf, "Times-Roman", NULL)
HPDF_Page_MoveTextPos (page, 60, doc_height - 105)
HPDF_Page_SetFontAndSize (page, txt_font, 14)
HPDF_Page_ShowText (page, "This is a first line")

'second line with font Courier 12
txt_font = HPDF_GetFont (pdf, "Courier", NULL)
HPDF_Page_MoveTextPos (page, 0, -20)
HPDF_Page_SetFontAndSize (page, txt_font, 12)
HPDF_Page_ShowText (page, "This is a second line")

'third line with font Symbol 16
txt_font = HPDF_GetFont (pdf, "Symbol", NULL)
HPDF_Page_MoveTextPos (page, 0, -20)
HPDF_Page_SetFontAndSize (page, txt_font, 16)
HPDF_Page_ShowText (page, "Here are some symbols")

HPDF_Page_EndText (page)

'save the document
HPDF_SaveToFile (pdf, "mydoc.pdf")

'clean up
HPDF_Free (pdf)

'****************************************************************************** 
'* End of main program
'****************************************************************************** 


sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr) 
'****************************************************************************** 
'* Error handler
'****************************************************************************** 
' do something here ... 
  print "error_no: ", error_no
  print "detail_no:", detail_no
  print "data:     ", user_data

end Sub

SEE THIS

http://www.freebasic.net/forum/viewtopic.php?t=9014
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: PdfLib on linux

Post by tinycla »

ike wrote:http://free-basic.ru/

18.04.2015


It is in russian, I guess you can not read cyrilic, but you dont need it: just click 3rd link from the top.

Library is called LIBHARU follow link and save libharu.zip - and then when you download it will be in english
I don use that lib, but I tested examples and it works ...

OR

Save file as SVG () and use rsvg-convert (google it) to covert it to pdf, png etc


P.S.
HERE IS DIRECT LINK:


http://free-basic.ru/user-files/LibHaru.zip



EXAMPLE

Code: Select all


'****************************************************************************** 
'*  Program name: hpdftest
'*  Version:      0.1
'*
'*  Author:       Copyright (c) 2008 Klaus Siebke
'*                Siebke Unternehmensberatung
'*                URL http://www.siebke.com
'*
'*  Description:
'*  -----------
'*
'*  Program to test the creation of a PDF file using the Haru Free PDF Library
'*
'*  License:
'*  -------
'*
'* Permission to use, copy, modify, distribute and sell this software
'* and its documentation for any purpose is hereby granted without fee,
'* provided that the above copyright notice appear in all copies and
'* that both that copyright notice and this permission notice appear
'* in supporting documentation.
'* It is provided "as is" without express or implied warranty.
'*
'*
'* External libraries used by the program:
'* --------------------------------------
'*
'* << Haru Free PDF Library 2.0.8 >>
'* URL http://libharu.sourceforge.net/
'* Copyright (c) 1999-2006 Takeshi Kanno
'*
'****************************************************************************** 
'****************************************************************************** 
'* Includes for Haru Free PDF Library 
'****************************************************************************** 
#include "crt/errno.bi"
#include "zlib.bi"       

#ifndef __mod_hpdf_bi__
#define __mod_hpdf_bi__
#include once "hpdf_consts.bi"
#include once "hpdf_types.bi"
#include once "hpdf.bi"
#endif

'****************************************************************************** 
'* Declarations of subroutines and functions
'****************************************************************************** 
declare sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr )

'****************************************************************************** 
'* Constants
'****************************************************************************** 
#define NULL 0 
const page_title = "PDF test document"

'****************************************************************************** 
'* Variables
'****************************************************************************** 
dim shared pdf          as HPDF_Doc 'ptr 
dim shared fname        as string * 256   
dim shared page         as HPDF_Page
dim shared def_font     as HPDF_Font
dim shared txt_font     as HPDF_Font
dim shared tw           as HPDF_REAL
dim shared doc_height   as HPDF_REAL
dim shared doc_width    as HPDF_REAL 
dim shared i            as HPDF_UINT
'dim shared errno        as HPDF_STATUS ptr
dim shared detno        as HPDF_STATUS ptr
dim shared userdat      as any ptr


'****************************************************************************** 
'* Begin of main program
'****************************************************************************** 
'print "let's go"
'let's go ... (initialize hpdf)
pdf = HPDF_New(@error_handler, NULL)
'print "after hpdf_new"
'add a new page object
page = HPDF_AddPage (pdf)
'print "after hpdf_AddPage"
doc_height = HPDF_Page_GetHeight (page)
'print "after hpdf_GetHeight"
doc_width = HPDF_Page_GetWidth (page)

'print a frame
HPDF_Page_SetLineWidth (page, .5)
HPDF_Page_Rectangle (page, 50, 50, doc_width - 100, doc_height - 110)
HPDF_Page_Stroke (page)

'print the title of the page (with positioning center) with font Helvetica
def_font = HPDF_GetFont (pdf, "Helvetica", NULL)
HPDF_Page_SetFontAndSize (page, def_font, 24)
tw = HPDF_Page_TextWidth (page, page_title)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, (doc_width - tw) / 2, doc_height - 50, page_title)
HPDF_Page_EndText (page)

'print some text inside the frame 
HPDF_Page_BeginText (page)

'first line with font Times Roman 14
txt_font = HPDF_GetFont (pdf, "Times-Roman", NULL)
HPDF_Page_MoveTextPos (page, 60, doc_height - 105)
HPDF_Page_SetFontAndSize (page, txt_font, 14)
HPDF_Page_ShowText (page, "This is a first line")

'second line with font Courier 12
txt_font = HPDF_GetFont (pdf, "Courier", NULL)
HPDF_Page_MoveTextPos (page, 0, -20)
HPDF_Page_SetFontAndSize (page, txt_font, 12)
HPDF_Page_ShowText (page, "This is a second line")

'third line with font Symbol 16
txt_font = HPDF_GetFont (pdf, "Symbol", NULL)
HPDF_Page_MoveTextPos (page, 0, -20)
HPDF_Page_SetFontAndSize (page, txt_font, 16)
HPDF_Page_ShowText (page, "Here are some symbols")

HPDF_Page_EndText (page)

'save the document
HPDF_SaveToFile (pdf, "mydoc.pdf")

'clean up
HPDF_Free (pdf)

'****************************************************************************** 
'* End of main program
'****************************************************************************** 


sub error_handler cdecl (byval error_no as HPDF_STATUS, byval detail_no as HPDF_STATUS, byval user_data as any ptr) 
'****************************************************************************** 
'* Error handler
'****************************************************************************** 
' do something here ... 
  print "error_no: ", error_no
  print "detail_no:", detail_no
  print "data:     ", user_data

end Sub

SEE THIS

http://www.freebasic.net/forum/viewtopic.php?t=9014
Thank you very much. Now I'm on Windows and cannot test the library on Linux. I'll do that when I'll be home. Anyway, I have no problem in reading russian (I studied russian language at University, many many years ago).
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: PdfLib on linux

Post by TJF »

AFAIR libharu is text only.

Here's an alternative if you need graphics (no encryption in this case):
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: PdfLib on linux

Post by tinycla »

TJF wrote:AFAIR libharu is text only.

Here's an alternative if you need graphics (no encryption in this case):
I don't need graphics, except maybe for a little logo, so I think libharu is OK. The advantage is that libharu doesn't require any external dependency (dll or so).
I've done some short test and the only thing that doesn't work well so far is the encoding: if I write accented letters such a "é" the PDF contains a graphical character and I'm not yet been able to make libharu print correctly that letters.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: PdfLib on linux

Post by TJF »

tinycla wrote: The advantage is that libharu doesn't require any external dependency (dll or so).
That's wrong. libharu is an external dependency itself, while cairo is part of each LINUX distribution with GTK desktop (like GNOME, XFCE, LXDE, ...).

I checked it, meanwhile libharu can handle graphics. The advantage is, it can encrypt pages (for security).

The disadvantage is that you have to start a PDF viewer to show the result. Instead, cairo can output on screen, in a vector graphic file, or in a pixel image -- it's just one line of code to direct the output.
tinycla wrote: ... if I write accented letters such a "é" the PDF contains a graphical character
In case of cairo you have to compile against pango-cairo for special characters. libharu may need pango for those characters (just a guess).
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: PdfLib on linux

Post by tinycla »

TJF wrote:
tinycla wrote: The advantage is that libharu doesn't require any external dependency (dll or so).
That's wrong. libharu is an external dependency itself, while cairo is part of each LINUX distribution with GTK desktop (like GNOME, XFCE, LXDE, ...).

I checked it, meanwhile libharu can handle graphics. The advantage is, it can encrypt pages (for security).

The disadvantage is that you have to start a PDF viewer to show the result. Instead, cairo can output on screen, in a vector graphic file, or in a pixel image -- it's just one line of code to direct the output.
tinycla wrote: ... if I write accented letters such a "é" the PDF contains a graphical character
In case of cairo you have to compile against pango-cairo for special characters. libharu may need pango for those characters (just a guess).
It's true that on Linux Cairo is already installed, but I'm developing a program that has to be run both on Linux and on Windows, and in Windows for using Cairo you have to install GTK (if I'm not wrong). On the other hand, I've been asked to make a program that can be run from an USB stick and doesn't require installation of other software on that computer.
But I'm interested in trying Cairo. I've take a look at the example, but my first impression is that it is more complicated and its use is mora for graphics than for textual report. But this impression could be erroneaus, so I'm ready to take a deeper look if someone could tell me where to find in-depth tutorial on creating pdf docs with Cairo. I didn't find many examples of that.
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

Re: PdfLib on linux

Post by RockTheSchock »

Well, if you dont want external dependencies just use the static version of the library. Even for GTK you can build a static version and use it for windows.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: PdfLib on linux

Post by dodicat »

For Cairo Windows you need 5 dll's in a folder, and run any test code you have from the same folder;
http://www.mediafire.com/download/ui41t ... /Cairo.zip

The .bi file is included in the folder.
tinycla
Posts: 121
Joined: Jan 07, 2006 12:51

Re: PdfLib on linux

Post by tinycla »

dodicat wrote:For Cairo Windows you need 5 dll's in a folder, and run any test code you have from the same folder;
http://www.mediafire.com/download/ui41t ... /Cairo.zip

The .bi file is included in the folder.
Well, very interesting, but it's not what I looked for. I need a way to produce PDF docs, almost exclusively containing text infos. The only graphic element will be a logo image, but this is optional. I know that Cairo can produce PDF, but is it well suited for producing the reports I need?
The big problem is that I can find only examples on how to draw images, but if I want to produce text, maybe with column and intests, how could I do? Maybe it's not the right tool for my program.
Post Reply