OpenFileDialog to view pdf file c# - c#

I just want to open a pdf file and not to use it. If the user wants to be able to print via a glider. I want to just pressing a button will open the file if Acrobat Reader to view

To open the PDF, try using the following code with the PDF's filename as the command.
string command=#"c:\Users\User\Desktop\hello.pdf";
var process = new System.Diagnostics.Process
{
StartInfo =
new System.Diagnostics.ProcessStartInfo(command)
};
process.Start();

Visual Basic CODE:
Dim FilePath As String = "<YourFilePath>" & "<YourFileName>" & ".pdf"
Dim Process As System.Diagnostics.Process = New System.Diagnostics.Process
Process.StartInfo.FileName = FilePath
Process.Start()
Every time the relative pdf file will show on a separate window
Obviously you MUST HAVE Adobe Reader INSTALLED on the CLIENT PC
It works pefectly. Used in Visual Studio 2010.

Related

How to print a pdf file via c#

I'm beginner developer. I'm building a windows desktop form application like a notepad. The user will fill contact info and add text when the information is loaded, the user should be able to save the form as .pdf file and the possibility to print out the entire form directly, same as it was loaded. Which the best and quick alternative to accomplish this on c#?
Save a .pdf file at least on C#
You can use an installed PDF Reader by this:
Process prcs = new Process();
prcs.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = #"your file path"
};
prcs.Start();

open winmerge with two documents side by side c#

I am developing a Windows Forms app in c# that will make changes to a document and I want to include a button that will open the before and after in winmerge.
If it is possible, how do I do it?
More Detail:
I want to click a button Show Result with the starting file in the textbox.
It should open winmerge and open this dialog with the original file on the left and updated file on the right.
So far I have:
Process notePad = new Process();
notePad.StartInfo.FileName = "WinMerge.exe";
notePad.StartInfo.Arguments = txtIn.Text;
notePad.Start();
The updated file is in the same directory as the input file one level down in a folder called "UPDATED"
String leftFilePath = "...";
String rightFilePath = "...";
string exe = "winmergeu.exe";
String args = $#"""{leftFilePath}"" ""{rightFilePath}""";
Process.Start(exe, args);

c# how to inclued a pdf file to my windows form application

When i publish my windows application for a cd/usb , i want that pdf iclueded with application. And when install the program, pdf must copied to user's computer. Then i must know the pdf file's directory for click event. What should i do?
Note: I'm sorry for my bad english. I hope that explain my problem.
Here's picture from my app;
After edited;
pdfFullPath = Path.GetFullPath("Kullanım Kılavuzu.pdf");
and my buttons like;
private void btnFirma_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(pdfFullPath);
}
As Oguz said, ensure that the PDF is included in the build path first.
If your executable is always going to be in a fixed directory structure. So you will know where the pdf is in relation to the application. You can try:
string pdfFullPath = Directory.GetCurrentDirectory() + "\\document\\Kullanım Kılavuzu.pdf";
Almost forgot your working directory might be off.
In your button click try:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = pdfFullPath;
startInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\document";
Process.Start(startInfo);
Right click the pdf file and click properties, then in the properties window set the following properties:
Build Action: Content
Copy to Output Directory: Copy always
After publishing your app, the file will be at this path:
string pdfFullPath = Path.GetFullPath("Kullanım Klavuzu.pdf");

How to run "Run Bar" commands?

I need to run a command "control bthprops.cpl" in a C# program. This command brings up Bluetooth Settings control panel window. I tried running it using Process.Start() but the bluetooth window doesn't show up. I also tried writing a BAT file to the disk and executing it though my program, but still has the same problem. Is there any way to accomplish this?
//Dump BAT File and execute it
string path = System.IO.Directory.GetCurrentDirectory()+"startBT.bat";
string[] content = {"control bthprops.cpl"};
System.IO.File.WriteAllLines(path, content);
//Execute BAT file
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = path;
p.Start();
No need to go with a BAT file, this single line ought to open the specified control panel;
System.Diagnostics.Process.Start("control", "bthprops.cpl");
Since I don't have aforementioned bthprops.cpl; at least this works on W7 (open desktop settings)
System.Diagnostics.Process.Start("control", "desk.cpl");
If your control panel has tabs, you can even select what tab to open;
System.Diagnostics.Process.Start("control", "bthprops.cpl,,2");
Supply the full path and start it, for example:
var path = Path.Combine(Environment.SystemDirectory, "bthprops.cpl");
if (File.Exists(path))
{
Process.Start(path);
}

PDF to XPS Converting via Microsoft XPS Document Writer

Printing pdf document with Microsoft XPS Document Writer:
string filename = "C:\\1.pdf";
Process process = new Process();
process.StartInfo.Verb = "PrintTo";
process.StartInfo.FileName = #"C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe";
process.StartInfo.Arguments =
"/t \"C:\\1.pdf\" \"Microsoft XPS Document Writer\" \"xps\" XPSPort:";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardOutput.ReadToEnd();
process.WaitForExit();
The only problem is Save Dialog, which requests file name (*.xps) where to save result. Everbody advices DOCINFO to solve this problem, but I didn't find any example of using.
I need programatically print PDF File via Microsoft XPS Document Writer with default output file name. How should I use DOCINFO in this situation?
Can you help me?
You can't reliably print by spawning Acrobat Reader unless you give it a desktop session and there will be a user there, because it sometimes pops up dialogs that need user attention.
Also it violates Adobe's licence if used unattended.
You can, however print using Ghostscript.
There is a C# interface to Ghostscript called Ghostscript.Net that I've used successfully on some very large projects. Both Ghostscript and Ghostcript.Net are free & open source.

Categories