RadprintDocument

1 Answer 291 Views
GridView
atfat
Top achievements
Rank 1
Iron
Iron
atfat asked on 06 Jul 2021, 06:40 AM

Hello

When i use RadprintDocument to print a radgridview in a winform ,i have a problem that the logo used in the left header section shrinking m
I have found a question in your forum,and i follow your instructions to solve this problem but still not working;

can you give me some help by sending a small sample in vb.net please...

thx in advance

Regards

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Jul 2021, 08:36 AM

Hello, Atfat,

According to the provided information, it is not clear what is the exact problem with the logo in the printed document you are experiencing. However, I have prepared a sample project for your reference which result is illustrated below. Please give it a try and see how it works on your end.

Am I missing something? Could you please specify the exact steps how to reproduce the problem?

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

atfat
Top achievements
Rank 1
Iron
Iron
commented on 08 Jul 2021, 01:18 PM

Hello Dess

First of all thank you very much for your interesting...

I've got a png file with a size of 65x45 pixels and I want to place it in the leftheader. It does print it, but the logo is stretched instead of retaining its shape and its proper size .Is there any way to print this logo with its original size without stretching ,I can't find any way to do this. Any ideas?

thank you again
Regards
atfat
Top achievements
Rank 1
Iron
Iron
commented on 12 Jul 2021, 09:53 AM

Hello Dess
Any suggest please ?
I am looking forward to your reply...
thank you
Dess | Tech Support Engineer, Principal
Telerik team
commented on 12 Jul 2021, 10:53 AM

Hello, Atfat,

The sample project contains a picture with size 200 x 100 in the left header of the document. Considering the paper size (A4, A5, etc.) of the print document, the applied margins, the rectangle for rendering the header logo or some other header text is calculated. Since there is left, middle, right header, the rectangle's width for the logo takes 1/3 of the total document's width. Hence, the picture may be shrunk in order to fit the content. However, if you don't have middle and right header, you can adjust the rectangle for the logo.

Please have a look at the default implementation of the PrintHeader method for the RadPrintDocument. You can change the PrintLogo  method and pass the desired rectangle so that the whole image will fit in the available space: 
    Public Class CustomPrintDocument
        Inherits RadPrintDocument

        Protected Overrides Sub PrintHeader(args As PrintPageEventArgs)
            Dim headerRect As Rectangle = New Rectangle(args.MarginBounds.Location, New Size(args.MarginBounds.Width, HeaderHeight))
            Dim stringFormat As StringFormat = New StringFormat()
            stringFormat.LineAlignment = StringAlignment.Center
            Dim leftString As String = If((Me.ReverseHeaderOnEvenPages AndAlso Me.PrintedPage Mod 2 = 0), Me.RightHeader, Me.LeftHeader)
            Dim rightString As String = If((Me.ReverseHeaderOnEvenPages AndAlso Me.PrintedPage Mod 2 = 0), Me.LeftHeader, Me.RightHeader)

            If Me.HasLogoInHeaderFooterString(leftString) AndAlso Me.Logo IsNot Nothing Then
                Me.PrintLogo(args.Graphics, New Rectangle(headerRect.X, headerRect.Y, headerRect.Width / 3, headerRect.Height))
            End If

            stringFormat.Alignment = StringAlignment.Near
            args.Graphics.DrawString(ParseHeaderFooterString(leftString), Me.HeaderFont, Brushes.Black, headerRect, stringFormat)

            If Me.HasLogoInHeaderFooterString(Me.MiddleHeader) AndAlso Me.Logo IsNot Nothing Then
                Me.PrintLogo(args.Graphics, New Rectangle(headerRect.X + (headerRect.Width / 3), headerRect.Y, headerRect.Width / 3, headerRect.Height))
            End If

            stringFormat.Alignment = StringAlignment.Center
            args.Graphics.DrawString(ParseHeaderFooterString(Me.MiddleHeader), Me.HeaderFont, Brushes.Black, headerRect, stringFormat)

            If Me.HasLogoInHeaderFooterString(rightString) AndAlso Me.Logo IsNot Nothing Then
                Me.PrintLogo(args.Graphics, New Rectangle(headerRect.Right - (headerRect.Width / 3), headerRect.Y, headerRect.Width / 3, headerRect.Height))
            End If

            stringFormat.Alignment = StringAlignment.Far
            args.Graphics.DrawString(ParseHeaderFooterString(rightString), Me.HeaderFont, Brushes.Black, headerRect, stringFormat)
        End Sub
        Protected Overrides Sub PrintLogo(g As Graphics, rect As Rectangle)
            MyBase.PrintLogo(g, rect)
        End Sub
    End Class
Tags
GridView
Asked by
atfat
Top achievements
Rank 1
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or