openhtmltopdf dont add fonts

322 Views Asked by At

I trying to add fonts to my pdf but without success, I using this code to generate

 public static void main(String[] args) throws Exception {
        try (OutputStream os = new FileOutputStream("/Users/fabio/Downloads/pdf/out2.pdf")) {
            PdfRendererBuilder builder = new PdfRendererBuilder();
            builder.useFastMode();
            Path fontDirectory = Paths.get("/Users/fabio/Downloads/Roboto/");

            // PERF: Should only be called once, as each font must be parsed for font family name.
            List<AutoFont.CSSFont> fonts = AutoFont.findFontsInDirectory(fontDirectory);

            // Use this in your template for the font-family property.
            String fontFamily = AutoFont.toCSSEscapedFontFamily(fonts);
            for (AutoFont.CSSFont font : fonts) {
                System.out.println(font.family);
            }
            // Add fonts to builder.
            AutoFont.toBuilder(builder, fonts);

            builder.withUri("file:/Users/fabio/Downloads/pdf/teste2.html");
            builder.toStream(os);
            builder.run();
        }
        Desktop desktop = Desktop.getDesktop();//checks file exists or not
            desktop.open(new File("/Users/fabio/Downloads/pdf/out2.pdf"));              //opens the specified file
    }

with this code to AutoFont AutoFont class

and this is my pdf without all fonts and the image thats show all fonts addedenter image description here enter image description here

0

There are 0 best solutions below