java - Cyrillic symbols -


i'm using itext7.
class works pdf files (it's template cyrillic symbols), on server.

first read document. second edit information , try save on local machine, have problem. new text not shown correctly.

if create new pdf file ttf fonts , add newly created pdf file, works fine, if modify template, text not correct (only cyrillic symbols).

i'm trying use 1 of simple examples official website - http://developers.itextpdf.com/examples/stamping-content-existing-pdfs/clone-replacing-pdf-objects

here relevant part of code:

pdfdocument document = new pdfdocument(new pdfreader(template), new pdfwriter(dest));         pdfpage page = document.getfirstpage();         pdfdictionary dictionary = page.getpdfobject();         pdfobject object = dictionary.get(pdfname.contents);          if (object instanceof pdfstream) {             pdfstream stream = (pdfstream) object;             byte[] data = stream.getbytes(true);              stream.setdata(new string(data).replace("user_fio", "Петров А.А.").getbytes("utf-8")); } document.close(); 

i'm trying use locales: http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html

but result "????? ?.?." or that.

what doing wrong? thank you!

pdf not wysiwyg format. can not hope replace information in content streams , have nice-looking pdf. there 2 reasons this

  1. pdf documents store information in objects. in order able reference objects byte-offset stored. if start replacing data, screwing internal table of byte-offsets.

  2. pdf documents not contain text such. should think of them more containers of instructions. changing order of instructions, or content of instructions not going result want.

    reflow (having text automatically laid out when text inserted, removed or replaced) can not done dynamically in document. when use code yours, (almost always) mess reflow.

    there exceptions. in 1 of examples on website, word "world" replaced "bruno". works because "world" , "bruno" have same number of letters (and same number of bytes), , in example mentioned, appear last word on respective line. reflow not problem there.

summary: - pdf not editable format!

if want similar usecase, consider following options:

  • generate pdf scratch every time
  • use forms (xfa or acro) have kind of field can accept dynamic content
  • convert html (dynamically generated) pdf using pdfhtml

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -