the outcome is gibrish.
see attachment.
i added also a snapshot for the source txt file.
the outcome is gibrish.
Hi Eran,
Thanks for your inquiry. I have tested the scenario using Aspose.Pdf for Java 10.4.0 with the following code snippet and I am unable to notice the issue. Please download the latest version of Aspose.Pdf for Java and try the following code, it will resolve the issue.
// Source PDF file
java.io.File file = new java.io.File(myDir + "11+TXT_HebUTF8.txt");
java.io.FileInputStream fis = new java.io.FileInputStream(file);
java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
// doc.save(myDir+"11+TXT_HebUTF8.pdf"); }
System.out.println("read " + readNum + " bytes,");
}
} catch (java.io.IOException ex) {
}
byte[] bytes = bos.toByteArray();
String textFromFile = new String(bytes, "UTF-8");
// Instantiate a Document object by calling its empty constructor
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// Add a new page in Pages collection of Document
Page page = doc.getPages().add();
// Create an instance of TextFragment and pass the text from reader object to its constructor as argument
com.aspose.pdf.TextFragment text=new TextFragment();
text.getTextState().setFont(FontRepository.findFont("Arial Unicode MS"));
text.setText(textFromFile);
// Add a new text paragraph in paragraphs collection and pass the TextFragment object
page.getParagraphs().add(text);
// Save resultant PDF file
doc.save(MyDir + "11+TXT_HebUTF8.pdf");
Please feel free to contact us for any further assistance.
Best Regards,