0

I want to merge two PDF files but when the input filename has some special characters such as ª or º etc., it fails to merge. With an input filename like MªRose.pdf.

try
    SetLength(Arg, 7);
    Arg[0] := PAnsiChar('-q');
    Arg[1] := PAnsiChar('-dSAFER');
    Arg[2] := PAnsiChar('-dNOPAUSE');
    Arg[3] := PAnsiChar('-dBATCH');
    Arg[4] := PAnsiChar('-sOutputFile=' + output + '.pdf');
    Arg[5] := PAnsiChar('-sDEVICE=ps2write');
    Arg[6] := PAnsiChar(input);

    ExitCode := gsapi_init_with_args(instance, Length(Arg), @Arg[0]);

    if ExitCode < 0 
       then raise Exception.Create('ERROR: init_args: '+IntToStr(ExitCode));

    gsapi_exit(instance);
finally
    gsapi_delete_instance(instance);
end;

Can someone provide a solution?

3
  • Ghostscript is known to work with filenames using non-ASCII languages, for example Chinese. Try executing your configuration from the command shell, I expect it will work. That should demonstrate to you that the problem is your Delph interface to the Ghostscript library. I suspect that you need to convert the filenames to UTF-8 if you are going to use the API instead of the command shell. Commented Jan 21 at 9:10
  • Is Google sheets not really involve in your situation? Commented Jan 21 at 13:24
  • 2
    Read Using GhostScript 9.10 in Windows with Unicode characters in parameters or the docs: Both will tell you to first call gsapi_set_arg_encoding( instance, GS_ARG_ENCODING_UTF8 ); and then to use UTF-8 AnsiStrings. Oh, and Arg[0] is always ignored. Commented Jan 21 at 15:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.