brettawv
asked on
printersettings conversion to vb.net
I found this code which is what I need for my program. I tried to convert it myself, but I get an error on
fi.SetValue(PD.PrinterSett ings, outname)
It says object reference not set to an instance of an object.
Here is the original code:
System.Type type = typeof(PrinterSettings);
this.PrinterSettings.Print ToFile = true;
FieldInfo outputPort = type.GetField("outputPort" ,
BindingFlags.NonPublic | BindingFlags.Instance);
outputPort.SetValue(this.P rinterSett ings,"FILE :");
Here is what I converted it to:
Dim PD As New Printing.PrintDocument
Dim fi As System.Reflection.FieldInf o
Dim outname As New Object
PD.PrinterSettings.PrintTo File = True
fi = PD.PrinterSettings.GetType ().GetFiel d("outputp ort", Reflection.BindingFlags.In stance)
outname = "C:\jimc.ps"
fi.SetValue(PD.PrinterSett ings, outname) "I get the error on this line"
PD.Print()
Can someone help me with this conversion?
fi.SetValue(PD.PrinterSett
It says object reference not set to an instance of an object.
Here is the original code:
System.Type type = typeof(PrinterSettings);
this.PrinterSettings.Print
FieldInfo outputPort = type.GetField("outputPort"
BindingFlags.NonPublic | BindingFlags.Instance);
outputPort.SetValue(this.P
Here is what I converted it to:
Dim PD As New Printing.PrintDocument
Dim fi As System.Reflection.FieldInf
Dim outname As New Object
PD.PrinterSettings.PrintTo
fi = PD.PrinterSettings.GetType
outname = "C:\jimc.ps"
fi.SetValue(PD.PrinterSett
PD.Print()
Can someone help me with this conversion?
Possibly this happens because first GetField argument in C# code is "outputPort", and in VB code "outputport". Last parameter in VB code is missing NonPublic flag.
ASKER
I'm not sure how to add that to the VB code. VB doesn't like the | sign. Any ideas on how to rewrite that line in VB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added and I still get the same error. Seems like I'm missing creating an instance of one of the objects, but I'm not sure what. I could be totally wrong to. If you have any other ideas, I would appreciate the help.
ASKER
I ended up using itextsharp to convert images directly to pdf which was the whole reason for asking this question. I was trying to send my picture to a postscript file and then convert it to pdf using ghostscript.
Thanks for trying to help. I'll try to work this out later, but I'm set for now.
I'm giving the points to gregoryyoung for at least helping me through part of the problem.
Thanks for trying to help. I'll try to work this out later, but I'm set for now.
I'm giving the points to gregoryyoung for at least helping me through part of the problem.
I appreciate the awarding of points for someone trying to help, but it is also misleading - it leads people to believe that the answer being rewarded solves the problem...which it does not.
I tried this and couldn't figure out why it was not working for me until I scrolled down and saw that the problem was not actually answered....
I tried this and couldn't figure out why it was not working for me until I scrolled down and saw that the problem was not actually answered....