Free Support Forum - aspose.com

PDF Encoding

Hi,
I try to read a UTF-8 file with Khmer characters and try to out it as a PDF using Aspose PDF. However, the output PDF is blank. May I know is Aspose support Khmer character ? The following is my code:

import java.io.File;
import java.nio.charset.Charset;
import aspose.pdf.*;
import org.apache.commons.io.FileUtils;

public class AsposePdf {

public static void main(String[] args) throws Exception {
new AsposePdf().createPdf();
}

public void createPdf() throws Exception {
// Instantiate Pdf object by calling its empty constructor
Pdf pdf = new Pdf();

// Create a new section in the Pdf object
Section sec = pdf.getSections().add();

final String hello = FileUtils.readFileToString(new File(“hello.txt”), Charset.forName(“UTF-8”));

// Create a new text paragraph and pass the text to its constructor as argument
Text text = new Text(sec, hello);

text.getTextInfo().setFontName(“Arial Unicode MS”);

sec.getParagraphs().add(text);

pdf.setUnicode();
pdf.save(“hello.pdf”);
}
}

Regards,
Cheong

Hi Cheong,


Thanks for your inquiry. Normally, when using Non-English text, you need to use the font that supports Non-English characters. Please share your sample source document. We will test the scenario and will provide you more information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi, thanks for the prompt reply. I’ve enclosed the source document, it’s UTF-8 encoded, hope to hear from you soon. Thanks

Best Regards,
Cheong

Hi Cheong,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for Java 9.0.0, We have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWJAVA-34132 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Cheong,


Thanks for your patience. We have further investigated the issue and would like to suggest you to use font that support Khmer characters e.g. khmerOS.ttf

String inputPath=myDir+“khmer.txt”;<o:p></o:p>

String outputPath=myDir+"TexttoPDF_java_1030.pdf";

StringBuffer sb = new StringBuffer(1024);

BufferedReader reader = new BufferedReader(new FileReader(inputPath));

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

doc.getPages().add();

//char[] chars = new char[1024];

String line = null;

ArrayList list = new ArrayList();

while( (line = reader.readLine()) != null)

{

// com.aspose.pdf.TextFragment text_fragment = new com.aspose.pdf.TextFragment("ជំរាបសួរកម្ពុជា!");

com.aspose.pdf.TextFragment text_fragment = new com.aspose.pdf.TextFragment();

text_fragment.getTextState().setFont(FontRepository.openFont(myDir+"../khmerOS.ttf"));

text_fragment.setText("ជំរាបសួរកម្ពុជា!");

list.add(text_fragment);

}

reader.close();

double y = list.size() * 14;

for(Object item : list)

{

((com.aspose.pdf.TextFragment) item).setPosition(new Position(0, y));

y -= 14;

}

com.aspose.pdf.TextBuilder textBuilder = new com.aspose.pdf.TextBuilder(doc.getPages().get_Item(1));

for(Object item : list)

{

textBuilder.appendText(((com.aspose.pdf.TextFragment) item));

}

doc.save(outputPath);


Please feel free to contact us for any further assistance.

Best Regards,

Hi

I am trying to test this example, and it does not work. All I get is ??? in the pdf.

I have downloaded and installed aspose-pdf-10.4.0-java
The path to the font is correct

Do I need to install something else as well?
Thanks

pdfpoc:
Hi

I am trying to test this example, and it does not work. All I get is ??? in the pdf.

I have downloaded and installed aspose-pdf-10.4.0-java
The path to the font is correct

Do I need to install something else as well?
Thanks
Hi Latika,

Thanks for using our API’s.

Can you please share your input PDF and resource font files you are using, so that we can test the scenario at our end. We are sorry for this inconvenience.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan