Lucee Flying Saucer PDF Engine not support chinese ttf

  • lucee extension-pdf use api addFontDirectory
  • resolver.addFontDirectory(fontDirectory.getCanonicalPath(), fontembed);
    
  • @Override
  • public byte[] _render(Dimension dimension, double unitFactor, PageContext pc, boolean generategenerateOutlines) throws PageException, IOException, DocumentException {
  • ITextRenderer renderer = new ITextRenderer();
  • // prepare(fontDirectory, "fs.properties");
  • // fonts
  • ITextFontResolver resolver = renderer.getFontResolver();
  • resolver.addFontDirectory(fontDirectory.getCanonicalPath(), fontembed);
  • // margin
  • double mt = margintop;
  • if (mt <= 0D) mt = getHeader() != null ? MARGIN_WITH_HF : MARGIN_INIT;
  • double mb = marginbottom;
  • if (mb <= 0D) mb = getFooter() != null ? MARGIN_WITH_HF : MARGIN_INIT;
  • Margin margin = new Margin(this, unitFactor, margintop, marginbottom, marginleft, marginright);
  • if ((margin.getLeftAsPoint() + margin.getRightAsPoint()) > dimension.getWidth()) throw engine.getExceptionUtil().createApplicationException(
  • 2.flyingsaucer ITextFontResolver.java addFontDirectory call addFont by 2 argument String ,boolean

    for (int i = 0; i < files.length; i++) {
           addFont(files[i].getAbsolutePath(), embedded);
              
  • File f = new File(dir);
  • if (f.isDirectory()) {
  • File[] files = f.listFiles(new FilenameFilter() {
  • public boolean accept(File dir, String name) {
  • String lower = name.toLowerCase();
  • return lower.endsWith(".otf") || lower.endsWith(".ttf");
  • for (int i = 0; i < files.length; i++) {
  • addFont(files[i].getAbsolutePath(), embedded);
  • public void addFont(String path, boolean embedded)
  • throws DocumentException, IOException {
  • addFont(path, BaseFont.CP1252, embedded);
  • public void addFont(String path, String encoding, boolean embedded)
  • 3.flyingsaucer ITextFontResolver.java addFont with 2 argument will use BaseFont.CP1252

    public void addFont(String path, boolean embedded)
                throws DocumentException, IOException {
            addFont(path, BaseFont.CP1252, embedded);
    
  • public void addFont(String path, boolean embedded)
  • throws DocumentException, IOException {
  • addFont(path, BaseFont.CP1252, embedded);
  • public void addFont(String path, String encoding, boolean embedded)
  • throws DocumentException, IOException {
  • addFont(path, encoding, embedded, null);
  • public void addFont(String path, String encoding, boolean embedded, String pathToPFB)
  • throws DocumentException, IOException {
  • addFont(path, null, encoding, embedded, pathToPFB);
  • should be solve by 3 argument

    fontResolver.addFont(files[i].getAbsolutePath(), BaseFont.IDENTITY_H, embedded);
    

    Don’t forget to tell us about your stack!

    OS: window 10
    Java Version: 11.0.11 (AdoptOpenJDK) 64bit
    Tomcat Version: WildFly / Undertow - 2.2.3.Final
    Lucee Version: Lucee 5.3.9.44-SNAPSHOT

    Have you tried to install all the correct fonts first to the OS, then to the java.properties of the Java runtime environment?

    On Windows, install the correct fonts in the Winroot/fonts
    Restart the system

    Next heck the environment path, make sure that your java runtime font.properties has the correct font mappings.

    On windows systems, make sure you have installed additional keyboard layouts for the languages you are having issues with, even if you do not use those languages for the UI.

    After you place the fonts in the correct location restart your lucee /tomcat instance
    then try again.

    I am a newbie in lucee ,i don’t understand about lucee extension.
    I create a sample code with index.cfm use createObject(“java”)
    The org.lucee.flyingSaucerPDF-9.1.20.jar copy from lucee extension
    use addFont method MingLiU-01.ttf can work

    https://github.com/gaias-jyh/lucee-flyingSaucerPDF/blob/main/index.cfm#L19

    https://github.com/gaias-jyh/lucee-flyingSaucerPDF

    When using chinese TTF file in classic mode, you have to write pd4fonts.properties for PD4ML .

    PD4ML or Lucee dont read Windows font directory.
    cfdocument description in fontdirectory

    But cfdocument is using “modern” by defaults Flying Saucer PDF Engine

    <cfdocument format="PDF" type="classic" fontdirectory="D:\fonts">
    

    i try chinese TTF with pd4fonts.properties file can be work

    https://luceeserver.atlassian.net/browse/LDEV-3836

    Add the jira ticket on gaia-jyh’s behalf.

    Owning to my poor knowledge about Java, I’m not able to continue with the PR. Sorry.