Solved

PRINT TO A FILE WITH THE FILE PATH HARDCODED

Posted on 2014-01-23
7
284 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS On fail action 5 48
Reactjs with .NET 3 70
Developing a front end to SPLUNK 1 50
ASP.NET Built-In Report Creator / Viewer 5 17
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 …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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