I wrote a small program to store and hopefully print contact information (in vb.net). The program contains a few text fields and a picture box. Saves the Information and so on. Can anyone recommend a quick way to save the form to a format that can then be transferred to her work computer and printed (she can't install my program at work, taboo policy and so on). Using the printform control, printform.print() with the PrintAction set to PrintToFile is just giving me garbled junk. I guess I could print to an html file bit by bit, but I thought I'd ask if anyone knows a better way. Also, with the html route I'm not sure how I'd add the contents of the picture box. Thanks in advance.
You can try saving your Form to a Bitmap using the DrawToBitmap Method which could then be saved as an image then printed out later, the main problem you will run into with this method is that the DPI settings are different between the screen and a printer.
Dim bmp As Bitmap = New Bitmap(Me.Width, Me.Height)
Me.DrawToBitmap(bmp, New Rectangle(New Point(0, 0), Me.Size))
bmp.Save("C:\temp\123.bmp") 'Set your path and your filename here
Related
this might sound like a repost of a question already asked. However, I have spent a few days looking through and testing many different examples from a number of different websites (incl. stackoveflow.com). Up to now, I got mostly undesired results and am a bit lost as to how to achieve this or something which produces good results? If anyone is able to help I would greatly appreciate it!
I work in VB.NET and use Visual Studio 2015.
My objective is to get a crisp image in the resulting RTF file when I open it in a text editor (I use WPS Office). However, the low quality, out of focus image I have been getting in the final RTF document is not a good header for the description I want to use it for! Nor will it look good after printing! I am not looking for a thumbnail image as the image is required for a larger document header.
Most solutions I have tried deal with resizing an image and then pasting it into a Rich Text Box(RTB).
However, although I have tried using interpolation, antialiasing, etc., the results are not great. For resizing, I have tried examples which use division, percentage, etc.
I am working on an app for my own personal use that "pastes" a screenshot of an active solution/app (i.e. bitmap) into a Picture Box(PB) and into an RTB using the clipboard, title is appended then text added manually in the RTB and the result is saved as an RTF file.
Image Quality issues I have found:
Pasting an image after resizing/scaling the original (or a copy) in the Picture Box reduces quality?
Saving to an RTF file or opening the RTF file in a text editor reduces quality? (Not sure which causes the issue?)
Both these processes result in a low quality, out of focus image (with or without interpolation, smoothing, antialiasing, etc.)? So, it seems to me that resizing before pasting reduces quality. I have tried pasting directly from the clipboard and also copying the image from the Picture Box to clipboard, then pasting to RTB. Both these procedures produce good results!
To be objective, I cannot share all the code I have tested, but share below a simple example of code which produces the best image quality for me, i.e. just simply pasting the screenshot directly from the clipboard to the RTB. However, the resulting image after pasting into the RTB has not been resized and is therefore too big. I don't want to manually resize the image in the RTF document as this would be an extremely repetitive task!
After pasting the bitmap into the RTF, I have used the Select All or Selection Start - 1 methods to select the image in the RTB, but to frame my question, "How can I resize the image in the RTB?"
You might ask why I want to do this. Well, pasting the bitmap directly into the RTB gives me the same quality image as the one in the Picture Box. There is a slight loss after saving to an RTF file and opening it in a text editor, but the quality is much better than the other methods mentioned above (i.e. resize then paste)! So, I got curious to attempt to paste and then resize! Here is my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Check whether PB1 is empty:
If PictureBox1.Image Is Nothing Then
'Get image from clipboard to PB1:
PictureBox1.Image = My.Computer.Clipboard.GetImage
'Resize image to fit PB1:
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
'Paste image:
RichTextBox1.Paste()
End Sub
I'm having hard times with this issue. I've a PDF File with fields so the user can fill them.
I'm using iTextSharp (on vb.net) to open the PDF file, read the fields and write the data back (and show it to the user).
Doc is not locked nor does it have any security measure.
I read it as follows:
Dim readerPDF As New PdfReader(Application.StartupPath & "\PDF\" & filename)
Dim pathTemp = IO.Path.GetTempFileName & ".pdf"
Dim stamperPDF As New PdfStamper(readerPDF, New IO.FileStream(pathTemp, IO.FileMode.Create))
Dim pdfFormFields As AcroFields = stamperPDF.AcroFields
then I simply loop pdfFormFields (I already have the key for each field saved in the database.
For each f as field_keys
pdfFormFields.SetField(f, "dummy text")
Next
This works great for every text input, no problems there. When I have a multiline field this thing goes nasty.
Filling using this approach gives me:
But If I open the original PDF file with Adobe Reader and I write the same I get:
So... I don't even know how to look this up on the internet. Is iTextSharp not supporting this or am I missing something?
EDIT: Link to PDF
EDIT: The itext dll was outdated. Download the lastest one and the problem still occurs.
The issue is likely with the properties of the multi-line field. One issue could be you have a fixed font and that would clip the text on screen when the field overflows. If the font is Auto it shrinks the font as the control fills up.
One thing to understand is that in PDF, the value of a field and the visual appearance of a field are two very different things. The field appearance is there to display the field in cases where the PDF viewer doesn't know what a field or it's value is. I believe the reason you're seeing What you're seeing is that there are some minor... and major... differences between how Adobe Reader generates appearances and how iText generates appearances. To test my theory, simply edit the field in Adobe Reader and see if the problem corrects itself. If it does, the the appearance generator in iText is the problem.
I am very new to managing PDF's in Vb.net, as for now I can open and view a PDF file in vb form.
the code goes like this:
OpenFileDialog1.ShowDialog()
AxAcroPDF1.src = OpenFileDialog1.FileName
But now I am stuck on how to rotate the view with a button. lets say I have 3 buttons 1 for clockwise rotation and the other for counterclockwise. And then I have a save button which saves the file to the rotated state. is this even possible?
I am using the adobe PDF reader in COM.
Short answer is no, not with the provided control. You need a third library to do this. The 3rd party controls work by creating a new image from the page you want to rotate and save that image as a new pdf page. Look into other pdf components to suit your needs. Most are not free, the good ones are pricey.
Here are some....
-iTextSharp
-PDFTron
-DynamicPDF
-PDFSharp
Can someone help me, how can I printscreen my screen that can be saved in gif or jpeg format
locally in VB.net
I know this question was asked a long time ago so I post this for posterity.
It's quite trivial to preform a screen capture operation using the CopyFromScreen method in the Graphics class. Also, the BitMap class ships with a Save method; making this even more trivial.
Using image As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Using surface As Graphics = Graphics.FromImage(image)
surface.CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, Point.Empty, image.Size)
End Using
image.Save("C:\myimage.jpg", Imaging.ImageFormat.Jpeg)
End Using
One possible solution when dealing with multiple monitors is to iterate, capture and save each screen as individual images. Place the above code inside the following For Each Next statement and replace Screen.PrimaryScreen with monitor. Be sure that you set a unique file name for each image.
For Each monitor As Screen In Screen.AllScreens
'...
Next
in my windows application there is a image saving process.i can save different images.the images details will seen in a grid ,when i click the corresponding row in grid the image will shown in a picturebox.i want to delete the open picture by pressing the delete key.i used the
"deletefile(path)" code for this operation.but there is an error that "This file is used by another process."if anyone knows the solution for this problem please help me.thank you.
Do you have a reference to a Bitmap object created from that file ? If so, the Bitmap object is locking the file and will prevent you from deleting it.
The problem is not where you delete your file, it lies in how you open your image to display it. Could you maybe add some code showing how you load your image ?
When you load an image using something list Bitmap.FromFile, the Bitmap object keeps a lock on the file until it is disposed. So you could simply use the
using(Bitmap bmp = Bitmap.FromFile(path))
{
/* The code using the bitmap to display it goes here */
}
construct to force it to release the file once you do not need it. This will prevent it from locking. The reason it locks is that it does not load the whole bitmap in memory when you create the bitmap object, it loads it lazily on demand, so it needs to keep a lock on the file.
Open the imagefile using Image.FromStream and make sure you close the stream after the image is loaded. That way you sould have no locks on the file.
Added after comment.
I don't have Visual Studio at hand and I'm a c# guy but it should look something like this.
Dim stream As New FileStream(specified_path, FileMode.Open)
Dim image As Image = Image.FromStream(stream)
picturebox1.image = image
stream.Close()