【发布时间】:2023-03-09 11:47:01
【问题描述】:
伙计们!
所以,正如标题所示,我正在尝试将 PDF 转换为 .png。我正在使用软件包 ImageMagick。我想使用这个包从 Unity 3d 项目中即时将 pdf 转换为 png - 以便应用程序可以在需要时在游戏中将 PDF 显示为 .png 纹理,但仍将它们保留为较小的 PDF文件大小。我不太确定我做错了什么,在这里 - 但是当我在 Unity 中运行它时,我得到的只是一个打开的 cmd 提示符,其中没有我的命令。这里有什么明显的我遗漏的东西吗?代码如下:
using UnityEngine;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Security.Policy;
public class CommandLineTest : MonoBehaviour {
// Use this for initialization
void Start () {
string convertedDirName = "ConvertedPDFs";
string currDir = System.Environment.CurrentDirectory;
System.IO.Directory.CreateDirectory(currDir + @"\" + convertedDirName);
string strCmdText;
strCmdText= @"/c " + currDir + @"\ImageMagick\convert.exe " + currDir + @"\PDFs\Appointment.pdf " + currDir + @"\" + convertedDirName + @"\" + "Appointment.png";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
//ImageMagick
print(strCmdText);
}
}
当最后的打印语句运行时,它会打印以下字符串: c/ convert /c F:\Documents and Settings\Administrator\Desktop\ImageMagickTest\ImageMagick\convert.exe F:\Documents and Settings\Administrator\ Desktop\ImageMagickTest\PDFs\Appointment.pdf F:\Documents and Settings\Administrator\Desktop\ImageMagickTest\ConvertedPDFs\Appointment.png
对你来说,有什么明显的错误吗?我应该提一下,ImageMagick 的转换应用程序实际上并没有“安装”在我的系统上——我只是使用“便携式”版本并将它扔到我的项目文件夹中。所以我希望“转换”命令行仍然有效。这是否意味着我无法使用 dos 提示符访问它?如果我不能,那么如果我知道它将在我的项目文件夹中,我如何将图像传递给 imagemagick 中的“转换”程序?
编辑:有些人建议我访问 convert.exe 而不是 cmd.exe,并尝试以这种方式将图像路径提供给它。所以这是我尝试的第二种方式:
strCmdText= currDir + @"\PDFs\Appointment.pdf" + " " + currDir + @"\" + convertedDirName + @"\" + "Appointment.png";
System.Diagnostics.Process.Start(currDir + @"\ImageMagick\convert.exe",strCmdText);
【问题讨论】:
-
路径周围可能缺少引号 ',因为它们似乎有一个或多个空格。
-
嘿 Oli,我很欣赏这个想法,但我认为报价情况还可以......如果有什么问题,打印声明不会显示吗?干杯。
标签: windows shell imagemagick cmd