Solved

PRINT TO A FILE WITH THE FILE PATH HARDCODED

Posted on 2014-01-23
7
281 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

919 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

20 Experts available now in Live!

Get 1:1 Help Now