Solved

PRINT TO A FILE WITH THE FILE PATH HARDCODED

Posted on 2014-01-23
7
282 Views
Last Modified: 2014-01-27
Visual Studio Power packs on VB.net 2013
I get the form to print to a printer with no problem with the code below

 Dim a As Date
        a = Today.ToString("MM-dd-yy")
        Dim pf As New PrintForm
        pf.Form = Me
        pf.Form.BackColor = Color.White
        pf.Form.Controls.Remove(ListBoxmachines)
        pf.Form.Controls.Remove(bntback)
        pf.Form.Controls.Remove(BNTPRINTEFF)
        pf.PrinterSettings.DefaultPageSettings.Landscape = True
        pf.PrinterSettings.DefaultPageSettings.Margins.Top = 0.5
        pf.PrinterSettings.DefaultPageSettings.Margins.Right = 0.5
        pf.PrinterSettings.DefaultPageSettings.Margins.Left = 0.5
        pf.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0.5
        pf.PrinterSettings.DefaultPageSettings.Landscape = True
        pf.PrinterSettings.Copies = 1
        pf.DocumentName = Today.ToString("MM-dd-yy") & " " & "VSP ROOM"
        pf.Print()
        pf.Form.Controls.Add(ListBoxmachines)
        pf.Form.Controls.Add(bntback)
        pf.Form.Controls.Add(BNTPRINTEFF)




However I want to keep a electronic copy of the file. is there anyway I can print to a file  on PDF format an. I need to save this file  like for example  C:\files
0
Comment
Question by:teogos
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 39802869
Hi!

PDF-printers do allow normal set path, but it's double work.

Matti
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39802881
A bitmap would be much more easier: http://www.vb-helper.com/howto_net_save_form_image.html

If you want a PDF, you will need to use a 3party library like Aspose or ITextSharp
0
 

Author Comment

by:teogos
ID: 39803045
The problem with the BITMAP, is that I do not want to print all the controls on the form, Like CLICK BOTTOMS
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:teogos
ID: 39803116
Matti,  can you provide with some code samples. If this is possible, I just want to save the file. and later if the user wants to print will be his choice once the file is save
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39803123
>>The problem with the BITMAP, is that I do not want to print all the controls on the form, Like CLICK BOTTOMS

Hide them, save and reshow them.
0
 

Author Comment

by:teogos
ID: 39810061
Ok, Got the Form save to an Image with the code below

 Dim bmpScreenshot As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
        ' Create a graphics object from the bitmap
        Dim a As Date
        a = Today.ToString("MM-dd-yy")
        Dim gfxScreenshot As Graphics = Graphics.FromImage(bmpScreenshot)
        ' Take a screenshot of the entire Form1
        bntback.Visible = False
        Button1.Visible = False
        gfxScreenshot.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, Me.Size, CopyPixelOperation.SourceCopy)
        ' Save the screenshot  
        bmpScreenshot.Save("c:\VSP.Jpeg", ImageFormat.Jpeg)
        bntback.Visible = True
        Button1.Visible = True
        MsgBox("IMAGE SAVE")


But I want to everytime is save  put also the current date along with the image name on this line

bmpScreenshot.Save("c:\VSP.Jpeg", ImageFormat.Jpeg)
 but I can seem to figure out the sintax. I tried
something like this
Dim a As Date
        a = Today.ToString("MM-dd-yy")
bmpScreenshot.Save("c:\VSP.Jpeg& a", ImageFormat.Jpeg)
but does not work
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 500 total points
ID: 39810497
bmpScreenshot.Save("c:\VSP" + Today.ToString("MM-dd-yy") + ".Jpeg", ImageFormat.Jpeg)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now