Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Printing: Fit To Page


I have been asking this question on a couple of forms, and have not recieved a response yet. I am not sure if what I want to do is possible, but here goes...I am making a program that basically prints out specified pages. I want the program to print out webpages to "shrink to fit" (Internet Explorer terms) or "fit to page" (Netscape terms). I am using the Microsoft Internet Controls to create a hidden web browser, then when the user clicks on print I use the following code:


The page prints out fine, but I cannot get it to be centered and fit to one page. I like the layout in Netscape when you check fit to page in page setup, but I cannot find that in IE. Please help...

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
[crystal Report] Avoid Printer From Ejecting Page After Printing A 3 Line Page
Im taking a printout in crystal report - but there are only 3 lines and after printing it goes to next page - but I dont want it to goto next page.
Instead I want it to continue the rest of the printing - which may be in some other report etc - to continue printing from where it left behind (maybe one or 2 lines break)
But after printing 3 lines it automatically ejects out the paper and goes to next page
How do I avoid this ?

Edit by johnminkjan: Topic Title


Edited by - johnminkjan on 9/7/2004 12:01:29 PM

Printing A Web Page?
Here is what I am trying to do:

1. Open browser (or even in WebBrowser control)
2. Connect to a web site
3. Print to specified printer (which in my case will be Adobe Distiller)
4. Close it

I can do this in Word fairly simply with:

Public Sub PrintToPDF()
Dim objWord As New Word.Application
Dim objDoc As Word.Document

With objWord
.ActivePrinter = "Acrobat Distiller"

Set objDoc = .Documents.Open("C:somefile.doc")
objDoc.PrintOut Background:=True, OutputFilename:="C:somefile.pdf"

While .BackgroundPrintingStatus > 0

Set objDoc = Nothing
End With

Set objWord = Nothing
End Sub
But honestly I am not sure if I can even hook into IE and do this.

Any ideas and thanks!

Printing Page
hi. I have a print command button onmy form.I want it to have the printing properties appeared when my client clicks the button. I don't want just the screen of properties. I want it to be a real printing menu.. where once the user clicks the print button, he could actually print the whole form...


Printing Two Or More Rft Box In The Same Page
I need print the content of two rtf boxes, formated of course, and i don't now how.....

Is for a medical software, i need print the header and the footer of the page, and the medical receipt, the header and the receipt is in the same rtf box, but in the botton of the page i need print addicional data of the Doctor........

anyone can help me????

Printing Page
I have a page which has some labels on. I want to print a report with the data in these labels on it. But i want to chose which labels i print by using a check box next to each label. If the check box is enabled then it will print that label if it is not it wont print it.

Is this possiable and if so what code do i need?

Please HelP!

Printing To Fit Page

this problem is probably really easy, to fix, but i can't seem to figure it out. i've managed to get my picture contained in a frame with some text/shapes to print, but the problem that i'm having now is that the right & bottom edges of the frame & picture gets cropped when i try to have the image printed to be as large as the page.

here's what i have for it:
Printer.PaintPicture picture1.Image, 0, 0, Printer.Height, Printer.Width, 0, 0, picture1.Height, picture1.Width

i've been playing with the parameters for a while, but when i just use:
Printer.PaintPicture picture1.Image, 0, 0, Printer.Height, Printer.Width
i end up with a grey square fitted to be the same size as the paper, but the picture itself doesnt get printed. any ideas?


Printing A New Page
hi all,

i having some difficulties in printing now. i have got a report to print. This report is printed with some records on it. So i actually drew out a table using printer.line to contain my records.

But due to the size of the paper, the table can only contain up to 30 records. so i would like to ask around:

how do i actually force the 31st record to a new page? do i juz use printer.newpage?

thanks alot,

Printing A Web Page?
Here is what I am trying to do:

1. Open browser (or even in WebBrowser control)
2. Connect to a web site
3. Print to a specified printer (Adobe Distiller in my case)
4. Close it

I can do this in Word fairly simply with:

Public Sub PrintToPDF()
Dim objWord As New Word.Application
Dim objDoc As Word.Document

With objWord
.ActivePrinter = "Acrobat Distiller"

Set objDoc = .Documents.Open("C:somefile.doc")
objDoc.PrintOut Background:=True, OutputFilename:="C:somefile.pdf"

While .BackgroundPrintingStatus > 0

Set objDoc = Nothing
End With

Set objWord = Nothing
End Sub

But honestly I am not sure if I can even hook into IE and do this.

Any ideas and thanks!

Printing Page Nos.
I'm trying to Print a Report with page numbers which works OK except that the first page number is always 4 instead of 1. the rest of the pages are numbered correctly. Any ideas please?

Printer.Print "Page" & Printer.Page
Printer.FontBold = True
Printer.FontBold = False
FileInvoice = App.Path & "Invoice.txt"
Open FileInvoice For Random As #3 Len = Len(Invoice)
NoInvoices = LOF(3) / Len(Invoice)
For Index = 1 To NoInvoices
Get #3, , Invoice
NoLines = NoLines + 1
If NoLines = 8 Then
NoLines = 0
Printer.Print "Page" & Printer.Page
End If
Printer.Print "Invoice No."; Invoice.InvoiceNo; Tab(60); "Date"; Invoice.Today
Printer.Print "Patient No."; Tab(30); "Total"; Tab(40); "Paid"; Tab(55); "Balance"
Printer.Print Invoice.PatientNo; Tab(30); Format(Invoice.transactionTotal, "Currency"); Tab(40); Format(Invoice.AmountPaid, "Currency"); Tab(55); Format(Invoice.Balance, "Currency")
Printer.Print "-------------------------------------------------------------------------------------------------------------------------------------------------------------------"
Next Index
Close #3

Thanks in advance

Printing A Web Page
I just found out that this prints from a text box:

Printer.Print Text1

But when I change text1 to WebBrowser1 it prints "Microsoft Web Browser Control"

How Do I make it print the page?


Printing A Web Page
I just found out that this prints from a text box:

Printer.Print Text1

But when I change text1 to WebBrowser1 it prints "Microsoft Web Browser Control"

How Do I make it print the page?


Printing JUST Page 2 Of A PDF
I would like to print JUST PAGE 2 (or maybe all pages EXCEPT page1) of a PDF File.

I currently use ShellExecute to print the PDF file but really need to Exclude Page 1 during the print.

Thnaks, Randy

Printing A Page In Word
How can i print the second page only of a threepage long document ?

Printing Page X Of X In Word
Hello, i have some code that prints off word docs which all works ok.
However, i now want to pass in some variables to tell the system to only print off pages x of x.

iPageCount = objDoc.ComputeStatistics(wdStatisticPages)
iPFrom = InputBox("The document page count is " & iPageCount & "." & vbCr & "Please enter the printing start page. Leave blank if you want to print all the document.")
iPTo = InputBox("The document page count is " & iPageCount & "." & vbCr & "Please enter the printing end page. Leave blank if you want to print all the document.")
If iPFrom = "" Or iPTo = "" Then
objDoc.PrintOut From:=iPFrom, To:=iPTo
End If
objDoc.Close Savechanges:=wdDoNotSaveChanges
But it just seems to ignore the input fields.
Can anyone see where i am going wrong.


Saving As Web Page & Printing
This most likely falls outside of this forum, but I don't know where to look to find help. I am playing around with saving some Excel sheets as web pages to post on a Sharepoint site. However, when you print them from IE there are no options to fit to one page wide or one page tall, etc. Therefore, a document that's 1 page wide by 2 pages tall in Excel comes out as four pages that are impossible to read. Are there places to somehow make this fit either in Excel or IE? Do you need the original Excel document to be a particular size? If anyone can point me towards any resources that explain this I would be grateful.


Page Height W/printing
how do i set the page height?

i have continous labels and i need to set the page height to 15/16 inches high.

Page Layout When Printing
I currently am using some code from to print flex grid data directly and draw a grid around it.

This is what i am using:

Private Sub cmdprint_Click()
Const GAP = 60

Dim xmax As Single
Dim ymax As Single
Dim X As Single
Dim c As Integer
Dim r As Integer

With Printer.Font
.Name = MSFlexGrid1.Font.Name
.Size = MSFlexGrid1.Font.Size
End With

With MSFlexGrid
' See how wide the whole thing is.
xmax = xmin + GAP
For c = 0 To .Cols - 1
xmax = xmax + .ColWidth(c) + 2 * GAP
Next c

' Print each row.
Printer.CurrentY = ymin
For r = 0 To .Rows - 1
' Draw a line above this row.
If r > 0 Then Printer.Line (xmin, Printer.CurrentY)-(xmax, Printer.CurrentY)
Printer.CurrentY = Printer.CurrentY + GAP

' Print the entries on this row.
X = xmin + GAP
For c = 0 To .Cols - 1
Printer.CurrentX = X
Printer.Print BoundedText(Printer, .TextMatrix(r, c), .ColWidth(c));
X = X + .ColWidth(c) + 2 * GAP
Next c
Printer.CurrentY = Printer.CurrentY + GAP

' Move to the next line.
Next r
ymax = Printer.CurrentY

' Draw a box around everything.
Printer.Line (xmin, ymin)-(xmax, ymax), , B

' Draw lines between the columns.
X = xmin
For c = 0 To .Cols - 2
X = X + .ColWidth(c) + 2 * GAP
Printer.Line (X, ymin)-(X, ymax)
Next c
End With

End Sub
And here is the function used within that:

Private Function BoundedText(ByVal ptr As Object, ByVal txt As String, ByVal max_wid As Single) As String
Do While ptr.TextWidth(txt) > max_wid
txt = Left$(txt, Len(txt) - 1)
BoundedText = txt
End Function
Now when it prints it prints the grid in the top left of the paper. If i enter any Printer.Print statements it simply writes them directly over the grid.

What i need help with is format the alignment so that i can a) enter some text before each flex grid row, i.e. a label and b) move it down so i can enter a title for it aswell.

How could i do this?

i know this is code from somewhere else and im probably not posting in the correct section but i need to get it formatted correclty and looking ok.


Printing Correctly Onto A Page
I need to print information on a paper, which has a layout already set up.

It is an invoice, and what i need to print on it are the details, like invoice number, supplier, itesm bought, etc...

Now i need to position the items correctly on the paper, in their column.

Im' using a scale to millimeters (Printer.ScaleMode = 6)

Now my problem is this. Not every printer can start printing from the top-left corner of a paper. My printer can print from 0.5,1cm from the corner.

The problem occurs when the printer changes. I will not know exactly what printer the user will have, therefore i need to get to know the margin, so as i can correctly print it in the appropriate column.

I tried using this:

dxOffset = ((Printer.Width / 56.9) - Printer.ScaleWidth) / 2
dyOffset = ((Printer.Height / 56.9) - Printer.ScaleHeight) / 2
(the 56.9 is how much twips there are per millimeter [approximatelsy])

Normally, all printers have equal margin to the left, and to the right, but many printers have differenent margins from top and bottom, with the top tending to be larger.

That method works fine, because it divides the space by 2, for the X position, but for the Y it is not, because the ratio is different!

any solutions?

i'm banging my head ATM

thanks a lots!

Any Way To Restrict 2nd Page From Printing?
I want to print a single page. I write a footer to the page, and it fits nicely. However...I believe that when the last line of the footer is written, the printer kicks to a new page. So when I print, two pages come out: 1 that has everything I want, the other is blank. Is there a way to restrict the 2nd blank page from printing?

Printing Html Page From Vb
is there any way in vb to control Html page printing?
is there any ready made ocx or something ?

HTML Page Printing
Hi all, i have developed a small app that generate several HTML pages. My intent is to merge all HTML pages in one single document and then send to the printer.

I was wondering if there is any way to grab the WebBrowser content to an image such a bitmap and then send to the Printer object ?

thanks in advance


Printing 2 Forms On Same Page...

I know this is probably quite elementary but I have 2 forms (both to fit on 800x600 screens) and when I fire the PRINTFORM command on both of them, they obviously print nicely on 2 separate pages but each print job only takes up the top half of each page. I was wondering if there was a simple way to print the first form on the top half of the page and the second form on the bottom half of the page. This would save the wasted space on the bottom half of the two printed pages and amalgamate all of my information to one printed page. Any suggestions?

Printing Last Page Of Report
Crystal Reprts XI Developer

I've created a "Consolidation" report. Through VB 6, the user enter Assembly numbers and based off of those, it will capture all of the parts that make up each Assembly entered. If a part is used in more than one Assembly, the Quantities needed are added together and on the Consolidation report, that part number is printed once with the adjusted total.
The Assembly numbers entered are captured in Recordset1.
The Parts numbers, Quantities, and other info are captured in Recordset2.

The Detail lines of my Consolidation report works great.

My Problem is:
After the last Detail line, I want to print all the Assemblies that make up the Cosolidation report. Recordset1 contains these assemblies. I may have 1 record, I may have "n" records. Each record is a different Assembly Number. I tried dragging Recordset1.field1 to the Report Footer section. When the report is previewed, it only prints out the first Assembly Number (record-1, field-1). I want it to print out ALL the records (record-2, field-1, etc) in Recordset1.

Printing XML Or HTML Page

I am using a PDF printer, and I want to print XML/HTML and DOC files to PDF. I know Word provides a COM object to print through VB. I do it like this

Dim w As New Word.Application
Dim doc As Word.Document
w.ActivePrinter = "3-Heights(TM) PDF Producer"
Set doc = w.Application.Documents.Open(Text1.Text)
doc.PrintOut False, , Word.wdPrintAllDocument, Text2.Text, , , , , , , True
doc.Close (False)
w.Quit (False)

Does IE provide a similar method for printing? I have been unable to find any way f doing this.

Thank you

Page Numbers In Printing

I have purchased an activex for generating 2D BarCode.
I have attached it to my Porject and generating labels .

My Problem is I generate many labels with same data.
Each label should have Page Number in the Label.

Since it was same data I used Printer.Copies function for printing.
My Code is:

Printer.Copies = 10
Printer.ScaleMode = 6 ' sets printer scale to mm
Printer.FontBold = False
Printer.FontSize = 10
Printer.Font = "Bookman Old Style"

Printer.Print Tab(20); Printer.Page
Printer.Print Tab(20); "GRM39F104Z16C530/P924"
Printer.Print Tab(20); "SC5518AA2050"


So I should get 10 labels with same data but with Page Numbers 1 to 10.
Iam not getting the Page Number to be displayed.
Iam getting only the value as 1 for 10 copies.

Can anybody help me please....

Printing Centred On A Page
Hi chaps,

Can anyone tell me why my image is not centred on my page? I have taken the printer height and subtracted the height of my image from it and divided it by 2. I have also taken the printer width and subtracted the width of my image from it and divided that by 2. But i have more space at the top of the printed image than below it and more space to the right of the printed image to the left of it. Ive used code off the web that is suppose to do it and thats doing the same. Its as tho the left/right margins and the top/bottom margins are different but the calculation im doing should correct it.


Printing Headers On Each Page
Hi folks,

My program prints out headers on the first page fine along with current page number etc, then it lists about 56 items and does a newpage. My problem is that i have no idea how to get the headings printed again on subsequent pages.
Im assuming i cant just throw a page after every 50th row and then just reprint the headings again as i assume some printers may be set up with a bigger margin meaning less will print on a page anyway.

Any tips?


Full Page Printing
I have created a VB program to print a coupon that is dependant on the day of the week. However, I'd like to get 10 coupons on an 8.5 x 11" page. VB 6's maximum form size, however, is about 7 inches. Is there anyway I can create a command to print the form several times on one sheet? I thought about using x and y commands, but since I also want a picture on each coupon, that could be challenging. Any ideas?

Thanks to all in advance. I look forward to hearing from you all.


Printing-page Break
msg ="hello friends"
Printer.Print msg
Printer.Print ""


this code prints on lq1050+ dmp

but skip the complete page

can any body help to stop the printer -- remove the page break

i want it should print "hello friends" and stop there itself


Printing Past The Page End...
I need to have the printer print quite a few columns. The problem is that when the printer does not make a new pages to print all the columns. It will just print to the edge of the first page. Is there a setting for this, or will it just take a lot of code?

This is an example...

for x = 0 to Grid.Cols
Printer.Print "Something",
next x

If I have 100 columns in my grid, the printer won't continue printing any columns past the first page.

Printing Items On More Than 1 Page
Hi Everyone

How do you print a certain number of rows per page? for example if i have 50 items in a listview
and i want to print 20 rows on one page, 20 on the next and the remaining 10 on the last page.
The number of items of course will vary, it might be 25 one time it might be 37 the next time.

I know i can force a new page by having Printer.NewPage but what happens is, if i have 35 items it pad's up the last five item rows to make up 40 items. How do i stop this?

Can anyone help

Opening And Printing A Web Page In VB
Hi Folks
A quick question. What code do I need to open and print a web page from VB. The web page is an XML file I am creating from an ADO recordset. Also can I open the web page while keeping it hidden?


Printing - Detecting End Of Page???
When printing the contents of a textbox, what if the contents of the textbox could not hold on one page how could you detect when you have reached the end of a page.


"Jesus is Lord"

Printing A Form To Fit A Page
I found a function that can print the image in a picturebox to fit a form. But how can you print the whole form to fit the page scale?

Is There A Way To Set PAGE Margins When Printing?
I have my form set to print landscape, but when I do, the form prints on the left most edge of the page. Is there anyway to
"set" a print margin?

Also, I have the form set to maximized size, but it still does not print across the whole page. I have approx. 2" on bottom and 3" on right of blank paper. Cannot find how to make form any larger on properties....

Thx for ANY & ALL help!

Creating A New Page For Printing
I have a userform in a VB5 app that does some calculations and is then supposed to display the results on a new page which will be a template(custom) to accept the answers. My problem is that I don't know how to create a new page. I am looking to set up the userform so that when I press OK button, a new page will be generated possibly in a picture box and have a look like Microsoft Word(where you can see the outline of a 8 1/2"x11" page) and print the results on that page. Can anyone help me out with this?

Blank Page When Printing In CR 4.6 And CR 8.0
Anyone help me please.
When I'm trying to print a report in CR 8.0, it shows a blank page, or if I'm lucky, it shows only one line in the DETAILS section, when it should print at least 5 lines...

If i write
    Msgbox "Printing..."
    'And Then
    CR.Action = 1
It works OK in my Computer, but in other PCs it doesn't work every time

I was using CR 4.6 and it was working OK, but now I returned to it after uninstalling CR 8.0 and now it does the same...

If anyone can help me...
Thank you all.

Sorry for my bad English, I speak spanish.

Printing Web Page Problem
I am having a problem printing a web page.

I use:


That works except that for some pages an additional blank page is printed. If I change it to prompt the user with the same web page it only prints the one page and no extra blanks. It didnt matter whether I had header and footer information, the results were the same.

Any idea why prompting the user would have slightly different printing results then when there is no prompt? I would really prefer to avoid prompting the user for each and every page that needs to be printed without kicking out a bunch of extra blank pages.

Thanks in advance,


Web Page Printing - Urgent
I have a 200 column wide HTML report on Web sphere server (AS/400). I need to format and print the same. I am using IE 5.0 and above.

I need to have a Print button on the page which should set the
page setup (pre-defined) to format and then print the page.

There seems to be no direct way of hooking the page and printer setup using script. Can this be done thro' ActiveX control?

Any pointers highly appreciated.

Thanks in advance

Printing Page Format Issues
I have an MDI application that can have an infinite number of children. I have all the code neede to save the info from the child forms to separate files. Now I need to work on the printing of each form.
I'm not sure about how text formatting works in VB. Some of the data on the form needs to be printed with an underline, is there a way I can turn on and off what text gets underlined like in HTML (i.e. <u></u> tags)?

Also I was thinking of just doing printform, because my form already looks the way I want to have it printed out...but I can't get it to print out in landscape fullpage, it needs to be this way for filing purposes in the office.

if anyone has any ideas, I'd appreciate any help. I can also attach the code if neccessary.


Avoid Printing Worksheets On New Page

Is it possible to print all sheets in an Excel (97) file directly after eachother, so without having each sheet starting on a new page?
I would like to have all my data in one continous flow over the pages.

Thanks in advance,


Printing A Document With Page X Of Y Gets Y Wrong.
Strangest thing with Page X of Y. If I stop the program before the ActiveDocument.PrintOut Background:=0 instruction then the Page X of Y numbers seem correct. If I let the program fly then the 'Y' stays as 2 which was the template document's value in the Footer. Does anybody have any ideas about this ?

Printing Page Numbers {flexgrid}
hey all
can anyone point me to some examples showing how to print with pagenumbers on the pages..The code I have is working but I cant figure out how to print the page numbers.


Printing A GIF Sized To Print Page?
I am loading a image box with a GIF. I can get it to print using PaintPicture to the Printer.

But how can I scale it to fit on a single page?

Printing A Form On A Full Page
I am trying to print barcode labels on a sheet of barcode label stickers. First, I used the printer.print command to print labels, but was not able to make it print three across b/c the spaces I used the serperate the barcodes, actually ended up becoming the barcode equivalent of a space (resulting in one really long line of barcode).

Now I have a form laid out with 18 labels, and I just fill the labels with the barcodes I need and print it out. I would like to somehow get all 33 / page on one form, or atleast in one print job. I seemed to have reached the max on form height, otherwise I would simply add more.

If anyone has any idea on how to print a full page of labels, I would love to hear them =) Thank you!


Printing A Textbox.text Without Going Off The Page
How do you get a printer to print a Text box's text.... without going off the page. In other words, is there a way to set margins?
(PS. I'm just experementing

This is a test - I am experimenting

Printing A Picturebox Half Way Page
Hi folks,

when i print a image of a picturebox (doc with attached text on it)
it positioned itself slightly away from the side and top of the page.
when i use

Printer.PaintPicture Picture1.Image, 0, 0

well it doesn't exactly print the page at the corner of the actual paper
is there a way to solve this ?

Printing Html Code As Web Page
how can I print html code as it looks in internet exploer using VB
for example.. the text has following html code

< html >
< b >hello! how are you !!! < /b >
< /html >
vb supposes to send/ print following hello! how are you !!! in bold. to a printer

DataReport And Printing Current Page Only

I wrote a program to track equipment transfers from one account to another. It also saves them in an Access database, so I can an electronic record of them.

Once the user completes the form, they click on the Print button, which brings up the DataReport. Unfortunately, it shows all the records. So, the user has to navigate to the end, to their report, to print it.

How can I code it so that the DataReport will only show the current record on the program?

Thank you in advance!

Copyright 2005-08, All rights reserved