doc/docx to postscript/ps - c#

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();

Related

SEP (Symantec Endpoint Protection) for C#

I am using Doscan.exe of SEP to scan files before uploading but there is no provision provided by SEP to generate a separate log file for each scanned file, so that's why I am not able to make sure whether the file is ok or not for uploading.
If anyone has a way to check this thing then please let me know.
I am using version 14.2
Thanks.
ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = " /ScanFile C:\\Users\\New Text Document (2).txt";
start.FileName = #"C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\14.2.3332.1000.105\Bin\DoScan.exe";
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
}

C# run a vbscript encoded file without the .vbe extension using process start

I can use process start and run a standard vbscript without its .vbs extension (see my code below) but how do you run a vbscript file that has been encoded using the VBScript Encoder object without the .vbe extension?
Process process = new Process();
process.StartInfo.FileName = #"wscript.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "//e:vbscript noExtensionFile";
process.Start();
If you're trying to run an encoded VBScript file, you want the VBScript.Encode engine rather than the VBScript engine. Try using //e:VBScript.Encode as your first argument to wscript.
Assuming your problem is with the file not having an extension and you can rename it you could do something like:
string filename = ....
if (!Path.HasExtension(filename))
{
string t = Path.ChangeExtension(filename, ".vbe");
File.Move(filename, t);
filename = t;
}
// rest of your code

Print Save as PDF

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\"";

Text content in pdf is not converted using pdf2swf

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

Automatic printing in C# with ProcessStartInfo cutting off bottom and top

I am using ProcessStartInfo to print my pdf file in my C# project in background. But the file that I printed is cutting off my top and bottom of the pdf file when printed. But when I print the same file by right clicking the pdf file it prints correctly.
Here is my code:
System.Diagnostics.Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = filename; // use default app to execute verb
//assert: can only go to local default printer
startInfo.Verb = "Print"; //prints to default printer
//try to keep Window hidden - work in background
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
// set process to startInfo and execute start
process.StartInfo = startInfo;
process.Start();
process.WaitForExit(10000);
process.CloseMainWindow();
process.Close();
this is in milliseconds. so it's only going to wait 10 seconds. Is that long enough?
process.WaitForExit(10000);
consider
process.WaitForExit();

Categories

Resources