Please note:
The generated PDF requires PDF viewer with Asian Font Pack installed.
Example_04.pdfimport java.io.*; import com.pdfjet.*; /** * Example_04.java * * The PDF generated by this example program will only work with * Adobe Reader 8 or Foxit Reader v2.0 or higher versions. It also * requires the Asian Font Packs from Adobe or Foxit Software respectively. */ public class Example_04 { public Example_04() throws Exception { String fileName = "data/happy-new-year.txt"; FileOutputStream fos = new FileOutputStream("Example_04.pdf"); PDF pdf = new PDF(fos); Font f1 = new Font( pdf, "AdobeMingStd-Light", // Chinese (Traditional) font CodePage.UNICODE); Font f2 = new Font( pdf, "STHeitiSC-Light", // Chinese (Simplified) font CodePage.UNICODE); Font f3 = new Font( pdf, "KozMinProVI-Regular", // Japanese font CodePage.UNICODE); Font f4 = new Font( pdf, "AdobeMyungjoStd-Medium", // Korean font CodePage.UNICODE); Page page = new Page(pdf, Letter.PORTRAIT); f1.setSize(14); f2.setSize(14); f3.setSize(14); f4.setSize(14); float x_pos = 100.0f; float y_pos = 20.0f; BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(fileName), "UTF-8")); TextLine text = new TextLine(f1); String line = null; while ((line = reader.readLine()) != null) { if (line.indexOf("Simplified") != -1) { text.setFont(f2); } else if (line.indexOf("Japanese") != -1) { text.setFont(f3); } else if (line.indexOf("Korean") != -1) { text.setFont(f4); } text.setText(line); text.setPosition(x_pos, y_pos += 24); text.drawOn(page); } reader.close(); pdf.flush(); fos.close(); } public static void main(String[] args) { try { new Example_04(); } catch (Exception e) { e.printStackTrace(); } } } // End of Example_04.java
© 2019 Innovatics Inc.