string ghostScriptPath = #"C:\Program Files (x86)\gs\gs9.09\bin\gswin32.exe";
string inputFileName = Server.MapPath("pdf/myprofile.pdf");
string outputFileName = #"D:\";
string ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o" + output + "-%d.jpg " + input;
Process proc = new Process();
proc.StartInfo.FileName = ghostScriptPath;
proc.StartInfo.Arguments = ars;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
I'm using asp.net application with c# language. I'm using the code above to convert the PDF to images using Ghost Script. Is it possible to retain Hyperlinks from PDF?
You can use PDFParser to read the PDF as text (into a string) and then parse the string yourself for "http".
Just for completeness:
// create an instance of the pdfparser class
PDFParser pdfParser = new PDFParser();
// extract the text
String result = pdfParser.ExtractText(pdfFile);
if(result.ToLower().Contains("http"))
{
//split the string on known factors like a "\n" and "/" for ending the url.
}
Related
ContextMenu context = new ContextMenu();
MenuItem menuItem1 = new MenuItem();
menuItem1.Header = $"Homeplus Search with '{text.Text}'";
menuItems.Add(menuItem1);
menuItem1.Click += delegate
{
string Encode = HttpUtility.UrlEncode(text.Text.Replace(' ', '+'));
Process process = new Process();
process.StartInfo.FileName = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "http://www.homeplus.co.kr/app.search.HeaderSearch.ghs?comm=usr.header.search.basic4&search_query="
+ Encode + " --new-window";
}
Finally, it must be execute commend "chrome.exe "http://www.homeplus.co.kr/app.search.HeaderSearch.ghs?comm=usr.header.search.basic4&search_query=%ea%b0%80%ec%98%88%ea%b7%a0%ec%9d%bc%ea%b0%802000%ec%9b%90 --new-window"
but exactly execute "chrome.exe http://www.homeplus.co.kr/app.search.HeaderSearch.ghs?comm=usr.header.search.basic4&search_query=가예균일가2000원" then finally it fail to search with decoded keyword.
I want to execute search with encoded keyword but I don`t know how to make it.
The following works for me. The text is encoded.
string text = "kim jong un";
string Encode = HttpUtility.UrlEncode(text.Replace(' ', '+'));
Process process = new Process();
process.StartInfo.FileName = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "http://www.homeplus.co.kr/app.search.HeaderSearch.ghs?comm=usr.header.search.basic4&search_query="
+ Encode + " --new-window";
process.Start();
I try to encode query once again. Then I made
HttpUtility.UrlEncode(text.Text.Replace(' ', '+'))
to
HttpUtility.UrlEncode(HttpUtility.UrlEncode(text.Text.Replace(' ', '+')));
So, It works very well. Thank you for struggle to find solution. You don`t need to answer my question.
I have two programs. The first program creates some JSON using Json.Net and then launches the second program, passing the JSON to it. The second program saves the JSON to a file using the SaveFileDialog from WinForms. The problem is the string values in the JSON are not saving properly.
For example, it saves
{
projectName : MY_PROJECT_NAME
}
When it should be
{
"projectName" : "MY_PROJECT_NAME"
}
Later when I'm trying to deserialize the JSON and convert to an object, I'm getting an error, but only with string values.
Here is the code that saves the file:
[STAThread]
static void Main(string[] args)
{
string seriaizedData = args[0];
Stream streamData;
SaveFileDialog savefiledialog = new SaveFileDialog();
savefiledialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Bamboo Wall";
savefiledialog.Filter = "bamboo files (*.bamboo)|*.bamboo|All files (*.*)|*.*";
savefiledialog.FilterIndex = 1;
savefiledialog.RestoreDirectory = true;
if (savefiledialog.ShowDialog() == DialogResult.OK)
{
if ((streamData = savefiledialog.OpenFile()) != null)
{
byte[] buffer = Encoding.ASCII.GetBytes(seriaizedData);
streamData.Write(buffer, 0, buffer.Length);
streamData.Close();
}
}
}
Here is the code that creates the JSON:
FloorModel grdData = GridData.gridData.gridDataClassList[GetActiveTabIndex()];
//How I get the object does not matter so much
string jsonObj = JsonConvert.SerializeObject(grdData);
print (jsonObj);
Process myProcess = new Process();
myProcess.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "Narnia.exe";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.Arguments = jsonObj;
myProcess.Start();
What am I doing wrong?
The problem is that you are passing JSON on the command line from one program to the other. Quote characters and spaces have special meaning to the command line parser, so you will need escape your JSON string judiciously if you want it to survive the command line parsing process intact. Another potential issue is the command line has a length limit, depending on what platform you are running on. So if the JSON you are trying to pass is large, it may be truncated even if you manage to escape it correctly. In short, I don't recommend this approach.
Instead, I would make your first program write the JSON to a temporary file, then pass the path of the temp file to the second program via the command line. That program can then copy the file to the correct location as specified by the user.
So, something like this:
Sending Program
FloorModel grdData = GridData.gridData.gridDataClassList[GetActiveTabIndex()];
string json = JsonConvert.SerializeObject(grdData);
string tempFile = Path.GetTempFileName();
File.WriteAllText(tempFile, json);
Process myProcess = new Process();
myProcess.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "Narnia.exe";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo.Arguments = '"' + tempFile + '"';
myProcess.Start();
Receiving Program
string jsonTempFile = args[0];
try
{
SaveFileDialog savefiledialog = new SaveFileDialog();
savefiledialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Bamboo Wall";
savefiledialog.Filter = "bamboo files (*.bamboo)|*.bamboo|All files (*.*)|*.*";
savefiledialog.FilterIndex = 1;
savefiledialog.RestoreDirectory = true;
if (savefiledialog.ShowDialog() == DialogResult.OK)
{
File.Copy(jsonTempFile, savefiledialog.FileName, overwrite: true);
}
}
finally
{
File.Delete(jsonTempFile);
}
I need to print multiple PDF-files from the hard-drive. I have found this beautiful solution of how to send a file to the printer. The problem with this solution is that if you want to print multiple files you have to wait for each file for the process to finish.
in the command shell it is possible to use the same command with multiple filenames: print /D:printerName file1.pdf file2.pdf
and one call would print them all.
unfortunately simply just to put all the filenames into the ProcessStartInfo doesn't work
string filenames = #"file1.pdf file2.pdf file3.pdf"
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = filenames;
neither does it to put the filenames as Arguments of the Process
info.Arguments = filename;
I always get the error: Cannot find the file!
How can I print a multitude of files with one process call?
Here is an example of how I use it now:
public void printWithPrinter(string filename, string printerName)
{
var procInfo = new ProcessStartInfo();
// the file name is a string of multiple filenames separated by space
procInfo.FileName = filename;
procInfo.Verb = "printto";
procInfo.WindowStyle = ProcessWindowStyle.Hidden;
procInfo.CreateNoWindow = true;
// select the printer
procInfo.Arguments = "\"" + printerName + "\"";
// doesn't work
//procInfo.Arguments = "\"" + printerName + "\"" + " " + filename;
Process p = new Process();
p.StartInfo = procInfo;
p.Start();
p.WaitForInputIdle();
//Thread.Sleep(3000;)
if (!p.CloseMainWindow()) p.Kill();
}
Following should work:
public void PrintFiles(string printerName, params string[] fileNames)
{
var files = String.Join(" ", fileNames);
var command = String.Format("/C print /D:{0} {1}", printerName, files);
var process = new Process();
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = command
};
process.StartInfo = startInfo;
process.Start();
}
//CALL
PrintFiles("YourPrinterName", "file1.pdf", "file2.pdf", "file3.pdf");
It's not necessarily a simple solution, but you could merge the pdfs first and then send then to acrobat.
For example, use PdfMerge
Example overload to your initial method:
public void printWithPrinter(string[] fileNames, string printerName)
{
var fileStreams = fileNames
.Select(fileName => (Stream)File.OpenRead(fileName)).ToList();
var bundleFileName = Path.GetTempPath();
try
{
try
{
var bundleBytes = new PdfMerge.PdfMerge().MergeFiles(fileStreams);
using (var bundleStream = File.OpenWrite(bundleFileName))
{
bundleStream.Write(bundleBytes, 0, bundleBytes.Length);
}
}
finally
{
fileStreams.ForEach(s => s.Dispose());
}
printWithPrinter(bundleFileName, printerName);
}
finally
{
if (File.Exists(bundleFileName))
File.Delete(bundleFileName);
}
}
I have an Asp.net Web forms application,when upload raw image file with format
{ "cr2", "raw", "dng", "nef", "raf", "orf", "srf", "sr2", "arw", "k25", "kdc", "dcr","mos",
"pnx", "crw", "mrw", "pef" , "mef" , "rw2","a7","a7r"}
How can i generate thumbnails from raw image?
You can use dcraw.exe application run on your .net application.you can download it in the link.
First save raw image in local disk and use the code:
string dcrawPath = "dcraw.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
string inputImagePath= "input Raw Image Path/";
string outputImagePath = "output Raw Image Path/";
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = dcrawPath;
string commandArg1 = string.Format("\"{0}\"", outputImagePath);
string commandArg2 = string.Format("\"{0}\"", inputImagePath);
startInfo.Arguments = "-u ";
startInfo.Arguments += commandArg1;
startInfo.Arguments += " -e ";
startInfo.Arguments += commandArg2;
startInfo.Arguments += " -T";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
string stdout = exeProcess.StandardOutput.ReadToEnd();
string stderr = exeProcess.StandardError.ReadToEnd();
Console.WriteLine("Exit code : {0}", exeProcess.ExitCode);
}
Put raw image in inputImagePath variable
You can find image in outputImagePath variable
Try GDPicture.NET component. It supports different RAW formats and easy for use, but is not free. To generate thumbnail use CreateThumbnail or CreateThumbnailHQ method of GdPictureImaging class:
using (var imaging = new GdPictureImaging())
{
int pictureId = imaging.CreateGdPictureImageFromFile(filepath);
if (pictureId == 0)
{
MessageBox.Show("Error: " + imaging.GetStat().ToString());
return;
}
int thumbnailImgId = imaging.CreateThumbnail(pictureId, 20, 20);
imaging.SaveAsPNG(thumbnailImgId, "thumbnail.png");
imaging.ReleaseGdPictureImage(thumbnailImgId);
imaging.ReleaseGdPictureImage(pictureId);
}
UPDATED...
I want to call kdiff from Console application. So I'm building two files and want to compare they at the end of executing my program:
string diffCmd = string.Format("{0} {1}", Logging.FileNames[0], Logging.FileNames[1]);
// diffCmd = D:\vdenisenko\DbHelper\DbHelper\bin\Debug\Reports\16_Nov 06_30_46_DiscussionThreads_ORIGIN.txt D:\vdenisenko\DbHelper\DbHelper\bin\Debug\Reports\16_Nov 06_30_46_DiscussionThreads_ORIGIN.txt
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\KDiff3\kdiff3.exe", diffCmd);
//specification is here http://kdiff3.sourceforge.net/doc/documentation.html
It runs kdiff3 tool, but something wrong with filenames or command... Could you please look on screenshot and say what is wrong?
You need to use Process.Start():
string kdiffPath = #"c:\Program Files\Kdiff3.exe"; // here is full path to kdiff utility
string fileName = #"d:\file1.txt";
string fileName2 = #"d:\file2.txt";
Process.Start(kdiffPath,String.Format("\"{0}\" \"{1}\"",fileName,fileName2));
Arguments as described in the docs: kdiff3 file1 file2
var args = String.Format("{0} {1}", fileName, fileName2);
Process.Start(kdiffPath, args);
string kdiffPath = #"c:\Program Files\Kdiff3.exe"; // here is full path to kdiff utility
string fileName = #"d:\file1.txt";
string fileName2 = #"d:\file2.txt";
ProcessStartInfo psi = new ProcessStartInfo(kdiffPath);
psi.RedirectStandardOutput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
psi.Arguments = fileName + " " + fileName2;
Process app = Process.Start(psi);
StreamReader reader = app.StandardOutput;
//get reponse from console app in your app
do
{
string line = reader.ReadLine();
}
while(!reader.EndOfStream);
app.WaitForExit();
This will run the program from your console app
Process p = new Process();
p.StartInfo.FileName = kdiffPath;
p.StartInfo.Arguments = "\"" + fileName + "\" \"" + fileName2 + "\"";
p.Start();
Unless you are trying to do something else, in which case you need to provide more details.