GithubHelp home page GithubHelp logo

Comments (5)

igorg1234 avatar igorg1234 commented on July 22, 2024 1

Here is tested solution. Works for me.

http://stackoverflow.com/questions/21251895/using-ghostscript-9-10-in-windows-with-unicode-characters-in-parameters

here is only explanation for 'gsapi_run_string'. -> change all strings under 'gsapi'.
The same approach works for string[] under 'gsapi_init_with_args'. -> use IntPtr[] for argv.

Instead calling 'gsapi_run_string' use 'call_gsapi_run_string(string str)' provided here.

// ====================================================

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate int gsapi_run_string(IntPtr instance, IntPtr str, Int32 user_errors, out Int32 pexit_code);

// ============================================

public int call_gsapi_run_string(IntPtr _gs_instance, string str, out int exit_code)
{
var pArg = StringHelper.NativeFromString(str);
int rc_run;
try
{
rc_run = gsapi_run_string(_gs_instance, pArg, 0, out exit_code);
}
finally
{
StringHelper.releaseManagedPointer(pArg);
}
return rc_run;
}

// ===========================================

public static IntPtr NativeUtf8FromString(string managedString)
{
  //var buffer = System.Text.Encoding.UTF8.GetBytes(managedString);
  int len = Encoding.UTF8.GetByteCount(managedString);
  byte[] buffer = new byte[len + 1];
  Encoding.UTF8.GetBytes(managedString, 0, managedString.Length, buffer, 0); 
  IntPtr nativeUtf8 = Marshal.AllocHGlobal(buffer.Length);
  Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length);
  return nativeUtf8;
}

// ===========================================

public static void releaseManagedPointer(IntPtr managedPointer)
{
    Marshal.FreeHGlobal(managedPointer);
}

// ===========================================

happy coding.

from ghostscript.net.

jhabjan avatar jhabjan commented on July 22, 2024

Hi,

In the subject you say "filename" and then later "title". Do you think it's the issue in the filename or pdf content?

What native Ghostscript library version do you use?
What Ghostscript.NET version do you use?
Can you post problematic PDF somewhere so I can see what's wrong?

from ghostscript.net.

yexcoffier avatar yexcoffier commented on July 22, 2024

Hi
Thank you for your answer.
I meant filename in both cases, sorry for the confusion.
I'm using the last version of ghostscript (9.15) in 32 bits version and the last version of Ghostscript.Net (1.1.9.0).

It's not a problematic pdf, if I change the filename by replacing the ê by e then it works whithout any issue. If I put a ê in the filename of any pdf then I have the issue.
It also crash with other special characters, not only ê.

It seems I'm not the only one, I've seen the same issue on codeplex : https://ghostscriptnet.codeplex.com/workitem/2266

from ghostscript.net.

yexcoffier avatar yexcoffier commented on July 22, 2024

I found a simple workaround for my issue. I copy the file in the user's temp folder with a random name and it works with any pdf (all the problematic ones I tried at least).

string pdfCopyPath = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf";
File.Copy(pdfPath, pdfCopyPath);

from ghostscript.net.

denis-ko avatar denis-ko commented on July 22, 2024

Still doesn't work (with the latest versions of gs and Ghostscript.NET)...

from ghostscript.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.