Results 1 to 3 of 3

Thread: ReportViewer and Microsoft PDF printing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    ReportViewer and Microsoft PDF printing

    I'm having trouble with margins when using the "Microsoft Print to PDF" printer to create a PDF document via the Microsoft ReportViewer.

    Even though I am setting the margins for my reports (see below), the left margin prints in the PDF document at position 0" (no left margin).

    Code:
    With newPageSettings
        .Margins.Top = 50       '...0.50 inch
        .Margins.Bottom = 25    '...0.25 inches
        .Margins.Left = 25      '...0.25 inches
        .Margins.Right = 25     '...0.25 inches
        .Landscape = False
        '...8.50" x 11.00" Letter-sized paper
        .PaperSize = New PaperSize(name:="Letter", width:=850, height:=1100)
    End With
    
    With ReportViewer1
        .SetPageSettings(newPageSettings)
        .RefreshReport()
        .SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
        .ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
    End With
    What am I doing wrong?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: ReportViewer and Microsoft PDF printing

    An update on this topic...

    After my report has rendered (visible on my PC screen), my objective is to print the rendered ReportViewer object to a PDF file.

    At this point, if I simply click the "Print" icon on the ReportViewer's toolstrip control, then the print dialog appears and I select "Microsoft Print to PDF" printer. The PDF is created and the left margin prints in the PDF document at position 0" (no left margin) even though my code has explicitly set the left margin to 0.25" (see post #1).

    I can get the PDF to print with the expected left margin (0.25") by doing the following steps after the report has rendered (instead of the above):

    1. Click the "Page Setup" icon on the ReportViewer's toolstrip control.
    2. The "Page Setup" dialog appears and the left margin value is 0.25 (as per the code in post #1).
    3. Change the left margin to a different value (e.g., 0.24 incudes).
    4. Close the "Page Setup" dialog.
    5. The ReportViewer object will repaint (the cursor will briefly change to the Wait cursor while the PC screen updates).
    6. Repeat the above steps #1-#3 but this time change the left margin back to 0.25 inches.
    7. Close the "Page Setup" dialog.
    8. The ReportViewer object will repaint (the cursor will briefly change to the Wait cursor while the PC screen updates).
    9. Click the "Print" icon on the toolstrip control
    10. Select the "Microsoft Print to PDF" printer.
    11. The "Printer" dialog will open.
    12. Click the "Print" button.
    13. The "Save Print Output As" dialog will open.
    14. Enter the desired filename for the PDF document and click the "Save" button.


    My question is why do I have to manually change/reset the left margin to get the PDF file to have the desired 0.25" margin? Is there a way to do this via code?
    Last edited by Mark@SF; Nov 9th, 2021 at 07:25 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: ReportViewer and Microsoft PDF printing

    I can get the left margin of the PDF to be correct with the following code which sets the ReportViewer1.PrinterSettings properties and then calls the ReportViewer1.PageSetupDialog method to display the "Page Setup" dialog.

    Code:
    With newPageSettings
        .Margins.Top = 50       '...0.50 inch
        .Margins.Bottom = 25    '...0.25 inches
        .Margins.Left = 25      '...0.25 inches
        .Margins.Right = 25     '...0.25 inches
        .Landscape = False
        '...8.50" x 11.00" Letter-sized paper
        .PaperSize = New PaperSize(Name:="Letter", Width:=850, Height:=1100)
    End With
    
    With ReportViewer1
        With .PrinterSettings
            .PrinterName = "Microsoft Print To PDF"
            .PrintToFile = True
        End With
        .SetPageSettings(newPageSettings)
        .RefreshReport()
        .SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
        .ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
    End With
    
    Dim result As Integer = ReportViewer1.PageSetupDialog
    The user has to click the "OK" button in the "Page Setup" dialog and then click the "Print" icon in the ReportViewer's toolstrip control.

    Is there a way to programmatically set the ReportViewer1.PrinterSettings properties without having to show the "Page Setup" dialog?
    Last edited by Mark@SF; Nov 9th, 2021 at 09:20 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width