Results 1 to 11 of 11

Thread: [RESOLVED] VB.NET Print Object To MS Word Or PDF

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Resolved [RESOLVED] VB.NET Print Object To MS Word Or PDF

    Is it in any way possible to take the contents contained in a VS2008 Print object (Graphics and Text) and create either
    an MS Word document, PDF File Or A Jpeg image from these contents?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET Print Object To MS Word Or PDF

    Jpeg image, no problem.
    MS Word document or PDF File are more complicated

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: VB.NET Print Object To MS Word Or PDF

    Thanks .paul jgeg image will suffice, any idea where i can get some help on how to do this?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET Print Object To MS Word Or PDF

    ok. show me your print code + i'll show you how to create a jpeg from that.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VB.NET Print Object To MS Word Or PDF

    If you want a PDF you can install CUTEPDF - it's free - and it appears as a "printer" on the machine.

    Now you can create a PDF as simple as printing to an actual printer.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: VB.NET Print Object To MS Word Or PDF

    Hi .paul

    Here is a shortened version of the print code:

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

    'This Is where The Printing Takes Place



    'Print The Graphics Image onto the page
    '--------------------------------------
    Dim Img As Image = Image.FromFile(Application.StartupPath & "\Graphics\" & Doc_GraphicsImageToPrint)
    Dim UlCorner As New Point(0, 0)
    e.Graphics.DrawImage(Img, UlCorner)


    Dim PrintFont As New Font("Arial", 12,FontStyle.Bold, GraphicsUnit.Pixel, Nothing)


    For I = 1 to Grid.Rows-1

    e.Graphics.DrawString(Grid.Cell(I,1).Text, PrintFont, Brushes.Black,Grid.Cell(I,2).Text, Grid.Cell(I,3).Text)

    Next

    End Sub

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: VB.NET Print Object To MS Word Or PDF

    Hi szlamany

    Thanks for your reply, i have something similar called PDF24 which works well.
    The problem is that users are complaining that they have to first select the printer, then create the PDF and then save it and only then can they e mail it.
    What i am hoping to achieve is if they don't want to print the page but rather e mail it directly then the user clicks on a button, the page is then transformed into a PDF
    or jpeg file which the program can now automatically attach to an e mail and send it directly

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: VB.NET Print Object To MS Word Or PDF

    Yeah - I know the problem. Selecting a file name "programatically" for a printed PDF can be a real chore - I've faced that myself.

    If jpg works for you - then that might be the best choice. I've not done that myself - I'm sure someone will come along with some code for doing that...
    Last edited by szlamany; Sep 24th, 2013 at 10:32 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: VB.NET Print Object To MS Word Or PDF

    Hi all .paul said that this was possible in jpeg format, does anyone have any idea as to how i could do this?

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB.NET Print Object To MS Word Or PDF

    Code:
    Private Sub PrintToJPeg()
    
        Dim pd As New Printing.PrintDocument
    
        Dim outputImg As New Bitmap(pd.DefaultPageSettings.Bounds.Width, pd.DefaultPageSettings.Bounds.Height)
        Dim gr As Graphics = Graphics.FromImage(outputImg)
        gr.Clear(Color.White)
    
        'This Is where The Printing Takes Place
    
    
    
        'Print The Graphics Image onto the page
            '--------------------------------------
        Dim Img As Image = Image.FromFile(Application.StartupPath & "\Graphics\" & Doc_GraphicsImageToPrint)
        Dim UlCorner As New Point(0, 0)
        gr.DrawImage(Img, UlCorner)
    
    
        Dim PrintFont As New Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Pixel, Nothing)
    
    
        For I = 1 To Grid.Rows - 1
    
            gr.DrawString(Grid.Cell(I, 1).Text, PrintFont, Brushes.Black, Grid.Cell(I, 2).Text, Grid.Cell(I, 3).Text)
    
        Next
    
        outputImg.Save("filename", Drawing.Imaging.ImageFormat.Jpeg)
    
    End Sub

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Location
    Bulawayo, Zimbabwe
    Posts
    576

    Re: VB.NET Print Object To MS Word Or PDF

    Hi .paul

    Many thanks for your reply, it works very well, Cheers have a good weekend

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