dcsimg
Results 1 to 5 of 5

Thread: Problem Printing RTF to PDF Printer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    86

    Question Problem Printing RTF to PDF Printer

    I'm looking for some help with this problem which is really baffling me. I'm a newbie in this particular area of VB.net "Printing".

    I have an RTF Editor form which saves an rtf file on one of my drives. I then call the print subroutine from the menu bar button. As I need to produce a PDF file I print the document to the PDF Printer. This appears to work as a PDF file is created in the correct folder - but it is blank!

    Code:
    Imports System.ComponentModel
    Imports System.Drawing
    Imports System.Drawing.Printing
    Imports System.IO
    Public Class frmTestPrint
        Private Sub FrmTestPrint_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            'load the rtf file in to Rich Text Box
            rtbContent.LoadFile("c:\APDSMan\Data\about.rtf")
    
        End Sub
        Private Sub PrintToolStripButton_Click(sender As Object, e As EventArgs) Handles PrintToolStripButton.Click
            'make sure that the print to PDF is selected
            Shell(String.Format("rundll32 printui.dll,PrintUIEntry /y /n ""{0}""", "Microsoft Print To PDF"))
    
            'initialise the PrintDocument
            Dim printDocument1 As New PrintDocument()
            PrintDialog1.Document = printDocument1
            Dim stringToPrint As String
            PrintDialog1.AllowSomePages = True
            PrintDialog1.ShowHelp = True
            Dim docName As String = "c:\APDSMan\Data\about.rtf"
            printDocument1.DocumentName = docName
            Dim stream As New FileStream(docName, FileMode.Open)
            Try
                Dim reader As New StreamReader(stream)
                Try
                    stringToPrint = reader.ReadToEnd()
                Finally
                    reader.Dispose()
                End Try
            Finally
                stream.Dispose()
            End Try
            printDocument1.Print()
        End Sub
    
    End Class
    Please can someone help me get this working?

    Many thanks for looking
    Pefound

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,389

    Re: Problem Printing RTF to PDF Printer

    Um, I don't see a PrintPage event handler. That's where the printing gets don't so if you don't one, nothing gets printed. You should visit our VB.NET CodeBank forum and check out Merrion's beginners tutorial on printing.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    86

    Re: Problem Printing RTF to PDF Printer

    I can only find a DataGridView print xam bits. So going to check out printpage event handler

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,389

    Re: Problem Printing RTF to PDF Printer

    Quote Originally Posted by Penfound View Post
    I can only find a DataGridView print xam bits.
    I'm not sure what that means but if you're trying to say that you couldn't find Merrion's tutorial thread, go to the VB.NET CodeBank forum, sort by Thread Starter, page to Merrion's threads and then just look down the list of titles until you find the right one.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    86

    Re: Problem Printing RTF to PDF Printer

    Found it!

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width