I have the below code. As per my knowledge it is converting and saving as pdf. Can anyone explain this code?
Process cnp = new Process();
cnp.StartInfo.FileName = "AcroRd64.exe";
cnp.StartInfo.Arguments = "/n /t c:/test.jpg Microsoft Office Document Image Writer";
Updates:
I created a sample console application to trigger print and it is not working
class Program
{
static void Main(string[] args)
{
try
{
Process p = new Process();
p.StartInfo.FileName = #"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe";
p.StartInfo.Verb = "Print";
p.StartInfo.Arguments = "/n /t c:/test.png " + "Microsoft Office Document Image Writer";
p.StartInfo.CreateNoWindow = false;
p.StartInfo.UseShellExecute = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadKey();
}
}
Process is used to start and stop processes on your system.
Seems pretty clear that your code attempts to start a process "AcroRd64.exe", which I would guess is the pdf-reader Adobe Acrobat Reader. Argumens are arguments to the process, so basically, this is the equivalent of writing the following in command line:
AcroRd64.exe /n /t c:/test.jpg Microsoft Office Document Image Writer
There's a little more info on this under this other SO question.
Your code might doesn't work because the single argument Microsoft Office Document Image Writer contains whitespace. Try:
cnp.StartInfo.Arguments =
"AcroRd64.exe /n /t c:/test.jpg \"Microsoft Office Document Image Writer\"";
Related
I want to get internal names of apk files and I've tried a lot of ways and I've searched a lot. finally this is what I've got :
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
proc.Start();
using (StreamWriter sw = proc.StandardInput)
{
foreach (string path in Directories.GetAllFiles(#"E:\apk", "apk"))
{
sw.WriteLine("aapt d badging " + "\"" + path + "\"");
//following line doesn't work because sStandardInput is open
Debug.WriteLine(proc.StandardOutput.ReadToEnd());
}
}
// There will be a really huge amount of text (at least 20 line per sw.Writeline) and
//it impacts performance so following line is not really what I'm looking for
Debug.WriteLine(proc.StandardOutput.ReadToEnd());
GetAllFiles is a function that I've created to fetch all apk file full path. This is not final code.
As I've commented it out first Debug.WriteLine doesn't work and second one is not a good idea. how should I get output from proc?
I have tried running proccess by argument and its awful :)
I have a Winforms app that utilizes a dll (docX) to create a .docx document from a StringBuilder. I'm trying to open that document with Microsoft Word (the default program) with a button click. I tried the folowing code but I keep getting errors. Can someone point me in the right direction to accomplish this?
private void button3_Click(object sender, EventArgs e)
{
var x = "";
using (DocX document = DocX.Create("Testdocx.docx"))
{
document.MarginTop = 25f;
document.MarginBottom = 25f;
document.MarginLeft = 25f;
document.MarginRight = 25f;
Paragraph p = document.InsertParagraph();
FontFamily fontFamily = new FontFamily("Courier New");
p.Append(sb.ToString()).Font(fontFamily).FontSize(8); //where "sb" is a StringBuilder
document.Save();
x = Environment.CurrentDirectory;
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE";
startInfo.Arguments = x + "\\Testdocx.docx";
startInfo.UseShellExecute = true;
Process.Start(startInfo);
}
Your approach hard-codes the path to WINWORD. While this may work for your case, it is inflexible and brittle.
You can instead simply do
Process.Start(x + "\\Testdocx.docx");
That will find the default document handler for .docx files (which is Winword, assuming it is installed and you have not installed anything else that handles .docx files).
Just change 3 lines in your code. Your problem will be solved
here...
using (DocX document = DocX.Create(Application.StartupPath + "\\Testdocx.docx"))
here
document.Save();
x = Application.StartupPath;
.
and here
startInfo.Arguments = "\"" + x + "\\Testdocx.docx\""; // -> Quotes on either sides
.
.
Also I think you dont need to give full path for Word. Just do
startInfo.FileName = "WINWORD.EXE";
Or even just
startInfo.FileName = "WINWORD";
Arguments passed includes : Application , location
Process.Start("winword.exe", "C:\\you path here \\filename.docx");
I am running c# application in service mode. And i am using pdf2swf tool to convert odf to swf format. Images saved in pdf is converting. But if any test adding to pdf is not getting converted in service mode.
But when run as UI mode(Consoleapplication.exe) then everything is getting converted.
string inputFileName = this.Filename;
string outputFileName = inputFileName.Replace("pdf", "swf");
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} -o {1}", inputFileName, outputFileName);
string executingDirPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
string dataDirectoryPath = Path.Combine(executingDirPath, "pdf2swf.exe");
ProcessStartInfo psi = new ProcessStartInfo(dataDirectoryPath, sb.ToString());
psi.UseShellExecute = false;
System.Diagnostics.Process pdf2swf = new System.Diagnostics.Process();
pdf2swf.StartInfo = psi;
pdf2swf.Start();
pdf2swf.WaitForExit();
pdf2swf.Close();
pdf2swf.Dispose();
Regards
Sangeetha
Direct using process to start pdf2swf.ext maybe had some privilege problems.I used another way to solve this problem,write a batch file,then running the batch file by process.
Batch file sample:
c:
cd C:\Program Files (x86)\SWFTools\
pdf2swf.exe -f -T 9 -t "%1" -o "%2"
Code in program:
Process p = new Process();
string path = basePath + "/plugin/ConvertToSwf.bat";//batch file path
ProcessStartInfo pi = new ProcessStartInfo(path, filePath + " " + swfPath);//passing the file path and converted file path to batch file
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
I faced a similar problem recently. I solved the issue by adding a separate console application(Consoleapplication.exe) with administrative-rights that runs on my server without shell.
Also, try to upgrade to the newest version of pdf2swf.
FYI. I recently had this problem (thought it was fonts not being embedded but actually was missing all text in converted swf). What fixed it for me was to set:
pi.UseShellExecute = false;
AND set the working directory;
pi.WorkingDirectory = "C:\windows\temp"; // path where read & write is
So I have code to open a pdf programmatically. the code opens adobe reader just fine, but I get a dialog that pops up that says the file doesn't exsit. The problem is though that I can browse to the exact path that is being used to try and open the pdf in a windows explore, plus there is an if statement for if the file exists. So why isn't adobe opening the pdf?
the path for the Adobe .exe on the proc.StartInfo.FileName is correct.
I found this link: https://visibleprocrastinations.wordpress.com/2009/08/20/there-was-an-error-opening-this-document-file-cannot-be-found-acrobat-reader/ but I don't know if it still applies
PDF file path:
C:\Users\Printer\SharePoint\Partners - Doc\McG\Labels\TR109897\eLabels_TR109897.pdf
Heres the code I'm using:
Process proc = new Process();
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
//Define Location of adobe reader/command line
proc.StartInfo.FileName = #"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Arguments = string.Format(#"{0}", file.FullName);
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
if (proc.HasExited == false)
proc.WaitForExit(10000);
proc.Close();
return true;
}
It sounds like the shell is parsing up your filename in an unintended way. Try wrapping your filename in quotes:
proc.StartInfo.Arguments = string.Format("\"{0}\"", file.FullName);
I want to convert a doc/docx file to postscript by C# without using Word save to file since Word saved a big ps file.
Also, I want to know if there is a way to optimize a PDF by C#.
can I do that?
did you find anyway so you can convert doc/docx to ps?I have the same problem.
I know that it's too late to help you, but you can use ghostscript for optimizing pdf
int ExitCode;
ProcessStartInfo ProcessInfo;
Process Process;
ProcessInfo = new System.Diagnostics.ProcessStartInfo("gswin64.exe", "-dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=C:\\26178DATA\\LowResOutput.pdf -dCompatibilityLevel=1.4 C:\\26178DATA\\Holding.pdf");
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = true;
ProcessInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Process = Process.Start(ProcessInfo);
Process.WaitForExit();
ExitCode = Process.ExitCode;
Process.Close();