optimized column width
Hi,
I want to create a report, that
(1) calculates the max-width of every column
(2) moves the columns to the optimized positions.
I've two questions:
1. Is this the right way to calculate the actual width of a Column
rtXYZ is the TppDBText-Field
RB is the report
RB.Printer.Canvas.Font := rtXYZ.Font;
iPixel := RB.Printer.Canvas.TextWidth(rtXYZ.Text);
iPrinterMMT := ppUtils.ppToMMThousandths(iPixel, utPrinterPixels,
pprtHorizontal, RB.Printer);
ActualWidth := iPrinterMMT/1000;
2. I need two steps of report-printing
(1) for calulating max
(2) to print after rearrange columns
How is it to do?
--
Best regards
Dietmar Brueckmann
I want to create a report, that
(1) calculates the max-width of every column
(2) moves the columns to the optimized positions.
I've two questions:
1. Is this the right way to calculate the actual width of a Column
rtXYZ is the TppDBText-Field
RB is the report
RB.Printer.Canvas.Font := rtXYZ.Font;
iPixel := RB.Printer.Canvas.TextWidth(rtXYZ.Text);
iPrinterMMT := ppUtils.ppToMMThousandths(iPixel, utPrinterPixels,
pprtHorizontal, RB.Printer);
ActualWidth := iPrinterMMT/1000;
2. I need two steps of report-printing
(1) for calulating max
(2) to print after rearrange columns
How is it to do?
--
Best regards
Dietmar Brueckmann
This discussion has been closed.
Comments
The ppToMMThousandths function will return you measurement in microns. Once
you get this value, you will need to convert that number into report units
(i.e. multiply by 1000 to get millimeters).
Then you can use the Report.Columns, Report.ColumnPositions, and
Report.ColumnWidth properties to define how you would like your columns to
look. Remember that this needs to be done before the report is generated
(preferably before Report.Print is called).
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Sorry for my bad translation to english.
I did'nt mean a column report. With "column" I mean a data column.
I.e. assume I've a report over an subset of "customer.db" with the Columns
CustNo, Company, City, State, Country, Addr1||' '||Addr2 ADDR
In a first step I want calculate maximum of width of each column.
Then I want to rearrange the columns
by calculating
rtCustno.Width := MaxWidth of column CustNo;
rtCompany.Left := rtCustNo.Left + rtCustno.Width + aDistance;
...
rtADDR gets the reamaining width.
I don't know where I can do the first step.
Is it necessary to print the report twice?
--
Best regards
Dietmar Brueckmann
Thanks for the clairification. I would not recommend generating the report
twice when all you need to do is simply traverse through your data. My
suggestion would be to traverse through your dataset manually measuring the
text of each record using the TextWidth function, then using this number
generate the report as you need.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Therefore it would be necessary, that I get the correct ..Printer.Canvas
before printing the report.
I didn't know anything about Printer.Canvas.
What's about a user deciding in Preview mode to print it on another printer
with an other pixelresolution.
--
Best regards
Dietmar Brueckmann
It is not entirely necessary to use the printer canvas when measuring text.
Though it may be a little less accurate, you can try creating a TBitmap and
using its canvas property to measure the text. Note that you will be
converting from screen pixels then. ReportBuilder converts every
measurement into microns before it is ready for printing. Then the micron
values are converted to printer pixels (specific to the printer connected)
before printed.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Hi Nico,
thanks for your quick answering! The RB-support is very comfortable!
But I need some more clarification.
I've tested in a little Application a TBitmap-Canvas vs. Printer-Canvas
It prints a text with an exactly measured TppShape around, to see the
exactness of measuring.
In Preview-mode it uses a TBitmap in Print-mode the Printer-Canvas.
In a test case (accXOR.Checked) it do it vice versa.
Then the measuring fails a little bit. You see it in longer texts.
In my opinion it means: different canvas gives different (false) measuring.
If you are interested I can post a .zip. But I don't know if it is possible
to do it in this group.
--
Best regards
Dietmar Brueckmann
If you would like you can send the small example you created in .zip format
to support@digital-metaphors.com and I'll take a look at it for you.
Yes, you're right, using the printer canvas will be more accurate when
printing to the printer because in contrast the screen only uses ~96 pixels
per inch where a printer typically uses 600. The problem in your case is
that you need to be sure the TppPrinter object has been created before you
try to use the printer canvas. If you add ppPrintr to your uses clause, I
believe you will then have access to the ppPrinter variable which will
create a TppPrinter object if it has not already been created.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I've done it and it works. Thanks for your advices!
I've some additional questions. But they are not necessary for that what I
want to do now. so I'll stop here.
--
Best regards
Dietmar Brueckmann