Re: [harbour-users] HARU PDF - open and fill a formng

504 views
Skip to first unread message

Klas Engwall

unread,
Feb 17, 2012, 2:48:49 PM2/17/12
to harbou...@googlegroups.com
Hi Zoran,

> My printing system is 90% based in generating reports through .pdf
> files using harupdf , but sometimes i have to fill some forms that are
> by law designed.

Are these forms originally in .pdf format and fillable using Adobe
Acrobat/Adobe Reader/Foxit Reader etc? If so, the easiest method is to
use .fdf files just like Maurizio said. An .fdf file is a text file
following a simple syntax. When you double-click on the finished .fdf
file, the .pdf file that it "belongs to" will also be opened, and the
fields in the .pdf will be filled with whatever you have put in the .fdf
file. Double-clicking the .fdf file and saving the final .pdf file is a
manual step.

The .fdf file format is described in the PDF Reference, available here:
http://partners.adobe.com/public/developer/en/pdf/PDFReference16.pdf
This file is huge, so right-click on the link and save it.

Here is a small example of what an .fdf file can look like:

%FDF-1.2
%����
1 0 obj
<</FDF<<
/F(mypdfwithtextfields.pdf)
/Fields[
<</T(1)/V(Text in field number one)>>
<</T(2)/V(First line of field number two\second line here)>>
<</T(3)/V(Third field)>>
<</T(4)/V(Fourth field, and so on)>>
]>>>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

The second line tells the application that there may be non-7-bit
characters in the file. The fifth line is the name of the .pdf file that
is to be filled with data. The numbers in parenthesis are the field
numbers in the .pdf file. Text in multi-line fields can be broken with
backslashes.

You will probably need Acrobat Pro to identify all the fields in the
existing .pdf files and find out which field has which number or name.

If the original file is just a dumb pdf with no forms, then you can use
for example Acrobat Pro to create the fields manually. If they only
exist on paper, scan them to .pdf and create the fields in Acrobat.

Adobe and others have SDKs that will let you fill existing .pdf files
directly. But that is a slightly bigger project.

Regards,
Klas

Giuseppe Paternò (Gippa)

unread,
Feb 17, 2012, 3:56:54 PM2/17/12
to harbou...@googlegroups.com
Hi!

Although not really harbour-related, I strongly suggest you to have a look to pdftk.
http://www.pdflabs.com/docs/install-pdftk/

An example for unix would be:
pdftk my_source.pdf fill_form my_temp.fdf output my_output.pdf

I use python for this specific application, but you can create the FDF file through harbour and then execute the above command.
Regards,
  Giuseppe

Klas Engwall

unread,
Feb 17, 2012, 4:39:17 PM2/17/12
to harbou...@googlegroups.com
Hi Giuseppe,

> Although not really harbour-related, I strongly suggest you to have a
> look to pdftk.
> http://www.pdflabs.com/docs/install-pdftk/

Sure. I use pdftk too. It is very powerful. The only problem is that it
adds an extra requirement for Zoran's clients.

Regards,
Klas

Zoran Sibinovic

unread,
Feb 19, 2012, 3:45:10 AM2/19/12
to Harbour Users
Hi to all,

sorry, I was away in a few past days,

at first thanks for suggestions.
I will take a look about pdftk.

My question is related to a simple way of pdf use,
but the suggestions open new options.

Since I use only, at this time, harupdf, my intent was simply to open
an already
made pdf that contain, for example, plotted tables and then using
harupdf functions
to write text in cells (fill them).

I must say, also, that that the tables/reports are made in openoffice,
identical to the request laws forms/reports that I need
and exported in pdf-s. There is no embedded form fields in it to fill,
just simply pdf with tables.

I simply want to overpass the method to create the above mentioned
tables and save them as png or jpg and
then import them using harupdf.

The possibility to create something better pdftk is welcome and we
will see

Thanks

Zoran

Klas Engwall

unread,
Feb 19, 2012, 8:51:29 AM2/19/12
to harbou...@googlegroups.com
Hi Zoran,

> Since I use only, at this time, harupdf, my intent was simply to open
> an already
> made pdf that contain, for example, plotted tables and then using
> harupdf functions
> to write text in cells (fill them).
>
> I must say, also, that that the tables/reports are made in openoffice,
> identical to the request laws forms/reports that I need
> and exported in pdf-s. There is no embedded form fields in it to fill,
> just simply pdf with tables.
>
> I simply want to overpass the method to create the above mentioned
> tables and save them as png or jpg and
> then import them using harupdf.

If you are considering drawing the forms in OOO identical to the
original government forms, exporting them to png/jpg and then importing
the bitmaps into the pdf to put your data on top of them, why not just
scan the original paper form to png/jpg and save all the drawing work?
You can stretch or shrink the background picture programmatically to fit
the size requirements.

Or you can program the form straight in the pdf using line drawing
functions. It may seem daunting at first, but you will quickly get the
hang of it. That will give you the smallest file size and no blur caused
by bitmap compression.

Regards,
Klas

Zoran Sibinovic

unread,
Feb 20, 2012, 2:34:14 AM2/20/12
to Harbour Users
Hi Klas

nice observation regard scanning the original documents, but there are
few things in favor of drawing then scanning.

Scanned documents are lot bigger, even u did it in grayscale, they
cannot be clean and sometimes sharpen, the white background is a misc
of gray shades that is reflected when printing. Also u cannot do text
or other changes if you need because you cannot achieved a good look.

In the other hand if u draw the document and save it in pdf, the pdf
size is lot smaller and you can always make changes. The difference
can be viewed if you have to make a file with 20 or more pages
importing a scanned file of 1.000kb and a drawn file of 100kb on every
page. Take more time using large files.

Drawing the doc using line drawing functions is very hard when you
have complicated tables to do and you cannot see the result till you
recompile a lot of times. Also table changes, if is needed, can be
very problematic.

So, the best way that I have found is to draw the document
(word,ooo,corel,etc.) using the original document as background,
export it in pdf (I use CutePDF) and than, convert it in a png file.
For the conversion PDF to PNG I found a versatile free app PDFill
tools that make the job very well. Changing the doc is very simple and
faster later.

Zoran

Reply all
Reply to author
Forward
0 new messages