I have problem with method
Printer.NewPage
When I use it fist time in procedure it create new page but next time it just print text on the same page. First page is OK but on second page I have 5 (and more) pages one over other. What is the problem?
Printable View
I have problem with method
Printer.NewPage
When I use it fist time in procedure it create new page but next time it just print text on the same page. First page is OK but on second page I have 5 (and more) pages one over other. What is the problem?
Worked fine for me
VB Code:
Printer.Print "Attempt page 1" Printer.NewPage Printer.Print "Attempt page 2" Printer.EndDoc
Well this is the code from my project, and it doesn't work. Can you tell me where is problem? I always get 2 page. First is great but second :(((((
Sorry for the format an comments in code but it's just Copy-Paste
Dim startXL 'Pocetak x sa leve strane
Dim startXR 'pocetak x sa desne strane
Dim startY ' pocetak Y
Dim Rb As Long ' redni broj linije koju stampa
Dim r As Boolean ' da li stampa u desnoj koloni
Dim NewDoc As Boolean 'da li je pocetak novog dokumenta
NewDoc = True
Printer.Font = "Tahoma"
Printer.Orientation = 1
Printer.PrintQuality = vbPRPQDraft
Printer.FontSize = 7
x = Printer.Width
y = Printer.Height
startXL = 100
startXR = x / 2 + 100
Set Base = OpenDatabase("h:\My Documents\Project\VB Project\MonSoft\base97.mdb")
Set rc = Base.OpenRecordset("select * from istorija") ' where panelID = 4444")
If rc.RecordCount = 0 Then MsgBox "Nema podataka za stampanje": Exit Sub
rc.MoveLast
rc.MoveFirst
Firma = rc!Objekat
startPage:
If NewDoc = True Then
Printer.FontSize = 20
Printer.CurrentX = x / 2 - Printer.TextWidth(Firma) / 2
Printer.CurrentY = 100
Printer.Print Firma
Printer.FontSize = 7
Printer.Print vbCrLf
Printer.CurrentX = startXL + 100
Printer.Print "Pregled dogadjaja od: "
Printer.CurrentX = startXL + 100
Printer.Print "Do: "
Printer.DrawWidth = 10
Printer.Line (startXL, Printer.CurrentY + 5)-(x, Printer.CurrentY + 5)
Printer.DrawWidth = 1
Printer.CurrentY = Printer.CurrentY + 20
startY = Printer.CurrentY
NewDoc = False
Else
startY = 200
End If
groupHeader:
Printer.CurrentY = startY
If r = False Then
Printer.CurrentX = startXL
Else
Printer.CurrentX = startXR
End If
cx = Printer.CurrentX
cy = Printer.CurrentY + 20
Printer.Print "Rb."
Printer.CurrentX = cx + Printer.TextWidth("rb.") + 300
cx = Printer.CurrentX
Printer.CurrentY = cy
Printer.Print "Datum"
Printer.CurrentX = cx + Printer.TextWidth("datum") + 500
Printer.CurrentY = cy
cx = Printer.CurrentX
Printer.Print "Vreme"
Printer.CurrentX = cx + Printer.TextWidth("Vreme") + 350
Printer.CurrentY = cy
cx = Printer.CurrentX
Printer.Print "Tip"
Printer.CurrentX = cx + Printer.TextWidth("Tip") + 200
Printer.CurrentY = cy
Printer.Print "Dogadjaj"
Printer.Line (startXL, Printer.CurrentY + 20)-(x, Printer.CurrentY + 20)
ProgressBar1.Max = rc.RecordCount
Do Until rc.EOF
ProgressBar1.Value = rc.AbsolutePosition
Rb = Rb + 1
If r = False Then
Printer.CurrentX = startXL
Else
Printer.CurrentX = startXR
End If
cx = Printer.CurrentX
Printer.CurrentY = Printer.CurrentY + 20
cy = Printer.CurrentY
Printer.Print Rb
Printer.CurrentX = cx + Printer.TextWidth("rb.") + 300
Printer.CurrentY = cy
cx = Printer.CurrentX
Printer.Print rc!datum
Printer.CurrentX = cx + Printer.TextWidth("datum") + 500
cx = Printer.CurrentX
Printer.CurrentY = cy
Printer.Print rc!vreme
Printer.CurrentX = cx + Printer.TextWidth("Vreme") + 350
Printer.CurrentY = cy
cx = Printer.CurrentX
Printer.Print rc!tipdogadjaja
Printer.CurrentX = cx + Printer.TextWidth("Tip") + 200
Printer.CurrentY = cy
Printer.Print rc!dogadjaj
Printer.Line (startXL, Printer.CurrentY + 20)-(x, Printer.CurrentY + 20)
rc.MoveNext
If Printer.CurrentY > Printer.Height - 2000 Then
If r = True Then
Printer.CurrentX = 9000
Printer.CurrentY = 15500
Printer.Print "Strana: " & Printer.Page
Printer.EndDoc
r = False
GoTo startPage
Else
r = True
GoTo groupHeader
End If
Else
End If
Loop
Printer.EndDoc
Well for staters Printer.NewPage isn't used in the code you posted??????????????
Try changing the top most Printer.EndDoc to Printer.NewPage, maybe. Since I can't run your code its hard to say.
i think it's your 1st "Printer.EndDoc" near the end or your code
VB Code:
If r = True Then Printer.CurrentX = 9000 Printer.CurrentY = 15500 Printer.Print "Strana: " & Printer.Page ' Printer.EndDoc (remove this line) r = False GoTo startPage Else r = True GoTo groupHeader End If
The ".EndDoc" should only come at the end of processing. It's telling your program...OK, I'm done talking to the printer, now release it and print. You should really only need one of these right at the end of your processing.
I think that's your problem, try it out...hopefully you get the results you're looking for....
I havn't looked at this carefully, I'm about to fall asleep it's 2315 here, but I think the enddoc's the problem. It literally means, the End of the Document...
I'm sorry but I put .EndDoc when I saw that .NewPage isn't working and forgot to change it back . I just want to see if I can do it that way (by the way it works fine just I have 5 print jobs with 1 page instead 1 with 5 page's on it) . Now I tried this code in New VB Project
Printer.print "Me"
printer.NewPage
Printer.print "Test 1"
printer.NewPage
printer.print "Sample text"
printer.NewPage
printer.print "Another samle text"
printer.EndDoc
and I got same result. First page is OK but on secon page I have all three text one over another. What's wrong whit this code ???
The code you have there on that last post looks good. Unfortuantly I think you may have some sort of local printer compatability issue. Unless someone else sees something that I don't I think you're out of luck on this one.....
:mad:
So what should do?? I tried this on HP DeskJet 640 and on 5D PDF Creator but it won't work
I dumped your code
VB Code:
Printer.print "Me" printer.NewPage Printer.print "Test 1" printer.NewPage printer.print "Sample text" printer.NewPage printer.print "Another samle text" printer.EndDoc
into a command button and it worked perfectly to my printer.
I then printed to file and Distilled it, so you can see the evidence in the attachement.
My printer is a Xerox DC432, using the PostScript driver.
*(&^@#)@# @#(*%^ )(@#*^% _)$^@#!@$
Thanx anyway
Well just to make you feel worse, I printed it with a PCL driver and that also worked fine!Quote:
Originally posted by vujke
*(&^@#)@# @#(*%^ )(@#*^% _)$^@#!@$
What should I do??? Should I reinstall Windows? I've tried this on WinME and Win2000.
What may be causing the problem is that you are moving the printer pointer position as you print (using CurrentX,Y) so I think even though you reset the position to a new page you are moving it back again with the CurrentX,Y code. Try running the code we posted and see if that works. If it does then its probably not a printer thing but a code thing and the difference in your code and ours is the Current X,Y.
I've tried before to do like you are doing and make a 'Report' using the printer object and thats what happened to me anyway.
If yo ucan get the length of the page maybe you could increment any place where you Set the CurrentX or Y (CurrentX=1000 +PageLength) with the value plus the length of a page so then you'd be setting the height for the next page.
I modified your code to test it without the data:
VB Code:
Dim startXL 'Pocetak x sa leve strane Dim startXR 'pocetak x sa desne strane Dim startY ' pocetak Y Dim Rb As Long ' redni broj linije koju stampa Dim r As Boolean ' da li stampa u desnoj koloni Dim NewDoc As Boolean 'da li je pocetak novog dokumenta Dim x As Long Dim y As Long NewDoc = True Printer.Font = "Tahoma" Printer.Orientation = 1 Printer.PrintQuality = vbPRPQDraft Printer.FontSize = 7 x = Printer.Width y = Printer.Height startXL = 100 startXR = x / 2 + 100 'Set Base = OpenDatabase("h:\My Documents\Project\VB Project\MonSoft\base97.mdb") 'Set rc = Base.OpenRecordset("select * from istorija") ' where panelID = 4444") 'If rc.RecordCount = 0 Then MsgBox "Nema podataka za stampanje": Exit Sub 'rc.MoveLast 'rc.MoveFirst Dim Firma As String Firma = "My Heading" 'rc!Objekat startPage: If NewDoc = True Then Printer.FontSize = 20 Printer.CurrentX = x / 2 - Printer.TextWidth(Firma) / 2 Printer.CurrentY = 100 Printer.Print Firma Printer.FontSize = 7 Printer.Print vbCrLf Printer.CurrentX = startXL + 100 Printer.Print "Pregled dogadjaja od: " Printer.CurrentX = startXL + 100 Printer.Print "Do: " Printer.DrawWidth = 10 Printer.Line (startXL, Printer.CurrentY + 5)-(x, Printer.CurrentY + 5) Printer.DrawWidth = 1 Printer.CurrentY = Printer.CurrentY + 20 startY = Printer.CurrentY NewDoc = False Else startY = 200 End If groupHeader: Printer.CurrentY = startY If r = False Then Printer.CurrentX = startXL Else Printer.CurrentX = startXR End If cx = Printer.CurrentX cy = Printer.CurrentY + 20 Printer.Print "Rb." Printer.CurrentX = cx + Printer.TextWidth("rb.") + 300 cx = Printer.CurrentX Printer.CurrentY = cy Printer.Print "Datum" Printer.CurrentX = cx + Printer.TextWidth("datum") + 500 Printer.CurrentY = cy cx = Printer.CurrentX Printer.Print "Vreme" Printer.CurrentX = cx + Printer.TextWidth("Vreme") + 350 Printer.CurrentY = cy cx = Printer.CurrentX Printer.Print "Tip" Printer.CurrentX = cx + Printer.TextWidth("Tip") + 200 Printer.CurrentY = cy Printer.Print "Dogadjaj" Printer.Line (startXL, Printer.CurrentY + 20)-(x, Printer.CurrentY + 20) ProgressBar1.Max = 3 'rc.RecordCount Dim cnt As Integer For cnt = 1 To 3 'Do Until rc.EOF ProgressBar1.Value = cnt 'rc.AbsolutePosition Rb = Rb + 1 If r = False Then Printer.CurrentX = startXL Else Printer.CurrentX = startXR End If cx = Printer.CurrentX Printer.CurrentY = Printer.CurrentY + 20 cy = Printer.CurrentY Printer.Print Rb Printer.CurrentX = cx + Printer.TextWidth("rb.") + 300 Printer.CurrentY = cy cx = Printer.CurrentX Printer.Print "datum " & cnt 'rc!datum Printer.CurrentX = cx + Printer.TextWidth("datum") + 500 cx = Printer.CurrentX Printer.CurrentY = cy Printer.Print "vreme " & cnt 'rc!vreme Printer.CurrentX = cx + Printer.TextWidth("Vreme") + 350 Printer.CurrentY = cy cx = Printer.CurrentX Printer.Print "tipdogadjaja " & cnt 'rc!tipdogadjaja Printer.CurrentX = cx + Printer.TextWidth("Tip") + 200 Printer.CurrentY = cy Printer.Print "dogadjaj " & cnt 'rc!dogadjaj Printer.Line (startXL, Printer.CurrentY + 20)-(x, Printer.CurrentY + 20) 'rc.MoveNext If Printer.CurrentY > Printer.Height - 2000 Then If r = True Then Printer.CurrentX = 9000 Printer.CurrentY = 15500 Printer.Print "Strana: " & Printer.Page Printer.NewPage r = False GoTo startPage Else r = True GoTo groupHeader End If Else End If Next cnt 'Loop Printer.EndDoc
But I am not sure what the report is supposed to look like.
Right now I get the first page as just the headers and a second page with all the values under the header.
So maybe I was wrong about adding the length of the page???
I wouldn't install your OS over this....Edneeis has a good point, if that doesn't work, I'd suggest looking toward something like Crystal Reports. But that's a whole nother animal altogether!
Vujke says the problem occurs with this simple code:
VB Code:
Printer.print "Me" printer.NewPage Printer.print "Test 1" printer.NewPage printer.print "Sample text" printer.NewPage printer.print "Another samle text" printer.EndDoc
and I don't get the same symptoms in either PCL or PS.
So I think vujke should print to file and let others try the print to say LPT: with a copy command from dos. Or if it's PCL which it seems to be, look at the pages in a PCL viewer.
Or print to file and look at the file in a hex editor: look for formfeeds or showpages.
Let's try and isolate one thing at time
OK. What driver to use to print to file? What printer?
I'd print to file with the printer & driver you're using already. Change the printer's port from LPT: or its ip address to FILE: by going into the printer's properties in Start/Printers.
When you print, it'll prompt you for a file name. Zip the file up and post it here: I'll look at in a PCL Interpreter and print it out.
Don't forget to change the printer port back again! I nearly always forget.
Well here at home I don't have printer but I use 5D PDF Creator. I'll send You 3 files.
HP 5L PCL print file
5D PDF Creator print file and
5D PDF Creator PDF file so You can see my result
I don't have driver for HP DeskJet 640 so I can't send you his prn file
Where is file ??? I send it again
Hi-
I opened the PCL file in my PCL Interpreter, and yes, it only has 2 pages just like your PDF. That indicates to me that the PCL itself is being generated with 2 pages: so the problem originates in the driver almost certainly, not at the printer itself.
I'm on leave from work, but I will be popping into the office tomorrow for a short while and I'll ask our PCL guru if there's anything in the PCL which looks unusual.
Perhaps in the meanwhile you should look at the window which the driver gives you at print time, to see if there's a check-box or a radio-button you might have overlooke which could have a bearing on this?