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?
Printable View
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?
Jpeg image, no problem.
MS Word document or PDF File are more complicated
Thanks .paul jgeg image will suffice, any idea where i can get some help on how to do this?
ok. show me your print code + i'll show you how to create a jpeg from that.
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.
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
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
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...
Hi all .paul said that this was possible in jpeg format, does anyone have any idea as to how i could do this?
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
Hi .paul
Many thanks for your reply, it works very well, Cheers have a good weekend