Solved

PRINT TO A FILE WITH THE FILE PATH HARDCODED

Posted on 2014-01-23
7
280 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 69

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 69

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 69

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

14 Experts available now in Live!

Get 1:1 Help Now