Reputation: 146198
I have a document that I want to be flipped / rotated 180 degrees when printed. (This is due to the orientation of label stock in the printer).
There is a property PrintDocument.PrinterSettings.LandscapeAngle
but it is read only.
I think this property is influenced by the printer driver and therefore not 'settable'.
Is there a nice way i can rotate the print by 180 degrees without having to do anything too nasty?
Upvotes: 3
Views: 9098
Reputation: 21
print a form and flip/rotate a PrintDocument in VB.NET and set DefaultPageSettings to landscape
Dim WithEvents mPrintDocument As New PrintDocument
Dim mPrintBitMap As Bitmap
Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPrintDocument.PrintPage
mPrintBitMap.RotateFlip(RotateFlipType.Rotate90FlipNone)
mPrintDocument.PrinterSettings.DefaultPageSettings.Landscape = True
' Draw the image centered.
Dim lWidth As Integer = e.MarginBounds.X + (e.MarginBounds.Width - mPrintBitMap.Width) \ 2
Dim lHeight As Integer = e.MarginBounds.Y + (e.MarginBounds.Height - mPrintBitMap.Height) \ 2
e.Graphics.DrawImage(mPrintBitMap, lWidth, lHeight)
' There's only one page.
e.HasMorePages = False
End Sub
Private Sub B_print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_print.Click
' Copy the form image into a bitmap.
mPrintBitMap = New Bitmap(Me.Width, Me.Height)
Dim lRect As System.Drawing.Rectangle
lRect.Width = Me.Width
lRect.Height = Me.Height
Me.DrawToBitmap(mPrintBitMap, lRect)
' Make a PrintDocument and print.
mPrintDocument = New PrintDocument
mPrintDocument.Print()
End Sub
Upvotes: 2
Reputation: 2561
have you tried before assigning it to the printer GDI rotate the image it self? thats what i did:
_currentPage = Image.FromStream((MemoryStream)_queue.Dequeue());
pageHeight = _currentPage.Height;
pageWidth = _currentPage.Width;
if (pageHeight < pageWidth)
{
_currentPage.RotateFlip(RotateFlipType.Rotate90FlipNone);
pageHeight = _currentPage.Height;
pageWidth = _currentPage.Width;
}
Upvotes: 1
Reputation: 1628
I guess that depends on what you define as being "anything too nasty" :-)
The PrintDocument class has a Graphics object you can use for this, which in turn has a TranslateTransform and RotateTransform method that will allow you to get things where you need them to be.
It's often worth taking a copy of the graphics object before you manipulate it so you can restore it back again when you're done.
Upvotes: 2