473,386 Members | 1,708 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,386 software developers and data experts.

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
Nov 20 '05 #1
4 5910
Hi Jody,

Could you post some code ?

Regards,
Fergus
Nov 20 '05 #2
"Jody Gelowitz" <jo**@mail.visualstatement.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
Nov 20 '05 #3
Hello,

"Jody Gelowitz" <jo**@mail.visualstatement.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.public.vb.general.discussion). Thanks!

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

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eU**************@tk2msftngp13.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 "PrintToGDIP" procedure is called which in turn sets up the
print job. The procedure that does the printing is under
"PrintPage_Event_PDF" which is setup using the "AddHandler" call. The line
of code within "PrintPage_Event_PDF" that determines if a page should be
printed is:
If strPages.IndexOf(m_intPrintPage + 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(ByVal p_colForms As Collection)

Try

Me.Cursor = Cursors.WaitCursor

If gdiprintDoc Is Nothing Then

gdiprintDoc = New Printing.PrintDocument()

gdiprintDoc.PrintController = New Printing.StandardPrintController()

If Not m_bolPDF Then

AddHandler gdiprintDoc.PrintPage, AddressOf PrintPage_Event_XML

Else

AddHandler gdiprintDoc.PrintPage, AddressOf PrintPage_Event_PDF

End If

End If

'set up printer defaults

With gdiprintDoc

..DocumentName = "MyDocument"

If Not datatier.SharedData.objPrintSetting Is Nothing Then

If Not datatier.SharedData.objPrintSetting.strPrinter Is Nothing AndAlso Not
datatier.SharedData.objPrintSetting.strPrinter = "" Then

..DefaultPageSettings.PrinterSettings.PrinterName =
datatier.SharedData.objPrintSetting.strPrinter

End If

Try

If Not .DefaultPageSettings.PaperSize.PaperName =
datatier.SharedData.objPrintSetting.strPaperName Then

Dim psTmp As New
Printing.PaperSize(datatier.SharedData.objPrintSet ting.strPaperName, _

datatier.SharedData.objPrintSetting.intPaperWidth,
datatier.SharedData.objPrintSetting.intPaperHeight )

..DefaultPageSettings.PaperSize = psTmp

End If

Catch ex As Exception

End Try

If Not PresentationTier.XMLForm.bolDataOnly Then

If Not datatier.SharedData.objPrintSetting.objMargin Is Nothing Then

..DefaultPageSettings.Margins = datatier.SharedData.objPrintSetting.objMargin

End If

Else

..DefaultPageSettings.Margins.Left = 0

..DefaultPageSettings.Margins.Top = 0

..DefaultPageSettings.Margins.Right = 0

..DefaultPageSettings.Margins.Bottom = 0

End If

End If

'check if first page is landscape

If Not m_bolPDF Then

Dim objXMLForm As PresentationTier.XMLForm

objXMLForm = CType(p_colForms.Item(1), PresentationTier.XMLForm)

..DefaultPageSettings.Landscape = objXMLForm.bolLandscape

Else

Dim objPDFFOrm As PresentationTier.PDFForm

objPDFFOrm = CType(p_colForms.Item(1), PresentationTier.PDFForm)

..DefaultPageSettings.Landscape = objPDFFOrm.objPages(0).bolLandScape

End If

End With

Dim dlgPrint As New frmPrintDialog()

dlgPrint.Document = gdiprintDoc

If Not dlgPrint.ShowDialog = DialogResult.Cancel Then

gdiprintDoc.Print()

End If

Try

datatier.SharedData.objPrintSetting.strPrinter =
gdiprintDoc.PrinterSettings.PrinterName

Catch ex As Exception

End Try

Catch ex As Exception

MsgBox(ex.ToString)

Finally

If Not gdiprintDoc Is Nothing Then

RemoveHandler gdiprintDoc.PrintPage, AddressOf PrintPage_Event_PDF

RemoveHandler gdiprintDoc.PrintPage, AddressOf PrintPage_Event_XML

gdiprintDoc.Dispose()

gdiprintDoc = Nothing

Me.m_intForm = 0

Me.m_intPrintPage = 0

End If

Me.Cursor = Cursors.Default

End Try

End Sub

Private Sub PrintPage_Event_PDF(ByVal sender As Object, ByVal e As
Printing.PrintPageEventArgs)

Dim graCanvas As Graphics

Dim rectClip As RectangleF

Dim priDoc As Printing.PrintDocument

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 PresentationTier.PDFForm

Dim mtxXForm As Drawing2D.Matrix

Dim imgBackground As Image

Dim ioMS As IO.MemoryStream

Dim abyteImage() As Byte

Dim sngEMFScale As Single

Try

objForm = CType(m_colForms.Item(m_intForm + 1), PresentationTier.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_colPrintForms(nodeTmp.Tag), PrintForm)

If objPrintForm.strFormDisplayName = objForm.strFormDisplayName Then

strPages = objPrintForm.strPagesToPrint

Exit For

Else

If Not objForm.strPrintCopiesDisplayName Is Nothing Then

Dim intPrintCopyCount As Integer

For intPrintCopyCount = 0 To objForm.strPrintCopiesDisplayName.Length - 1

If objForm.strPrintCopiesDisplayName(intPrintCopyCoun t) =
objPrintForm.strFormDisplayName Then

strPages = objPrintForm.strPagesToPrint

Exit For

End If

Next

End If

End If

Catch ex As Exception

End Try

Next

If strPages.IndexOf(m_intPrintPage + 1) > -1 Then

priDoc = CType(sender, Printing.PrintDocument)

graCanvas = e.Graphics

graCanvas.PageUnit = GraphicsUnit.Point

graCanvas.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality

'Retrieve the image from the page object

If Not DataTier.SharedData.objPrintSetting.bolDataOnly Then

If objForm.objPages(m_intPrintPage).abyteImageData Is Nothing Then

'EMF:Load emf from file

Dim strEMFPath As String = Application.StartupPath & "\crashreports\" &
DataTier.SharedData.objCurrentPackage.GetConfig.st rVersion & "\"

Dim strEMFFile As String = objForm.strFormName & ".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.HorizontalResolution

Else

'set background image= false

imgBackground = Nothing

Exit Sub

End If

'*EMF*

Else

abyteImage = objForm.objPages(m_intPrintPage).abyteImageData

ioMS = New IO.MemoryStream(abyteImage)

Dim sngImageW As Single, sngImageH As Single

imgBackground = Image.FromStream(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.SharedData.objPrintSetting.bolDataOnly
Then

If Not e.PageSettings.Landscape Then

'set scale

intDocW = priDoc.DefaultPageSettings.Bounds.Width -
priDoc.DefaultPageSettings.Margins.Left -
priDoc.DefaultPageSettings.Margins.Right

intDocH = priDoc.DefaultPageSettings.Bounds.Height -
priDoc.DefaultPageSettings.Margins.Top -
priDoc.DefaultPageSettings.Margins.Bottom

Else

'set scale

intDocH = priDoc.DefaultPageSettings.Bounds.Width -
priDoc.DefaultPageSettings.Margins.Left -
priDoc.DefaultPageSettings.Margins.Right

intDocW = priDoc.DefaultPageSettings.Bounds.Height -
priDoc.DefaultPageSettings.Margins.Top -
priDoc.DefaultPageSettings.Margins.Bottom

End If

Dim sngImgW As Single, sngImgH As Single

'Paper Width/Height will be in 100th inch

sngImgW = objForm.objPages(m_intPrintPage).sngPaperWidth

sngImgH = objForm.objPages(m_intPrintPage).sngPaperHeight

If sngImgW = 0 Then

If Not objForm.objPages(m_intPrintPage).bolLandScape Then

sngImgW = 850 'default to 8.5 inch

Else

sngImgW = 1100

End If

End If

If sngImgH = 0 Then

If Not objForm.objPages(m_intPrintPage).bolLandScape Then

sngImgH = 1100 'default to 11 inch

Else

sngImgH = 850

End If

End If

sngScaleW = intDocW / sngImgW 'objForm.objPages(m_intPrintPage).sngPageWidth

sngScaleH = intDocH / sngImgH
'objForm.objPages(m_intPrintPage).sngPageHeight

If Single.IsInfinity(sngScaleW) Or Single.IsInfinity(sngScaleH) Then

sngScale = 1

Else

sngScale = Math.Min(sngScaleW, sngScaleH)

End If

Else

With priDoc.DefaultPageSettings.Margins

..Left = 0

..Right = 0

..Top = 0

..Bottom = 0

End With

sngScale = 1

If tsPrintPDF.TraceInfo Then

Trace.WriteLine("m_bolScale: " & m_bolScale.ToString)

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_sngPrintOffsetX = DataTier.SharedData.objPrintSetting.sngOffsetX

m_sngPrintOffsetY = DataTier.SharedData.objPrintSetting.sngOffsetY

Catch ex As Exception

End Try

sngDX = priDoc.DefaultPageSettings.Margins.Left + m_sngPrintOffsetX

sngDY = priDoc.DefaultPageSettings.Margins.Top + m_sngPrintOffsetY

mtxXForm = New Drawing2D.Matrix()

mtxXForm.Scale(sngScale, sngScale)

mtxXForm.Translate(sngDX, sngDY, Drawing.Drawing2D.MatrixOrder.Append)

graCanvas.Transform = mtxXForm

rectClip = graCanvas.ClipBounds

Dim rectfSource As New RectangleF(0, 0, imgBackground.Width,
imgBackground.Height)

Dim rectfDest As New RectangleF(0, 0, imgBackground.Width * sngEMFScale,
imgBackground.Height * sngEMFScale)

e.Graphics.DrawImage(imgBackground, rectfDest, rectfSource,
GraphicsUnit.Pixel)

Dim objField As PresentationTier.PDFField

If Not objForm.objPages(m_intPrintPage).objFields Is Nothing Then

For Each objField In objForm.objPages(m_intPrintPage).objFields

Try

objField.bolPrinting = True

If (DataTier.SharedData.objPrintSetting.bolDataOnly) Then

If objField.bolPrintDataOnly Then

objField.Render(graCanvas)

End If

Else

objField.Render(graCanvas)

End If

objField.bolPrinting = 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.objPages.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.Count Then

e.HasMorePages = True

End If

End If

'check if more forms

If e.HasMorePages Then

'check next form's orienation

objForm = CType(m_colForms.Item(m_intForm + 1), PresentationTier.PDFForm)

If objForm.objPages(m_intPrintPage).bolLandScape Then

e.PageSettings.Landscape = True

Else

e.PageSettings.Landscape = False

End If

End If

Catch exPrint As Exception

Debug.WriteLine(exPrint.ToString)

Finally

'reset status

If Not mtxXForm Is Nothing Then

mtxXForm.Dispose()

End If

If Not imgBackground Is Nothing Then

imgBackground.Dispose()

imgBackground = Nothing

End If

If e.HasMorePages = False Then

'reset print counters

m_intForm = 0

m_intPrintPage = 0

End If

End Try

End Sub
Nov 20 '05 #5

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

Similar topics

4
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...
5
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...
4
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...
0
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: ...
1
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...
5
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...
3
by: Richard MSL | last post by:
I have an application that prints documents that it creates. It uses what I believe is a standard .NET way of doing so, like this: PrintDocument pd = new PrintDocument(); pd.PrintPage += new...
0
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...
3
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...
18
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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,...
0
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...

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.