首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GhostScript.net无法识别fileName中的特殊字符

GhostScript.net无法识别fileName中的特殊字符
EN

Stack Overflow用户
提问于 2019-07-08 14:08:37
回答 1查看 440关注 0票数 0
代码语言:javascript
复制
private static string[] GetArgs(string inputFile, string outputFile)
{
    return new[] {
    $"gs",
    $"-o",
    $"{outputFile}",
    $"-dNoOutputFonts",
    $"-sDEVICE=pdfwrite",
    $"{inputFile}",
 }; 


GhostscriptProcessor ghostscript = new GhostscriptProcessor();
string inputFile = "D:\\%1.pdf";
string outputFile = "D:\\%output.pdf";
ghostscript.Process(GetArgs(inputFile, outputFile));

there will be an error "An error occured when call to 

'gsapi_init_with_args‘制作:-100“

但如果将文件路径更改为fellows

string inputFile = "D:\%1.pdf";(包含%) string outputFile = "D:\output.pdf";(不包含%)

它起作用了,没问题

如果将文件路径更改为fellows

string inputFile = "D:\你.pdf";string outputFile = "D:\output.pdf";

inputFile="D:\你.pdf“"你”是汉字

这也不起作用。

而且我已经做了更多的测试,如果文件路径包含中文字符,则不起作用。

有谁能给点建议吗?非常感谢。

我做了一些更改,将fileName转换为UTF8作为研究员

新的utf8 = UTF8Encoding UTF8Encoding();

string inputFile = "D:\你.pdf";string outputFile = "D:\%91.pdf";

Byte[] inputFileEncodedBytes = utf8.GetBytes(inputFile);

Byte[] outPutFileEncodedBytes = utf8.GetBytes(outputFile);

string strInput =string

string =System.Text.Encoding.UTF8.GetString(outPutFileEncodedBytes);strOutPut字符串

ghostscript.Process(GetArgs(strInput,strOutPut ));

结果是一样的

EN

回答 1

Stack Overflow用户

发布于 2019-07-08 14:59:29

在文件名未表示为UTF-8的平台上,Ghostscript可执行文件(与Ghostscript.NET使用的DLL相反)将把文件名转换为UTF-8。例如,在Windows上,非拉丁文文件名采用宽字符格式,Ghostscript前端可执行文件会在将其传递给DLL之前将其转换为UTF-8。

DLL不会自行完成此操作。由调用者(在本例中是Ghostscript.NET或您的代码)负责确保传递给DLL的所有文件名都是UTF8格式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56929197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档