简体   繁体   中英

Merge fonts to generate multi locale PDF in Java

I am trying to generate PDF using iText for all locale. It's like PDF can have characters from any languages supported by noto sans and noto sans cjk. I do not know in advance which character may be used in PDF. Itext doesnot give any fallback as well. I decided to merge these two fonts in one. Is it possible?

Here is code snippet I am using to do all this:

  public static void generatePDF(String inputFileName, String fileName) throws FileNotFoundException {
        OutputStream os = null;
        try {
            File f = new File(fileName);
            os = new BufferedOutputStream(new FileOutputStream(f));
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(new File(inputFileName));
            renderer.layout();
            renderer.createPDF(os);
        } catch(Exception e){

        }finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
@font-face {
font-family: Noto Serif;
src: url("GoogleNotoSerif-Regular-V1-1.ttf");
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}

* {
    font-family: Noto Serif;
 }

In above code, I want to use font-family name as some common name and that file will be merged as a result of both fonts ie Noto Sans and Noto Sans CJK.

No, you can't merge noto and noto-cjk into a single font. The whole reason they're separate is that the full set of characters supported by both fonts is more than fits in a single font file (which have a hard limit of 65355 distinct shapes, which includes shapes used as compositional parts of other shapes).

(more details about that in this stackoverflow question )

Also, a PDF is not like a plain text file: PDF files are a markup format, where stretches of text explicitly say which font resource they are tied to. They are not "plain text and then the PDF reader picks whatever font would work for that", PDF are strictly typeset data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM