0

これが私のシナリオです。html ファイルを pdf に変換する実行可能ファイルがあります。この exe は、そのフォルダーから起動した場合にのみ機能します。例: exe は C:\HtmlToPdf にあるので、プロンプトで次のようにします。

C:\> cd HtmlToPdf
C:\HtmlToPdf> htmltopdf.exe htmlFile pdfFile

それで、C#でこれを行う方法はありますか? 私はこれを試したので:

FileInfo htmlInfo = new FileInfo(executablePath + @"\" + filename);
var procInfo = new ProcessStartInfo("wkhtmltopdf.exe",htmlInfo.FullName + " " + htmlInfo.FullName.Replace(".html",".pdf"));

procInfo.WorkingDirectory=executablePath;
procInfo.UseShellExecute = false;
Process.Start(procInfo);

しかし、うまくいきません。

4

2 に答える 2

3

wkhtmltopdf のドキュメンテーション/wikiには、フル パスを使用するとファイルを見つけるのに苦労すると記載されています。file:///ファイル名の先頭に追加する必要があります

Windows では、現時点では HTML ファイルのドライブに絶対パス名を使用できないことに注意してください。

wkhtmltopdf d:\temp\x.html x.pdf

失敗します。file:/// URL を使用する必要があります。

wkhtmltopdf ファイル:///d:/tmp/x.html x.pdf

この回答は、追加に役立つ場合があります

于 2013-08-07T07:11:14.923 に答える
0

EXE を呼び出している場所から .. .その Windows フォーム アプリケーションまたは Webforms....

If its windows forms it will work

else

if its Webforms like asp.net you have to change the properties of IIS Server to start the exe

Because due to some security reasons microsoft will not allow you to start the process class from IIS server... but the same code will work from Visualstudio ..

これが私のコードです

現在の実行可能ファイルのパスを取得するには

 string sCurrentPAth =  Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

  Process.Start(@"E:\Debug\MyExe.exe", "arg1 arg2 arg3");

その動作は正しく.....

于 2013-08-07T08:26:36.357 に答える