如何在asp.net应用程序中使用qpdf设置线性化的PDF(web快速视图属性)



QPDF可以将pdf转换为线性化的pdf(web快速视图属性(。我可以使用命令行:qpdf—linearize input.pdf output.pdf将pdf转换为线性化的pdf。

我如何在asp.net程序上使用它?

我的代码就像

private void LaunchCommandLineApp()
{
// For the example
string ex4 = @"C:Program Filesqpdf-7.0.b1binqpdf.exe";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = ex4;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = " --linearize input.pdf output.pdf";
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
if (exeProcess != null)
{
string op = exeProcess.StandardOutput.ReadToEnd();
exeProcess.WaitForExit();
Console.WriteLine(op);
}
}
}
catch (Exception ex)
{
// Log error.
}
}

有没有其他解决方案可以在asp.net中使用Qpdf?非常感谢!

最后,我使用qpdf.exe使其按以下代码工作。

private void RunQpdfExe(string output)
{
string QPDFPath = @"C:Program Filesqpdf-5.1.2bin";
string newfile = ExportFilePath + "Lin.pdf";
try
{
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.FileName = QPDFPath + "qpdf.exe";
startInfo.Verb = "runas";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.Arguments = " --check " + output;
startInfo.WorkingDirectory = Path.GetDirectoryName(QPDFPath);
startInfo.Arguments = " --linearize " + output + " " + newfile;
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
if (exeProcess != null)
{
string op = exeProcess.StandardOutput.ReadToEnd();
exeProcess.WaitForExit();
}
}
//Rename the output file back
File.Delete(output);
File.Copy(newfile, output);
File.Delete(newfile);
}
catch (Exception)
{
// Log error.
}
}

此外,我还在输出文件夹中为asp.net用户角色添加了"写入"权限。希望能有所帮助。

最新更新