RubyPDF Blog English,iText,Open Source,PDF,tutorial A easy way to let application compiled by gcj support Chinese path

A easy way to let application compiled by gcj support Chinese path

I have developed some java program and compiled with GCJ, feel free to visit
download center
but they does not support Chinese path now.

pdftk is a very famous software, developed in java and compiled with GCJ, does not support Chinese path,
of course I have release a modified version that supports Chinese path.

so how to let it support Chinese(Japanese, Korean) path? the answer is CNI(the Compiled Native Interface) can help you, and the related source code is

static int writeFile (java::ByteArrayOutputStream* ofs_p, const char* fileName)

FILE * pFile;
long lSize;
char* buffer = (char*) malloc (sizeof(char)*lSize);
jbyteArray out_pdf=ofs_p->toByteArray();
//ofs_p->write(out_pdf, 0, (jint)lSize);

lSize );

pFile = fopen ( fileName , "wb" );
fwrite (buffer , sizeof(buffer[0]) , lSize , pFile );
fclose (pFile);
return 0;

static jbyteArray readFile(const char* fileName)
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen (fileName , "rb" );
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

// obtain file size:
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);

// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
//printf ("%d",lSize);

// copy the file into the buffer:
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}

jbyteArray in_pdf= JvNewByteArray(lSize);
memcpy( (char*)(elements(in_pdf)),
lSize );

/* the whole file is now loaded in the memory buffer. */

// terminate
fclose (pFile);
free (buffer);
return in_pdf;

Related Resource

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.