Recent

Author Topic: Visual tool to map fields to print on a template PDF  (Read 6693 times)

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Visual tool to map fields to print on a template PDF
« on: March 18, 2014, 07:26:01 am »
The task doesn't seem complicated to write, but I have learned to ask
first before reinventing the wheel. :-)

In our company we generate mortgage applications. We have a web
interface that collects a lot of data. We also have a empty mortgage
application (PDF) from each client. We then map our data (eg: First
name, last name, etc) to be printed at the correct positions of each
page of the template PDF. eg: First name field must be print on page 3
at co-ordinates x,y with a certain width and height. Then generate a
populated PDF which the customer downloads and prints off.

All this functionality is already implemented, but the mapping process
is currently done manually. A very boring and labour intensive job,
considering how large mortgage applications can be.

Do any of you know of any tool (custom written or commercial) that can do such
mapping in a more visual way? Drop a new field on a PDF page, drag and
resize to fit etc. A similar concept to when we visually design forms for
desktop applications.

If no existing tool can be found, I'm thinking of using fpGUI's
UIDesigner (forms designer) as a basis for such a tool. eg: export the
PDF to one image per page (many such tools already exist). Load each
image as the "form". Then use the XML file to give me a list of
available fields which I can insert on the form and position and size,
using the mouse. Write that field position information back to the XML
when you select "File -> Save" in the UIDesigner.

Like I said, it doesn't seem that hard, but if something already exists,
it will save me some effort.

Regards,
  Graeme


--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Visual tool to map fields to print on a template PDF
« Reply #1 on: March 18, 2014, 08:05:44 am »
If I understood what you need right, then a free version of Foxit Reader should be sufficient.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Visual tool to map fields to print on a template PDF
« Reply #2 on: March 20, 2014, 03:51:01 pm »
Thanks I'll take a look.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

kpeters58

  • Sr. Member
  • ****
  • Posts: 267
Re: Visual tool to map fields to print on a template PDF
« Reply #3 on: March 24, 2014, 05:59:13 pm »
Years ago I used FDFs for this in a Delphi application to fill in claimant demographics on a number of forms - would this work for you?
Lazarus 2.0.4/FPC 3.0.4/Win 64

GolfCat

  • New Member
  • *
  • Posts: 17
Re: Visual tool to map fields to print on a template PDF
« Reply #4 on: March 24, 2014, 10:09:11 pm »
I have used Debenu Quick PDF Library for situations like this, but then in Delphi. I think their library now works with Lazarus, but you should check.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Visual tool to map fields to print on a template PDF
« Reply #5 on: April 03, 2014, 02:55:08 pm »
Thanks for all the replies.  I might not have been 100% clear in my original message. I wasn't looking for a tool/component/library that could modify a PDF, I was simply looking for something that could modify XML to tell our existing solution where to place text fields in a PDF.

Anyway, I spent 2 hours and put together a custom solution that does just that. I use GIMP to load a PDF and export each page to a PNG image. My tool then loads a page image as the background. At the same time it reads the XML mapping file, finds the TEXT nodes and places them over the background image to represent where they would appear on the PDF. I can drag, resize etc the various text fields. In turn this updates the XML file with the new coordinates and size values. Attached is a screenshot of my tool. It will not win a beauty contest, but it is very functional and saves me a huge amount of time.  :)
« Last Edit: April 05, 2014, 01:29:45 am by Graeme Geldenhuys »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Visual tool to map fields to print on a template PDF
« Reply #6 on: April 03, 2014, 03:47:51 pm »
I use GIMP to load a PDF and export each page to a PNG image.
If you want to incorporate that part in your tool, AFAIK GIMP uses GhostScript . The code is something like:
Code: [Select]
// GhostTools.pas v.03, 12/20013, Marvi mail: phantomlord@embarqmail.com
//
// Open source, modify to whatever extent
...
{ generates PNG image from PDF - 1 image per page }
procedure PDF2PNG(input : AnsiString; output: AnsiString);
var
  ExitCode:integer;
  instance: Pointer;
  Arg: array of PAnsiChar;
begin
  ExitCode := gsapi_new_instance(@instance, nil);
  if ExitCode < 0 then
    raise Exception.Create('Impossible to open an instance of ghostscript. Error ExitCode: '+IntToStr(ExitCode));
  try
    SetLength(Arg, 11);
    Arg[0] := PAnsiChar('ps2pdf');
    Arg[1] := PAnsiChar('-dNOPAUSE');
    Arg[2] := PAnsiChar('-dBATCH');
    Arg[3] := PAnsiChar('-dSAFER');
    Arg[4] := PAnsiChar('-sDEVICE=pngalpha');
    Arg[5] := PAnsiChar('-r300');
    Arg[6] := PAnsiChar('-dTextAlphaBits=4');
    Arg[7] := PAnsiChar('-sOutputFile='+output+' Page-%02d.png');
    Arg[8] := PAnsiChar('-c');
    Arg[9] := PAnsiChar('.setpdfwrite');
    Arg[10]:= PAnsiChar('-f'+ input);

    ExitCode := gsapi_init_with_args(instance, Length(Arg), @Arg[0]);
    if ExitCode < 0 then raise Exception.Create('ERROR: init_args: '+IntToStr(ExitCode));
    gsapi_exit(instance);
  finally
    gsapi_delete_instance(instance);
  end;
end;
You can control the pages with additional parameters.
gsapi_* are from gsapi.pas (written by Alessandro Briosi)

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Visual tool to map fields to print on a template PDF
« Reply #7 on: April 05, 2014, 01:34:34 am »
If you want to incorporate that part in your tool, AFAIK GIMP uses GhostScript . The code is something like:
Thank you very much for that. That was going to be one of my next features to add to the tool.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018