473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Print Document && Wrapping

I have some text lines to print that are much longer than the width of
the paper, maybe as much as 6 times. For a given page, I'd like
everything that doesn't fit to print on a second page, and whatever
doesn't fit there to go on a third page, etc, so that I can piece
together the final output by laying the pages side by side.

Things that don't work well:

1) Breaking up the line into sections of a given # of characters.
Problem with variable pitch fonts.
2) Writing output string to internal bitmap and grabbing it piece by
piece of a given width. (Too slow.)

Seems like there must be an easier solution to this.

May 14 '07 #1
6 5141
"Greg Esres" <ge****@boundvortex.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I have some text lines to print that are much longer than the width of
the paper, maybe as much as 6 times. For a given page, I'd like
everything that doesn't fit to print on a second page, and whatever
doesn't fit there to go on a third page, etc, so that I can piece
together the final output by laying the pages side by side.

Things that don't work well:

1) Breaking up the line into sections of a given # of characters.
Problem with variable pitch fonts.
2) Writing output string to internal bitmap and grabbing it piece by
piece of a given width. (Too slow.)

Seems like there must be an easier solution to this.
I assume you are using a PrintDocument and using DrawString to render the
strings you want to print. In that case, you can use MeasureString to find
out how wide your string is going to be when printed in a specified font. If
the length exceeds the page width, you remove a character from the string
and execute MeasureString again to find out how long the string is with one
character less. Loop until it fits in the page. I've done this and it is
quite fast (when compared with the speed of the printer) but if you find it
to be inefficient, you can do a dicothomic search instead of removing
characters one by one to find out the optimal length.
May 14 '07 #2
Hi,
"Greg Esres" <ge****@boundvortex.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I have some text lines to print that are much longer than the width of
the paper, maybe as much as 6 times. For a given page, I'd like
everything that doesn't fit to print on a second page, and whatever
doesn't fit there to go on a third page, etc, so that I can piece
together the final output by laying the pages side by side.
You have two options:
1- Print it yourself using PrintDocument (if so see my remarks to your
problems below)
2- Create a report using CR and let him handle those perky details :) , you
can simply pass the strings as parameters.
Things that don't work well:

1) Breaking up the line into sections of a given # of characters.
Problem with variable pitch fonts.
Nop, problem with your code, you have to use MeasureString to know how big
the string will be, and split it accordingly.
2) Writing output string to internal bitmap and grabbing it piece by
piece of a given width. (Too slow.)
I have never tried this before.

Printing using PRintDocument can be a pain in the back, at least at the
beginning, also be ready to spend a lot of papers doing test :)
May 14 '07 #3
On Mon, 14 May 2007 08:25:30 -0700, Greg Esres <ge****@boundvortex.com>
wrote:
I have some text lines to print that are much longer than the width of
the paper, maybe as much as 6 times. For a given page, I'd like
everything that doesn't fit to print on a second page, and whatever
doesn't fit there to go on a third page, etc, so that I can piece
together the final output by laying the pages side by side.

Things that don't work well:

1) Breaking up the line into sections of a given # of characters.
Problem with variable pitch fonts.
2) Writing output string to internal bitmap and grabbing it piece by
piece of a given width. (Too slow.)
Granted, I have not used the .NET print API yet, but I used to do a fair
amount of work with other print APIs. I think that given the built-in
functionality in .NET, you should not have to do any text-wrapping
yourself.

Two things are important here: PrintDocument provides you with a "one page
at a time", via the PrintPage event; and MeasureString provides a way for
you to specify the width of your output and return the total line-wrapped
height for the given string.

So, what you do is use MeasureString to figure out how far down each
text-wrapped string goes (DrawString will wrap text for you if you ask it
to). When you get a string that doesn't fit on the page, you're not done
with it yet. Save the height of the output string that has been printed
so far, and use that as a negative offset when drawing the string to the
next page (in the next PrintPage event). Continue this until the bottom
of your output string is within the bounds of the printed page, at which
point you move on to the next string (if any).

It seems to me that the above process should handle any font, without
requiring the use of secondary bitmap buffer.

Now, upon a second reading of your post, I'm not exactly clear on how you
want the strings to print. I had assumed you just wanted them
line-wrapped, based on the other replies I saw. But now that I read your
post again, I think it might be that you don't want the text wrapped, but
rather just want the text to spill across subsequent pages horizontally.
If so, the above idea is still the basic concept, but it's a little more
complicated because you need to build up a layout of your output, tracking
how many pages vertically and horizontally you'll need and printing the
appropriate strings with appropriate negative horizontal positions on
pages to the right of the initial column of pages of output.

Even so, you should not have to deal with text wrapping/breaking yourself,
nor should you have to generate internal bitmaps rather than printing text
directly.

Pete
May 14 '07 #4
Alberto Poblacion wrote:

<<Loop until it fits in the page. I've done this and it is
quite fast (when compared with the speed of the printer) but if you
find it
to be inefficient, you can do a dicothomic search instead of removing
characters one by one to find out the optimal length.>>

I did think of this, but thought I'd run into some issues with
variable pitch fonts; some things which line up might not do so when
a wider character is removed to the next page.

However, my current application is using fixed pitch fonts, so it will
work.

Thank you.

May 15 '07 #5
Ignacio Machin wrote:

<<Create a report using CR and let him handle those perky details :) ,
you
can simply pass the strings as parameters.>>
Yes, if I had known of this problem ahead of time, that would have
been an easier solution.

<<Nop, problem with your code, you have to use MeasureString to know
how big
the string will be, and split it accordingly.>>

I did think of this, but thought I'd run into some issues with
variable pitch fonts; some things which line up might not do so when a
wider character is removed to the next page.

However, my current application is using fixed pitch fonts, so it will
work.

Thank you.
May 15 '07 #6
Peter Duniho wrote:

<<negative offsets>>

Your second reading of my question got it right, and this was the
strategy I attempted at first. It worked well for about 3 pages, but
it seems that PrintDocument has a problem with negative offsets of
more than about -5000 to -6000. The text starts appearing from the
right side and moves towards the left.
May 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
by: Woolly Mittens | last post by:
I was asked to find some documentation which explains how to develop a website using DIV's and CSS, instead of TABLES. This is to explain to the people we outsource things to, how we want it done....
0
by: ^crazy^ | last post by:
Dear all, Seem it isn't easy to find, even on ms or msdn site. Where can I find it ? Please .. ^Crazy^
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: ...
1
by: Cognizance | last post by:
Hi gang, I'm an ASP developer by trade, but I've had to create client side scripts with JavaScript many times in the past. Simple things, like validating form elements and such. Now I've been...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, Does VS2005 have anything buildin to retrieve the Directory path for C:\Documents and Settings\UserName\Start Menu\Programs... Like an application has Application.StartupPath Or do...
3
by: Bob Sanderson | last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript...
17
by: Andrew C. | last post by:
I'm trying to complete excercise 1-23 in the K&R book, which calls for a program to wrap input lines at a given column, making sure to handle lines that wrap twice or don't contain whitespace. This...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.