Important alert: (current site time 7/16/2013 3:05:33 AM EDT)
 

winzip icon

Print-Preview and More

Email
Submitted on: 8/1/2002 8:54:13 AM
By: Morgan Haueisen  
Level: Advanced
User Rating: By 154 Users
Compatibility: VB 5.0, VB 6.0
Views: 53953
 
     Bug Fix: 4-19-04 This code gives you the ability to add print previewing to you application and the tools to allow you to make nice looking printed reports. You can fix the printing options such as paper orientation and preview/screen or allow the user to change them when running the report. Use it to design reports without wasting all that paper. I have tried to make this as simple as possible so you can add it to your existing projects and with only a little effort to change your reports. I have never before asked for votes, but I have put a lot of time into this and would appreciate your feedback (please be kind).

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 28 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

8/1/2002 9:22:08 AMRick Strickland

Great Job, I like it alot...Will certainly be in my toolbox
Thanks
(If this comment was disrespectful, please report it.)

 
8/1/2002 9:39:40 AMJohn Galanopoulos

Quality work. 5 from me. Keep up.
(If this comment was disrespectful, please report it.)

 
8/1/2002 4:58:01 PMBadr Almodarra

5 globes
keep up great work
(If this comment was disrespectful, please report it.)

 
8/1/2002 5:34:19 PMDaniel Camacho

Nice something lots of people are looking for... ***** from me..... Good luck...
(If this comment was disrespectful, please report it.)

 
8/1/2002 7:01:40 PMTurki A. Umairan

Wonderful.
(If this comment was disrespectful, please report it.)

 
8/1/2002 11:25:43 PMVic Richardson

First Class!
(If this comment was disrespectful, please report it.)

 
8/2/2002 5:39:43 AMJørgen Levesen

Thanks for the posting, this deserves to win this month contest. I have a question though: Do you plan i the near future to incorporate printing of pictures as well as text as part of the document ?
(If this comment was disrespectful, please report it.)

 
8/2/2002 8:45:41 AMjoyprakash saikia

Hi Morgan,
Its Great Code and Excellent Inovative Approach for printing. So here is my 5 globes for you.
I've Gathered some facts on it:
1) The Code is Excellent and Simplest to understand. Thank you for sharing it.
Some Suggestions:
1)It throws an error on While the Printer is Changed through the ComboBox on the FrmPrinterSetup due to "Printer.Duplex" Property.
2) As we know that "Doevents" statment is most unpredictable and resource consuming. From My point of view, If you can reduce the No of "Doevents" (Now it is total 10), then we see expected behaviour on Compiled Mode.
3)In 'FontTransparent' of 'clsMultiPgPreview' , the 'vNewValue' is never used for Assigning It.



(If this comment was disrespectful, please report it.)

 
8/2/2002 11:20:44 AMJames W Pyle, III

Very nice job.
(If this comment was disrespectful, please report it.)

 
8/2/2002 4:33:45 PMJF

Very good work, keep on coding...
5 from me
(If this comment was disrespectful, please report it.)

 
8/2/2002 6:11:42 PMUlli

You have a Recursive Call in pPrint. Try setting .Orientation = PagePortrait in Command2_Click

But good work otherwise, keep it up...
(If this comment was disrespectful, please report it.)

 
8/3/2002 6:54:03 AMTahir M. Akram

Nice and great effort. 5 out 5.
(If this comment was disrespectful, please report it.)

 
8/3/2002 10:46:48 AMMorgan Haueisen

Thanks for the feed back I really do appreciate it. I changed the code to fix the recusive call in pPrint. I did not think to prevent the programmer from entering a tab location larger then the page. I have also made the changes suggested by joyprakash saikia. Thanks again for your assistance. Morgan
(If this comment was disrespectful, please report it.)

 
8/3/2002 10:26:48 PMR. Watson

Excellent code!! Just one suggestion for future enhancement. As of now, it prints in bitmap (choppy chars). Although OK for preview (it being a bitmap) on the actual printing you should convert it to a richtext so it can be "drawn" as text (sharp, true type text!). Otherwise great job!!
(If this comment was disrespectful, please report it.)

 
8/4/2002 10:02:25 AMmichael doering

Hello Morgan,
>
I think this is a good experiment
and I search a lot of months for a 'small' print-preview unfortunately
each page is a very big bitmap ~2,5 MB,
is this the ultimative solution ?
'...
I`m not sure, also I have no better suggestion.
I hope other people`s have any suggestion.
Anyway I voted with 5 globes.

(If this comment was disrespectful, please report it.)

 
8/5/2002 8:42:01 AMMorgan Haueisen

I started to write the preview using RTF files and Word but I ran into some problems.
Since I was not dealing with an object such as a printer or picture box I could not get a lot of information I needed.
For example:
* There was no way to find out how long the printed text was going to be.
* There was no way to position text vertically on a page or even know where on the page you were
* Did not know printable area (page height or width).
3. Using RTF Codes became very complicated, since there was no way to predict how or what combination of codes were going to be used.

If anyone knows a way to solve these problems, I would love to here them.

Thanks again for your interest,
Morgan Haueisen
(If this comment was disrespectful, please report it.)

 
8/5/2002 6:33:02 PMJF

I find your work of an exceptional quality.It is very well commented, very useful, it leaves the place for modification for private use. For your good work, and the numerous hours which you had to spend there, I wish you the price for the month contest!
(If this comment was disrespectful, please report it.)

 
8/14/2002 12:46:54 PMzeff calilung

cool! its nice.
could you send me a tutorial of your (Print-Preview and More)program
(If this comment was disrespectful, please report it.)

 
8/21/2002 7:51:13 AMAlaeddin Hallak

long awaited... great work
(If this comment was disrespectful, please report it.)

 
10/1/2002 5:12:02 PM

Good job, dude!
(If this comment was disrespectful, please report it.)

 
10/6/2002 9:10:45 PM

Nice work. finally this will help me organize my reports. thanks. mabuhay and more power
(If this comment was disrespectful, please report it.)

 
10/30/2002 7:30:23 PMDanny J.

Personaly, do you want to work with me?

Danny J.
(If this comment was disrespectful, please report it.)

 
10/30/2002 8:34:40 PM

Nice, much cleaner than the one i had to write recently (despite all the niggles above).

Shall be replacing some bits from my shabby effort with some bits out of this , much better, one... Keep it up ..
(If this comment was disrespectful, please report it.)

 
10/31/2002 2:19:37 AM

What is the utility of this ? All page are statically created inside the code. What about taking a RichTextBox for source ? That will be very more useful !
(If this comment was disrespectful, please report it.)

 
11/1/2002 12:16:38 AMRamu

This is one of the very best I've seen on PSC, keep up the good work

I'll be glad if you could do something on the printing after preview, the bmps give a bad quality of printing. This will be the best ever.
(If this comment was disrespectful, please report it.)

 
11/7/2002 10:10:58 AMBrian!!

Verry nice code, i have been looking for something like this 5 from me
(If this comment was disrespectful, please report it.)

 
11/7/2002 6:58:27 PM

This code is amazing....
(If this comment was disrespectful, please report it.)

 
12/20/2002 6:38:38 PM

Excellent, just the approach that i was looking for, prefesionnal quality. Keep up the good work
(If this comment was disrespectful, please report it.)

 
1/24/2003 10:30:11 AM

Excellent! A very good solution to a complex problem. In response to others...RTF as far as I know is impossible to overlay text on graphics, If someone knows how to do that I'd like to know. This is a great start to a great print engine.
(If this comment was disrespectful, please report it.)

 
2/6/2003 3:10:29 AMSanjayKattimani

Excellent code!!! Keep it up, God bless you :)
(If this comment was disrespectful, please report it.)

 
2/6/2003 12:09:17 PM

Good stuff, keep it up. 5 stars from me
(If this comment was disrespectful, please report it.)

 
2/6/2003 12:11:38 PM

Excellent code. Keep it up.
(If this comment was disrespectful, please report it.)

 
2/9/2003 3:23:12 AMDhaval Faria

really an excellent job.. 5 globes from me.
(If this comment was disrespectful, please report it.)

 
4/13/2003 5:08:14 AM

This is one super piece of coding.

5 ***** from me.

I have seen a lot of print preview solutions for VB, but this is simply one of the best....because you get alle the functionality of the build in Printer object.

JUST GREAT !!!
(If this comment was disrespectful, please report it.)

 
4/30/2003 10:45:52 PM

After searching and trying various ways of performing Print Preview for two days, I had a problem getting the system up and running. As it turned out, I was trying to make it too difficult. The system works and works well. It provides a set of tools for producing almost any kind of report you choose to do. The instructions are clear and simple. The code examples are handy and easy to follow. The results are outstanding. I give the system five globes, only because there is nothing more that I can give it, other than credits in the applications that I work on. Thanks for the good work.
(If this comment was disrespectful, please report it.)

 
5/1/2003 10:41:33 AM

Great, just what i was looking for !
(If this comment was disrespectful, please report it.)

 
9/4/2003 4:07:50 AMFaisal Farough

Excellent work! Since long time I was looking for such a code which can replace Crystal Report. You solved my problem. Now I'm using your code for printing/preview in all my projects. The only problem is the bmps
give a bad quality of printing. Keep it up. 5 stars from me. Thanks
(If this comment was disrespectful, please report it.)

 
9/6/2003 5:03:05 AMRizwan Tahir

Man u Save Me

;) this is the best VB Can DO!!!!

6 out of 5 from me :)

Riz
(If this comment was disrespectful, please report it.)

 
10/1/2003 9:30:15 PMMrVB50au

This is a very good print preview and I give you 5. You did well. Only one other thing, is it possible to print preview a retrieved document, save it after formatting text for retrieval later?
(If this comment was disrespectful, please report it.)

 
10/8/2003 1:59:14 PM

Muy buen trabajo muchacho.
Lo felicito.
Es un trabajo excelente y usted tambien !!!

(If this comment was disrespectful, please report it.)

 
10/14/2003 10:14:10 AM

The best VB coding I have encounterd on
PSC. And it really works. It is a very good
teaching example also. Keep up the good
work!
(If this comment was disrespectful, please report it.)

 
10/22/2003 3:16:11 PMLawrence Miller

You have done a really awesome job with this. I have incorporated it into my large project in just a matter of minutes. It does a great job. I then made some modifications you might be interested in. I moved the controls from the side to the top (more standard). I also added a new routine to it called Using. This method is based on the old QuickBasic PrintUsing command. Example:
cPrint.Using "\ \ $#,###.00","Total Amt:", TotAmt
It will cause you report columns to line up perfectly. I will be e-mailing this to you.
(If this comment was disrespectful, please report it.)

 
10/23/2003 10:34:31 AMMorgan Haueisen

Thanks for the comment and I look forward to seeing the PrintUsing code. One other person suggested moving the tool bar to the top; the reason I moved it to the side was because this space was already being used for the scroll bar (which did not need to be very large) and it provided the maximum possible viewing area for the report (less moving the page around). I realize that most previewing application have the tool bar on top but they also have less viewing area which means more moving required.
(If this comment was disrespectful, please report it.)

 
1/5/2004 12:19:44 PMPetko Petkov

OK
(If this comment was disrespectful, please report it.)

 
2/25/2004 7:44:21 AMaquarius24

excellent, one of the best ideas i have come accross. but how do you get it to print on a printer
(If this comment was disrespectful, please report it.)

 
3/1/2004 5:05:17 PMJohn G

Luv this code. however the rotated text feature comes out different on the preview as oppossed to the printed version. Page six of demo shows two Rotated print commands. Only one prints on the printed page. The one rotated 90 shows in the lower left of the printed page the second rotate command does not show at all.
Seems like a CurrentX positioning problem.

Neat code though and easy to comprehend.
Be nice to make it into a DLL.
(If this comment was disrespectful, please report it.)

 
3/1/2004 5:17:13 PMJohn G

Ignore my comments for now. The second time I tried everything looks good.
The only thing I can see is your sample is trusting to luck as to the currentX and CurrentY settings before the rotate commands
(If this comment was disrespectful, please report it.)

 
3/16/2004 3:16:52 AM

Very nice print class. Only one drawback (but apparently has to do with bmp): print from the preview a single page has bad quality fonts. Printing all is very good.
(If this comment was disrespectful, please report it.)

 
9/8/2004 3:19:09 AM

very good code i really needed such code from long time
thanks to u
(If this comment was disrespectful, please report it.)

 
10/8/2004 2:45:50 PMkerplunk_boy

GEEEEEEEEEEEEEEEEEEEEEEZ! A work of art! Got my 5 gloves! you saved my job!!!!
(If this comment was disrespectful, please report it.)

 
10/24/2005 9:28:15 PMHeriberto Mantilla Santamaria

Wow, This code is amaizing, I see you today is genial.
(If this comment was disrespectful, please report it.)

 
11/25/2005 6:40:21 AMMark Gambo

I just found this code about a week ago and it is better than any other code I was using previously. Thanks!!
(If this comment was disrespectful, please report it.)

 
12/26/2005 2:05:46 AMWhitefj

I note you are suggesting using DIJPG.DLL for your program. I searched for this file and found the following which may be of interest:
Dijpg.dll tries to terminate antiviral programs installed on a user computer.
Dijpg.dll monitors user Internet activity and private information.
It sends stolen data to a hacker site.
Thought you may be interested !!
(If this comment was disrespectful, please report it.)

 
5/16/2006 5:53:44 AMkbhrx

this will be very very handy
thanks for sharing...
5 marbles for you and your marvelous print preview
(If this comment was disrespectful, please report it.)

 
8/15/2006 7:30:38 AMAjay Bagdia

Great work you have done, this is one of the best codes i have come across. i would
have done same modification in your old code worked gr8. thank you very much. i will mail the zip file to you
(If this comment was disrespectful, please report it.)

 
11/29/2006 10:33:12 AMfREBie

re: "Dijpg.dll tries to terminate antiviral programs installed on a user computer.
Dijpg.dll monitors user Internet activity and private information.
It sends stolen data to a hacker site."

According to Symantic, "dijpg.dll -- This is a non-malicious component that may be used by other applications." It may be installed by a Trojan horse, but dijpg.dll itself is not a threat.

http://www.symantec.com/security_response/writeup.jsp?docid=2005-050523-0 922-99&tabid=2

(If this comment was disrespectful, please report it.)

 
2/27/2007 1:47:19 AMMRM

that's one of wonderfull code i'v be seen

(If this comment was disrespectful, please report it.)

 
4/1/2008 4:29:11 PMGary

Fabulous piece of work.
Have you any plans to provide an "export" capability ?
I seriously need to be able to export(save) my reports in a variety of formats.. DOC, RTF, PDF, HTM, CSV, TXT.

This would certainly make your product better than anything else.

Thanks
(If this comment was disrespectful, please report it.)

 
2/14/2009 3:47:37 AMMartsoft

Very comprehensive code. Thank you for sharing.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.