Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Asian Characters Not Printing in a pdf- Java(ADF)

917988Sep 16 2014 — edited Sep 26 2014

HI All,

IDE:- JDev7 (ADF Application)

API used for PDF creation- Itext

I am stuck in an issue where there is a requirement for me to Parse HTML text( Different Languages) and print the same in the pdf.

Right now when i am trying to print it, it is printing in ????....type. Pdf is being open using servlet as:-

        response.setHeader("Expires", "0");

        response.setHeader("Cache-Control",

                           "must-revalidate, post-check=0, pre-check=0");

        response.setHeader("Pragma", "public");

        response.setHeader("pageEncoding", "UTF-8");

        response.setContentType("application/pdf; charset=UTF-8");

        response.setCharacterEncoding("UTF-8");

        response.addHeader("Content-Disposition",

                           "inline;filename=Contract.pdf");

        Document document = new Document();

        PdfWriter pdfWriter;

        OutputStream out = null;

        InputStream in1=null;

        InputStream in2=null;

        try {

            out=response.getOutputStream();

            request.setCharacterEncoding("utf-8");

            try {

                if (null !=

                //Getting Language Here

                }

            } catch (Exception e) {

                log.info("Exception:" + e.toString());

            }

            log.info("PDF language:" + lang);

            HttpSession session = request.getSession(true);

           String title =

              //title

         String text =

               //Text  in html

   

       //Making it fully HTML compatible

            if (null != text && !text.equals("")) {

                text = text.replaceAll("<br>", "<br></br>");

                text = text.replaceAll("&", "&amp;");

            }

            if (null != title && !title.equals("")) {

                title = title.replaceAll("&", "&amp;");

            }

            StringBuffer sf = new StringBuffer();

            sf.append("<html><body>");

            if (null != title && title.length() > 0) {

                sf.append("<div style=\"color:#5482AB; text-align: center; font-size: 18px;\"><table><tr><td>" +

                          title + "</td></tr></table></div>");

            }

            sf.append("<div>"+text+"</div>");

            sf.append("</body></html>");

            log.info("fortest:::::::::::::::" + text);          

            pdfWriter = PdfWriter.getInstance(document, out);

            document.open();

            XMLWorkerHelper  worker =  XMLWorkerHelper.getInstance();

            in1=new ByteArrayInputStream(sf.toString().getBytes());

            in2=XMLWorkerHelper.class.getResourceAsStream("/default.css");

              worker.parseXHtml(pdfWriter, document,in1,in2, Charset.forName("UTF-8"), new ExternalFontFactory());

             document.close();

            log.info("PdfServlet call end...");

Kindly guide me for getting the correct format of Asian languages.

Regards

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2014
Added on Sep 16 2014
7 comments
1,905 views