0
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' is made: -100"

but if change the file Path as fellows

string inputFile = "D:\%1.pdf"; (contains %) string outputFile = "D:\output.pdf"; (not contains %)

it works ,no Problem

and if change the file Path as fellows

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

the inputFile="D:\你.pdf" "你" is chinese character

this also not work

and i have do more test, if the file Path Contains chinese character ,not works.

anybody can give some advise?thanks a lot .

i do some changes to convert the fileName to UTF8 as fellows

UTF8Encoding utf8 = new UTF8Encoding();

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

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

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

string strInput = System.Text.Encoding.UTF8.GetString(inputFileEncodedBytes);
string strOutPut =System.Text.Encoding.UTF8.GetString(outPutFileEncodedBytes);

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

the result is the same

steive
  • 11
  • 5

1 Answers1

0

The Ghostscript executable (as opposed to the DLL which is used by Ghostscript.NET) will, on platforms where the filename is not expressed as UTF-8, convert the filename to UTF-8. For example, on Windows non-Latin filenames are in Wide Character format, and the Ghostscript front-end executable will convert these to UTF-8 before passing them to the DLL.

The DLL will not do this on its own. Its up to the caller (either Ghostscript.NET or your code in this case) to ensure that any filenames passed to the DLL are in UTF-8 form.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • thanks Kens, i do some changes like this UTF8Encoding utf8 = new UTF8Encoding(); string inputFile = "D:\\你.pdf"; string outputFile = "D:\\%91.pdf"; Byte[] inputFileEncodedBytes = utf8.GetBytes(inputFile); Byte[] outPutFileEncodedBytes = utf8.GetBytes(outputFile); string strInput = System.Text.Encoding.UTF8.GetString(inputFileEncodedBytes); string strOutPut =System.Text.Encoding.UTF8.GetString(outPutFileEncodedBytes); but the result is the same ,not working – steive Jul 08 '19 at 14:46
  • I can't really help you much further, I don't code in C# or .NET so your code is, I'm afraid, meaningless to me. However, using an online UTF-8 converter it suggests that 你 should be converted to 0xe4 0xbd 0xa0. So '%91' doesn't sound right to me at all. You can (or should be able to) prove that the Ghostscript executable works by running gswin64c from the command shell with the relevant arguments. – KenS Jul 08 '19 at 15:33