Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP print Word doc with certain position of data field 2

Status
Not open for further replies.

Eliott

Programmer
Nov 8, 2009
91
BA
Hi there,
I have already forms printed in press-room (instead blank, plain paper) which I need to print out with data field on correct certain position (height from top, left, different font). Size of printed form is classic A4 (297x210 mm). I tried to solve it inside VFP 9 report but it was hard to measure and position more than 80 data fields scattered over form on different vertical and horizontal position - simply: fields wasn't on position where I thought it shall be (I measured form and entered on report each text field) during printing from VFP report. So, I decided to scan printed form and put inside Word doc as a picture and use it as "template" for more easiest positioning for each field. Now, I wish to fill them from VFP but don't know how to reference it; I planned to use Text Box control inside Word 2010, as it can be positioned very precise, but how to reference so many controls..?
Earlier I did similar things with table inside Word, but now not all data fields are positioned always on same doc's height or left position. Is here some kind person taht would help about it? Thank you.

There is no good nor evil, just decisions and consequences.
 
It's me, again,
I gave up from using Word & Mailing merge & Excel as one of possible solution for precise printing; I used Textboxes from Word (with mailmerge fields inside), due to their abilities to be positioned anywhere on page, but measuring object's position on upper part of page and in lower part of page doesn't obey same rule: simply, I directly set objects on upper part of page according to my measurement, and they appears almost correctly, but objects in lower part that I set on this way show error for almost 1 cm!? [ponder] It seems that I need to measure all V and H positions and calculate some "magic" error parameter in order to get correct position for each object by vertical position... beside this, Word print on different printers with different precision, so I tried to make some VBA code and form that will help to correct these deviations, but too much coding with unpromising result.
Due that I'm back on VFP9 and at first I made report with all necessary fields, then I made some form for report corrections (it open FRX as table): there is a listbox that shows name of textfields (type object 8), and their vpos, hpos, and width, calculated to millimeter. Double-click on listbox's row select some textfield and fill few fields where user can input new value and save into FRX - seems clean and elegant solution. But by comparison position information from report designer and what I got in the mentioned form I noticed small differences, not significant, but expected that calculation show very precise numbers! [surprise]
Some textfield has hpos, vpos and width in report designer 3.74 cm, 3.50 cm, 6.82 cm but in the table's fields I have 37.571, 35.190 and 68.527 cm!? My calculation based on formula:
Code:
 X [mm] = Y [inch] read from table-field / 0.039370 / 10000
Is it OK calculated then? Also, I refused to save printer environment inside report file, but I don't see anywhere ability to set margins. Do I need to somehow set margins to zero or some other value, and how margin size affect to printing positions? Thank you. [thumbsup2]

There is no good nor evil, just decisions and consequences.
 
Well, you face the difficulties Dan talked about, when saying:

Dan Freeman said:
There are specialized form-filling software packages that make the task much easier because Word simply wasn't built to put text at fixed locations on a piece of paper.
Gre

You initially said you had a scan of the form and embedded that as background of the word template. Then positioning the Textboxes and printing on blank paper should print things aligned, shouldn't it?

If you don't print the textboxes together with the form scan, you will get inaccurate results and no formula will fix that for more than one printer.

Bye, Olaf.
 
Yes, your formula looks correct.

You asked about setting margins. In the report designer, you should go to Report / Properties. On the Page Layout tab, set Print Area to "whole page". Then set the left margin to 0, and the column width to 21 cm - or as close to that as you can get (assuming you are using A4 paper). The effect of this is to set all the margins to zero.

You said that Word will print on different printers with different precisions. This is not specific to Word. It is a factor of the make and model of printer you are using. This is why you need the fudge factor that I referred to earlier. I suggest you try the above suggestion re page layout first. If that gives a small error in positioning, try adding or subtracting a small amount to every Hpos or Vpos until you get it right. You might need a bit of trial end error to find the amount, but it should be do-able.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Olaf said:
You initially said you had a scan of the form and embedded that as background of the word template. Then positioning the Textboxes and printing on blank paper should print things aligned, shouldn't it? If you don't print the textboxes together with the form scan, you will get inaccurate results and no formula will fix that for more than one printer.
Yes, I planned to use scanned paper form as temporary template, just to align all fields that will be printed, and second before printing I would cut this template (picture) and only fields would be printed on paper form, right on precise positions (V & H)... but it's not allowed to print template and data, as printing must be done on paper form approved by law, so I returned to VFP. I stuck with these margins, how they affect to report object positions, I guess positions are always based on top of paper, not from margins?
Also, I know in report designer is ability called grouping where is possible to group few objects; I planned, if it's possible to group dozen of them just to move programatically all of them at once. I checked data inside FRX table but wasn't able to notice some useful clue based on values I have about group object from Report designer. By moving whole group user could save time instead moving each control for same value, I guess.
Thanks Olaf.

There is no good nor evil, just decisions and consequences.
 
Even just the normal detail band is printed repeated per record. Actually a single form should have data of one record, I assune, you may have form sections having several persons or anything you could call a group, but that won't be in conjunction with report groups. In short report groups or group bands of course can repeat certain "subforms", but to be able to use that you even have less control of positioning.

The simplest way to adapt all data to a form sheet is with a detail band as large as a whole page and the record filling all form sections.

Bye, Olaf.
 
Thanks Olaf, [thumbsup2]
I decided to make a report as you suggested, probably will height of Header band be involved into calculation of each vertical position, I'll check later with printer.
In meantime I made a form that list all objects "of type 8" into form's listbox with their main properties (hpos, vpos, width...) and all listed FRU values I calculated into millimeter to be more informative to human. With this form a user is able to select "mis-justified" text object and insert new top and left positions and on this way easy change the report and save updated file. On this way user is able to make adjustment of this report to any printer if some of objects have printed on wrong positions (higher/lower or left/right). Until now I always put frx, scx... into project for compiling and getting EXE file, now I don't know where to save this FRX in order to be reachable to compiled EXE when whole app is complete, in order to be programmatic ally editable at runtime!? May I put this FRX into project or somehow left outside, as free table? [ponder]
Thank you.

There is no good nor evil, just decisions and consequences.
 
If you include the frx/frt in the project it will not be editable. You must distribute the report with the EXE as separate files.

You can simply right-click the report in the project manager and select "Exclude" to have it not included in the project.

What many of us do is include all reports, stored in memo fields, in a dbf/fpt so there's a default settings version available. When the report is first used you COPY MEMO to create standalone files that the user is allowed to edit. That also, conveniently, gives you a default version you can revert to when you get the inevitable OHMYGODIRUINEDIT call.
 
Eliott,

Did you try my suggestion re setting the margins and the making the Print Area "whole page"? This was about three or four posts ago. The reason I ask is that you explicitly asked about that, and I wanted to check that my suggestion solved that particular part of the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top