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();
Related
MSDN says that starting in Windows 10, it is not possible to call SHOpenWithDialog to set the file association for the specified format.
When I tried to invoke the following two commands, neither of the "Open With" dialog boxes were able to set the file association.%1 is a full file path.
OpenWith.exe -override "%1"
rundll32.exe shell32.dll,OpenAs_RunDLL "%1"
I tried to start a process using the "openas" verb and the "Open With" dialog displayed, thus will have a check box named "Always open with this application," as-if clicking "Open With" from a file's context menu. But that will open the file, and an exception is thrown for an extension with no file association set.
public static void ShowOpenWithDialog(string extension)
{
string tempPath = $"{Path.GetTempPath()}{Guid.NewGuid()}{extension}";
File.WriteAllText(tempPath, "");
using(Process process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
UseShellExecute = true,
FileName = tempPath,
Verb = "openas"
};
process.Start();
}
File.Delete(tempPath);
}
I want to know, how can I call the "Open With" dialog used to associate file formats? Bandizip can do it!
I found a screenshot of an English language display system that sets up file associations for specified file types in Settings, like this.
I'm coding a Wpf application to print docx files. I can normally print it. This my code:
var info = new Process();
info.StartInfo = new ProcessStartInfo(filePath) //in this pass the file path
{
UseShellExecute = true
};
info.StartInfo.Verb = "Print";
info.StartInfo.CreateNoWindow = true;
info.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
info.Start();
info.WaitForExit();
info.Dispose();
But now, I want to print pages in this docx file by reverse order. First I wonder how can I use AddCoreProperty in DOCX package, but i don't find anyway to use it to print reverse order. I searched but could find any helpful information. Maybe by another solution, all useful with me.
I am developing an Add-In for MSProject 2013 and higher.
I want to safe/convert the opened .mpp file into an .pdf file without having an additional dialog for the user. He just presses the button an gets an notification when everything is done.
I need to save it in a spacific path and user a defined start and end date.
I tried the SaveAs-methode, but since it takes an MSProject.PjFileType as input and the is no option for pdf, I can't use this. PjFileFormat Enumeration
An other approche was using the DocumentExport-methode.
app.DocumentExport(#"D:/doc_exportqwre.pdf", MSProject.PjDocExportType.pjPDF, true, true, false, System.DateTime.Now, System.DateTime.Now.AddDays(42));
But in this case i only see 3 weeks at once. It is zoomed in and haven't found a way to change this. Changing the View in MSProject, before exporting does not help.
A third way is using the Windows10 pdf-printer:
// generate a file name as the current date/time in unix timestamp format
string file = (string)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
// the directory to store the output.
string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// initialize PrintDocument object
PrintDocument doc = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.Print();
but this way I can not give the starting and end date. This results in having way to many pages I do not need.
Is there any chance to achieve my goal with changing one of my solutions or is there any other option?
After not finding a proper solution, i used the windows 10 Printer and simulated keyboard events to insert the path in the dialog, which opens. With Enter i start the printing.
I know it is not a nice solution, but it is the onlyway i got it to work
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);
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.