473,547 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing Selected Page(s) = Blank Pages

I am having a problem with printing selected pages. Actually, the problem
isn't with printing selected pages as it is more to do with having blank
pages print for those pages that have not been selected.

For example, if I were to have 5 pages with every second page printing, I
would get the following results:
Page 1 = Print OK
Page 2 = Blank
Page 3 = Print OK
Page 4 = Blank
Page 5 = Print OK

I am doing the validation as to whether or not anything gets printed within
the PrintPage event before anything else is done. If it has been determined
that a page is to be skipped, then I skip over the printing code (sending
information to the e.Graphics object) and go directly to the clean-up code
which Disposes of objects used within the print routine and determines if
there are more pages to be printed as well as determine the page orientation
(Portrait/Landscape) of the next page.

Does anybody have any ideas as to why this might be happening as well as any
clues on how to fix it?

Thanks,
Jody
Jul 19 '05 #1
4 4838
Hi Jody,

Could you post some code ?

Regards,
Fergus
Jul 19 '05 #2
"Jody Gelowitz" <jo**@mail.visu alstatement.com > wrote
I am having a problem with printing selected pages.


Not seeing any code, I would suggest you put a breakpoint on
all your Printer.NewPage lines and see if they are being called
when they should not be.

Please do not mix classic VB groups with VB.Net groups.
Groups like ..public.dotnet .* are for the .Net languages, and
groups like ..public.vb.* are for the prior versions of VB.

As you may know, there is no Printer object in .Net, nor
does the PrintDocument support a NewPage method. In
other words, the languages may be similar, but they are not
compatable and for that reason it is best to keep them separated
when asking your questions. Post .Net questions to the dotnet.*
groups and classic VB questions to the VB.* groups, please....

LFS
Jul 19 '05 #3
Hello,

"Jody Gelowitz" <jo**@mail.visu alstatement.com > schrieb:
I am having a problem with printing selected pages. Actually, the problem
isn't with printing selected pages as it is more to do with having blank
pages print for those pages that have not been selected.

For example, if I were to have 5 pages with every second page printing, I
would get the following results:
Page 1 = Print OK
Page 2 = Blank
Page 3 = Print OK
Page 4 = Blank
Page 5 = Print OK


Please post some code.

Do _not_ crosspost VB .NET related questions to the VB Classic groups
(microsoft.publ ic.vb.general.d iscussion). Thanks!

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Jul 19 '05 #4

"Fergus Cooney" <fi******@tesco .net> wrote in message
news:eU******** ******@tk2msftn gp13.phx.gbl...
Hi Jody,

Could you post some code ?

Regards,
Fergus


The code is at the end of this message.

I have a collection of forms that have been selected to be printed. Within
each form, there can be either 1 or 2 pages. The user also has the option
to select which pages of each form are to be printed through a treeview
control. The "PrintToGDI P" procedure is called which in turn sets up the
print job. The procedure that does the printing is under
"PrintPage_Even t_PDF" which is setup using the "AddHandler " call. The line
of code within "PrintPage_Even t_PDF" that determines if a page should be
printed is:
If strPages.IndexO f(m_intPrintPag e + 1) > -1 Then
"strPages" contains a comma-separated list of the pages to be printed (ie.
"1,2" or "1" or "2") based on user selection.

After thinking about this over the weekend, it would be easier for me to
create an array of pages from each form that are to be printed before
"PrintPageEvent _PDF" is called. This way, all pages are determined before
printing and all I will have to do afterwards is cycle through the array
instead of doing validation on each form within the print code. Regardless,
it would still be nice to know if it is my code causing the blank pages to
be printed, or if it is some type of bug within the .NET Framework
(v1.0.3705).

Thanks,
Jody

Private Sub PrintToGDIP(ByV al p_colForms As Collection)

Try

Me.Cursor = Cursors.WaitCur sor

If gdiprintDoc Is Nothing Then

gdiprintDoc = New Printing.PrintD ocument()

gdiprintDoc.Pri ntController = New Printing.Standa rdPrintControll er()

If Not m_bolPDF Then

AddHandler gdiprintDoc.Pri ntPage, AddressOf PrintPage_Event _XML

Else

AddHandler gdiprintDoc.Pri ntPage, AddressOf PrintPage_Event _PDF

End If

End If

'set up printer defaults

With gdiprintDoc

..DocumentName = "MyDocument "

If Not datatier.Shared Data.objPrintSe tting Is Nothing Then

If Not datatier.Shared Data.objPrintSe tting.strPrinte r Is Nothing AndAlso Not
datatier.Shared Data.objPrintSe tting.strPrinte r = "" Then

..DefaultPageSe ttings.PrinterS ettings.Printer Name =
datatier.Shared Data.objPrintSe tting.strPrinte r

End If

Try

If Not .DefaultPageSet tings.PaperSize .PaperName =
datatier.Shared Data.objPrintSe tting.strPaperN ame Then

Dim psTmp As New
Printing.PaperS ize(datatier.Sh aredData.objPri ntSetting.strPa perName, _

datatier.Shared Data.objPrintSe tting.intPaperW idth,
datatier.Shared Data.objPrintSe tting.intPaperH eight)

..DefaultPageSe ttings.PaperSiz e = psTmp

End If

Catch ex As Exception

End Try

If Not PresentationTie r.XMLForm.bolDa taOnly Then

If Not datatier.Shared Data.objPrintSe tting.objMargin Is Nothing Then

..DefaultPageSe ttings.Margins = datatier.Shared Data.objPrintSe tting.objMargin

End If

Else

..DefaultPageSe ttings.Margins. Left = 0

..DefaultPageSe ttings.Margins. Top = 0

..DefaultPageSe ttings.Margins. Right = 0

..DefaultPageSe ttings.Margins. Bottom = 0

End If

End If

'check if first page is landscape

If Not m_bolPDF Then

Dim objXMLForm As PresentationTie r.XMLForm

objXMLForm = CType(p_colForm s.Item(1), PresentationTie r.XMLForm)

..DefaultPageSe ttings.Landscap e = objXMLForm.bolL andscape

Else

Dim objPDFFOrm As PresentationTie r.PDFForm

objPDFFOrm = CType(p_colForm s.Item(1), PresentationTie r.PDFForm)

..DefaultPageSe ttings.Landscap e = objPDFFOrm.objP ages(0).bolLand Scape

End If

End With

Dim dlgPrint As New frmPrintDialog( )

dlgPrint.Docume nt = gdiprintDoc

If Not dlgPrint.ShowDi alog = DialogResult.Ca ncel Then

gdiprintDoc.Pri nt()

End If

Try

datatier.Shared Data.objPrintSe tting.strPrinte r =
gdiprintDoc.Pri nterSettings.Pr interName

Catch ex As Exception

End Try

Catch ex As Exception

MsgBox(ex.ToStr ing)

Finally

If Not gdiprintDoc Is Nothing Then

RemoveHandler gdiprintDoc.Pri ntPage, AddressOf PrintPage_Event _PDF

RemoveHandler gdiprintDoc.Pri ntPage, AddressOf PrintPage_Event _XML

gdiprintDoc.Dis pose()

gdiprintDoc = Nothing

Me.m_intForm = 0

Me.m_intPrintPa ge = 0

End If

Me.Cursor = Cursors.Default

End Try

End Sub

Private Sub PrintPage_Event _PDF(ByVal sender As Object, ByVal e As
Printing.PrintP ageEventArgs)

Dim graCanvas As Graphics

Dim rectClip As RectangleF

Dim priDoc As Printing.PrintD ocument

Dim intPrintCopy As Integer

Dim intDocW, intDocH As Integer

Dim sngScaleW, sngScaleH As Single

Dim sngScale As Single = 1

Dim sngDX, sngDY As Single

Dim objForm As PresentationTie r.PDFForm

Dim mtxXForm As Drawing2D.Matri x

Dim imgBackground As Image

Dim ioMS As IO.MemoryStream

Dim abyteImage() As Byte

Dim sngEMFScale As Single

Try

objForm = CType(m_colForm s.Item(m_intFor m + 1), PresentationTie r.PDFForm)

'Determine if this page has been selected to print

Dim nodeTmp As TreeNode

Dim objPrintForm As PrintForm

Dim strPages As String

For Each nodeTmp In tvwPrint.Nodes

Try

objPrintForm = Nothing

objPrintForm = CType(m_colPrin tForms(nodeTmp. Tag), PrintForm)

If objPrintForm.st rFormDisplayNam e = objForm.strForm DisplayName Then

strPages = objPrintForm.st rPagesToPrint

Exit For

Else

If Not objForm.strPrin tCopiesDisplayN ame Is Nothing Then

Dim intPrintCopyCou nt As Integer

For intPrintCopyCou nt = 0 To objForm.strPrin tCopiesDisplayN ame.Length - 1

If objForm.strPrin tCopiesDisplayN ame(intPrintCop yCount) =
objPrintForm.st rFormDisplayNam e Then

strPages = objPrintForm.st rPagesToPrint

Exit For

End If

Next

End If

End If

Catch ex As Exception

End Try

Next

If strPages.IndexO f(m_intPrintPag e + 1) > -1 Then

priDoc = CType(sender, Printing.PrintD ocument)

graCanvas = e.Graphics

graCanvas.PageU nit = GraphicsUnit.Po int

graCanvas.Smoot hingMode = Drawing.Drawing 2D.SmoothingMod e.HighQuality

'Retrieve the image from the page object

If Not DataTier.Shared Data.objPrintSe tting.bolDataOn ly Then

If objForm.objPage s(m_intPrintPag e).abyteImageDa ta Is Nothing Then

'EMF:Load emf from file

Dim strEMFPath As String = Application.Sta rtupPath & "\crashreports\ " &
DataTier.Shared Data.objCurrent Package.GetConf ig.strVersion & "\"

Dim strEMFFile As String = objForm.strForm Name & ".page" &
m_intPrintPage. ToString

Dim strFile As String = strEMFPath & strEMFFile & "\" & strEMFFile & ".emf"

If IO.File.Exists( strFile) Then

'load into background image

imgBackground = Image.FromFile( strFile)

sngEMFScale = 1 'graCanvas.DpiX / imgBackground.H orizontalResolu tion

Else

'set background image= false

imgBackground = Nothing

Exit Sub

End If

'*EMF*

Else

abyteImage = objForm.objPage s(m_intPrintPag e).abyteImageDa ta

ioMS = New IO.MemoryStream (abyteImage)

Dim sngImageW As Single, sngImageH As Single

imgBackground = Image.FromStrea m(ioMS)

ioMS.Close()

End If

End If

'NOTE***doc width/height are in 100ths of an inch 850=8.5 inches

If m_bolScale AndAlso Not DataTier.Shared Data.objPrintSe tting.bolDataOn ly
Then

If Not e.PageSettings. Landscape Then

'set scale

intDocW = priDoc.DefaultP ageSettings.Bou nds.Width -
priDoc.DefaultP ageSettings.Mar gins.Left -
priDoc.DefaultP ageSettings.Mar gins.Right

intDocH = priDoc.DefaultP ageSettings.Bou nds.Height -
priDoc.DefaultP ageSettings.Mar gins.Top -
priDoc.DefaultP ageSettings.Mar gins.Bottom

Else

'set scale

intDocH = priDoc.DefaultP ageSettings.Bou nds.Width -
priDoc.DefaultP ageSettings.Mar gins.Left -
priDoc.DefaultP ageSettings.Mar gins.Right

intDocW = priDoc.DefaultP ageSettings.Bou nds.Height -
priDoc.DefaultP ageSettings.Mar gins.Top -
priDoc.DefaultP ageSettings.Mar gins.Bottom

End If

Dim sngImgW As Single, sngImgH As Single

'Paper Width/Height will be in 100th inch

sngImgW = objForm.objPage s(m_intPrintPag e).sngPaperWidt h

sngImgH = objForm.objPage s(m_intPrintPag e).sngPaperHeig ht

If sngImgW = 0 Then

If Not objForm.objPage s(m_intPrintPag e).bolLandScape Then

sngImgW = 850 'default to 8.5 inch

Else

sngImgW = 1100

End If

End If

If sngImgH = 0 Then

If Not objForm.objPage s(m_intPrintPag e).bolLandScape Then

sngImgH = 1100 'default to 11 inch

Else

sngImgH = 850

End If

End If

sngScaleW = intDocW / sngImgW 'objForm.objPag es(m_intPrintPa ge).sngPageWidt h

sngScaleH = intDocH / sngImgH
'objForm.objPag es(m_intPrintPa ge).sngPageHeig ht

If Single.IsInfini ty(sngScaleW) Or Single.IsInfini ty(sngScaleH) Then

sngScale = 1

Else

sngScale = Math.Min(sngSca leW, sngScaleH)

End If

Else

With priDoc.DefaultP ageSettings.Mar gins

..Left = 0

..Right = 0

..Top = 0

..Bottom = 0

End With

sngScale = 1

If tsPrintPDF.Trac eInfo Then

Trace.WriteLine ("m_bolScale : " & m_bolScale.ToSt ring)

Trace.WriteLine ("Scale: " & sngScale)

End If

End If

'set translation for margins

'margins are in 1/100th an inch,for some reason this doesn't need to be
converted to page units

Try

m_sngPrintOffse tX = DataTier.Shared Data.objPrintSe tting.sngOffset X

m_sngPrintOffse tY = DataTier.Shared Data.objPrintSe tting.sngOffset Y

Catch ex As Exception

End Try

sngDX = priDoc.DefaultP ageSettings.Mar gins.Left + m_sngPrintOffse tX

sngDY = priDoc.DefaultP ageSettings.Mar gins.Top + m_sngPrintOffse tY

mtxXForm = New Drawing2D.Matri x()

mtxXForm.Scale( sngScale, sngScale)

mtxXForm.Transl ate(sngDX, sngDY, Drawing.Drawing 2D.MatrixOrder. Append)

graCanvas.Trans form = mtxXForm

rectClip = graCanvas.ClipB ounds

Dim rectfSource As New RectangleF(0, 0, imgBackground.W idth,
imgBackground.H eight)

Dim rectfDest As New RectangleF(0, 0, imgBackground.W idth * sngEMFScale,
imgBackground.H eight * sngEMFScale)

e.Graphics.Draw Image(imgBackgr ound, rectfDest, rectfSource,
GraphicsUnit.Pi xel)

Dim objField As PresentationTie r.PDFField

If Not objForm.objPage s(m_intPrintPag e).objFields Is Nothing Then

For Each objField In objForm.objPage s(m_intPrintPag e).objFields

Try

objField.bolPri nting = True

If (DataTier.Share dData.objPrintS etting.bolDataO nly) Then

If objField.bolPri ntDataOnly Then

objField.Render (graCanvas)

End If

Else

objField.Render (graCanvas)

End If

objField.bolPri nting = False

Catch exField As Exception

End Try

Next

End If

End If

'setup page,copy,form for next print call

'increment current page

m_intPrintPage += 1

'check if anymore pages on current form or more forms to print

If m_intPrintPage < objForm.objPage s.Length Then

e.HasMorePages = True

Else

m_intPrintPage = 0

'increment current form

m_intForm += 1

'check if more forms to print

If m_intForm < m_colForms.Coun t Then

e.HasMorePages = True

End If

End If

'check if more forms

If e.HasMorePages Then

'check next form's orienation

objForm = CType(m_colForm s.Item(m_intFor m + 1), PresentationTie r.PDFForm)

If objForm.objPage s(m_intPrintPag e).bolLandScape Then

e.PageSettings. Landscape = True

Else

e.PageSettings. Landscape = False

End If

End If

Catch exPrint As Exception

Debug.WriteLine (exPrint.ToStri ng)

Finally

'reset status

If Not mtxXForm Is Nothing Then

mtxXForm.Dispos e()

End If

If Not imgBackground Is Nothing Then

imgBackground.D ispose()

imgBackground = Nothing

End If

If e.HasMorePages = False Then

'reset print counters

m_intForm = 0

m_intPrintPage = 0

End If

End Try

End Sub
Jul 19 '05 #5

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

Similar topics

5
2143
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am really stuck here (probably the ol' Not seeing the tree cause of the forest thingy). But I just can not get this to work. The following is my Test...
4
5862
by: Jamey Shuemaker | last post by:
I've been looking for a way to do a duplex print job without a duplex printer. I reviewed some old posts about printing odd pages and found that most of them led to KB article 101075 or an export of the document to Word for duplexing there. I was looking for a VBA method for doing this, so the KB article is right out and when you export to...
0
2006
by: brettk | last post by:
Thanks to Bob's help, I was able to get .tif printing working. Now i've got a new problem; if the image is more than one page, it only prints the first page. Here's my code: ############################################ public class PrintTif {
4
5917
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been selected. For example, if I were to have 5 pages with every second page printing, I would get the following results: Page 1 = Print OK Page 2 =...
1
5690
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me...
5
2204
by: bobh | last post by:
Hi All, A clients database (built by another and not very well but, its what I have to work with) has bound forms that display customer information and when printed is three pages long. The information on page 3 is set to screen display only. When printing it prints 3 pages with the last page being a blank page. I have tried to surpress the...
0
5740
by: John Smith | last post by:
Hello, I have 7 different crystal reports that need to be collated. Since I want to end up with a page of each (which all together make a single report), I created a blank main report and then added the 7 as subreports so they can print one after the other. I'm supposed to be printing them from a VB.Net 2003 application and I will be passing...
3
2354
by: Kristijan Marin | last post by:
Hi, I need to print a report like document. So in report there are many articles and what I need when I get to the end, is to update page numbers on the second page where the Table of Content is .... or even update strings like Page 1 or 10 ... Page 2 of 10 etc .... When starting the report I don't know the total number of pages nor...
18
11268
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I...
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7437
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1050
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.