Printing to a PDF file

2,114 views
Skip to first unread message

Zeljko

unread,
Dec 25, 2012, 3:41:09 AM12/25/12
to harbou...@googlegroups.com
Is there a way to print to a PDF file using standard Harbour printing commands (SET PRINT ON, SET PRINTER TO, devout()). I really don't need any fancy graphics in my PDF, just a standard report (printing instead of to a real printer to a PDF file)?

Dragan Cizmarevic

unread,
Dec 25, 2012, 8:11:20 AM12/25/12
to harbou...@googlegroups.com
PDF is more complex than just a position in the line, a simple solution is to create a text file and rewrite the program to pdf

Look  https://github.com/MRonaldo/MR-Tools/downloads

PDF је slozeniji оd obicnog pozicioniranja u liniji, nеko jednostavno resenje је krerati txt fajl pa program to prepise u pdf, pogledaj link

Zeljko

unread,
Dec 25, 2012, 3:30:01 PM12/25/12
to harbou...@googlegroups.com
I do realize that PDF is more than printing out text. But I have a specific program request to store printed reports as PDF files (and send them via email). The reports are printed to PCL laser printers and they  are just fine, I just need to transform them into PDF files without too much added work.

apolinar

unread,
Dec 25, 2012, 5:35:46 PM12/25/12
to Harbour Users
Study
\harbour\contrib\hbhpdf\ library and samples to create pdf reports

regards
Apolinar

Klas Engwall

unread,
Dec 25, 2012, 9:18:49 PM12/25/12
to harbou...@googlegroups.com
Hi Zeljko,

> I do realize that PDF is more than printing out text. But I have a
> specific program request to store printed reports as PDF files (and send
> them via email). The reports are printed to PCL laser printers and they
> are just fine, I just need to transform them into PDF files without
> too much added work.

It *does* take some extra work :-)

Harbour has two pdf libraries, contrib\hbhpdf and extras\hbvpdf. For
simple needs, like the ones you describe, hbvpdf will work nicely. Try
the pdf_demo.prg example in extras\hbvpdf\tests to see how easily you
can get started.

I would recommend that you write wrappers for SET PRINTER TO, @ ... SAY
etc so you can easily switch between physical printers and pdf output
with the exact same function calls in your reports. I used a variant of
hbvpdf's procedural "ancestor" in Clipper with UDFs like SetPrinter(),
AtSay(), Eject() etc with branches for paper and pdf printing in each of
the UDFs. In Harbour I have a print job class that does the same thing
OOP style. If you are satisfied with what the hbvpdf demo can do, then
it is not too difficult to write the wrappers I mentioned.

Regards,
Klas

Richard Acosta

unread,
Dec 26, 2012, 1:32:44 AM12/26/12
to harbou...@googlegroups.com, Zeljko
"without too much added work"
  
The fastest and simplest way would be to install a .pdf printer, then send to that printer a .txt file generated by the program.
This off course if you're using an OS with Graphical user interfase. If you're still rolling your code over DOS, then there will not be a pdf. printer available.

The other easy way to achieve that, is by making an array with the text, then sending that to a pdf by using pdfnew(), pdfstartpage(), pdfendpage(),pdfend()
I'm not too sure where they come, could be pdflib.lib or hbhwvw.lib i know for sure this does not come from libharu.lib or hbhpdf.lib I'm using them all from some time on, so i cant remember too well.

And this would be the sample code:

    pdfnew(cFile,9,842,595,1,1,1304,,)

            pdfstartpage("",.T.)
                pdfdrawpage(AMSG)
            pdfendpage()
    pdfend()

where cFile is the file you want to create and amsg is the array with your text. The numbers are related to page size, orientation and text size.

Greetings.

El 25/12/2012 06:41 a.m., Zeljko escribió:
Is there a way to print to a PDF file using standard Harbour printing commands (SET PRINT ON, SET PRINTER TO, devout()). I really don't need any fancy graphics in my PDF, just a standard report (printing instead of to a real printer to a PDF file)? --
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
 
 
 

marek.h...@interia.pl

unread,
Dec 26, 2012, 3:05:39 AM12/26/12
to harbou...@googlegroups.com
Hi,

"Klas Engwall" <har...@engwall.com> pisze:
> Hi Zeljko,
>
> > I do realize that PDF is more than printing out text. But I have a
[...]
> Harbour has two pdf libraries, contrib\hbhpdf and extras\hbvpdf. For

And third for pdf is cairo.

Regards,
Marek Horodyski

Zeljko

unread,
Dec 26, 2012, 11:22:41 AM12/26/12
to harbou...@googlegroups.com
Thanks everybody for your help. After examining all the options, it seems to me that the following combination takes the least effort: Installing GHOSTPCL and REDMON, adding a new printer and creating a  virtual port with REDMON and mapping this port to GHOSTPCL.EXE with parameters like this (-sOutputFile=c:\tmp\myPdf.PDF -sDEVICE=pdfwrite -dBATCH -dNOPAUSE c:\TMP\TMP.TXT). Then you simply print your report from harbour to a text file named TMP.TXT and afterwards set the printer to the newly created printer and print anything (I really mean anything - it doesn't matter). Then GHOSTPCL is triggered and the txt file is converted from PCL to PDF. This works. I have only one problem with this. The command SET PRINTER TO ( win_PrinterGetDefault() ) does not seem to work when there is a virtual port mapped to the new printer with a virtual port (REDMON creates a port named RPT1:). I have to use: SET PRINTER TO  \\MY_COMP\LASER\MY_TEKST, but then there is an error when setting a port option in REDMON to prompt for a file name. I get the following: REDMON StartDocPort: remote access to "prompt for filename" is not permitted. Obviously REDMON thinks I am remapping a remote computer and not mine. Is there any way to use SET PRINTER TO with a printer that has a port mapped that is not LPT and not COM?


On Tuesday, December 25, 2012 9:41:09 AM UTC+1, Zeljko wrote:

Zeljko

unread,
Dec 26, 2012, 1:40:26 PM12/26/12
to harbou...@googlegroups.com
Update to my post above. You even don't have to do all the virtual port voodoo, you even don't need a printer. Just print to a text file and call ghostpcl with the adequate parameters:
result = HB_processRUN("D:\pcl_ghost\pcl6.exe -sOutputFile=C:\TMP\therealdeal.pdf -sDEVICE=pdfwrite -dBATCH -dNOPAUSE c:\TMP\TMP.TXT"


On Tuesday, December 25, 2012 9:41:09 AM UTC+1, Zeljko wrote:

vszakats

unread,
Dec 26, 2012, 4:35:38 PM12/26/12
to harbou...@googlegroups.com
On Wednesday, December 26, 2012 7:40:26 PM UTC+1, Zeljko wrote:
Update to my post above. You even don't have to do all the virtual port voodoo, you even don't need a printer. Just print to a text file and call ghostpcl with the adequate parameters:
result = HB_processRUN("D:\pcl_ghost\pcl6.exe -sOutputFile=C:\TMP\therealdeal.pdf -sDEVICE=pdfwrite -dBATCH -dNOPAUSE c:\TMP\TMP.TXT"

It may be a problem with this approach that you 
need to get the commercial license for the fonts 
it uses (and on a per site basis). It's not cheap.

-- Viktor

Zeljko

unread,
Dec 26, 2012, 5:24:25 PM12/26/12
to harbou...@googlegroups.com
It is distributed under a GNU GPL license. As I need it only for internal use (don't plan to sell the software commercially) this seems to fit my needs. And as for simplicity, this fits perfectly.

vszakats

unread,
Dec 26, 2012, 5:35:07 PM12/26/12
to harbou...@googlegroups.com


On Wednesday, December 26, 2012 11:24:25 PM UTC+1, Zeljko wrote:
It is distributed under a GNU GPL license. As I need it only for internal use (don't plan to sell the software commercially) this seems to fit my needs. And as for simplicity, this fits perfectly.

Wrong, the fonts are not under GNU GPL.

Quote from http://artifex.com/downloads/:
---
URW fonts

These are the set of 80 standard TrueType fonts from URW. This font set is required for proper functioning of GhostPCL. If you have obtained a commercial OEM license agreement from Artifex, please use this font set. For all others they are distributed under a license called the AFPL which, among other restrictions, disallows any commercial distribution and as such they are kept in a separate package.
---

"Internal" has no correlation to 'commercial' usage, 
where usage is also unrelated to 'sales'. Anyhow 
you should consult the AFPL text for details.

-- Viktor

Zeljko

unread,
Dec 26, 2012, 6:12:22 PM12/26/12
to harbou...@googlegroups.com
Viktor, I am not a lawyer but as I understood the license, I am not allowed to sell it. From Wikipedia:

The Aladdin Free Public License, abbreviated AFPL, is a license written by L. Peter Deutsch for his Ghostscript PostScript language interpreter.

The license was derived from the GNU General Public License, but differs on two key points:

  • The source code must be included with any software distribution.
  • The software may not be sold, including any fees involved with distribution.

 Anyhow, I didn't download the fonts (even didn't notice they were needed) and the output generated by ghospcl looks rather nice. I have to test this with more complex reports, but right now it looks as if I even don't need these fonts.

Jayadev U

unread,
Dec 27, 2012, 2:38:01 AM12/27/12
to harbou...@googlegroups.com
Hi,
 
You can use "CUTEPDF Writer" which is available here and free and can be treated as a printer.
 
HTH,
 
Warm regards,
 
Jayadev
 
 
 
 


From: harbou...@googlegroups.com [mailto:harbou...@googlegroups.com] On Behalf Of Zeljko
Sent: Thursday, December 27, 2012 4:42 AM
To: harbou...@googlegroups.com
Subject: [harbour-users] Re: Printing to a PDF file

ujayadev_at_gmail.com

unread,
Dec 27, 2012, 2:43:02 AM12/27/12
to harbou...@googlegroups.com
Oops, missed the link:

http://www.cutepdf.com/

Have been using for a long time without any issues.

Warm regards,

Jayadev



On Thursday, December 27, 2012 1:08:01 PM UTC+5:30, ujayadev_at_gmail.com wrote:
Hi,
 
You can use "CUTEPDF Writer" which is available here and free and can be treated as a printer.
 
HTH,
 
Warm regards,
 
Jayadev
 
 
 
 

Reply all
Reply to author
Forward
0 new messages