opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.21k stars 371 forks source link

Docx to PDF converter missing ☑ #327

Open darwin0616 opened 6 years ago

darwin0616 commented 6 years ago

Similar to issue #129, I reproduced the method,

XWPFDocument in = new XWPFDocument(instream);
OutputStream out = new FileOutputStream(file);
PdfOptions pdfOptions = PdfOptions.create();
pdfOptions.fontProvider(new IFontProvider() {

    @Override
    public Font getFont(String familyName, String encoding, float size, int style, Color color) {
    try {
        if (familyName.equalsIgnoreCase("Wingdings2")) {
            BaseFont baseFont =
                    BaseFont.createFont(fontLibrary + "wingdings2.ttf", encoding, BaseFont.EMBEDDED);
            return new Font(baseFont, size, style, color);

        } 
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return PdfOptions.create().getFontProvider().getFont(familyName, encoding, size, style, color);
    }
});

PdfConverter.getInstance().convert(in, out, pdfOptions);

unfortunately, ☑ and ☐ are missing in PDF file. I try to print "familyName", but there is no "wingdings 2" or "wingdings2" !

In order to check my docx file, I convert my docx file to xml, and then <w:sym w:font="Wingdings 2 w:char="F052"/> ... <w:sym w:font="Wingdings 2 w:char="F0A3"/> ... exist in the xml file.

Please, I need some help! Thank you!

rahulahoop commented 4 years ago

Damn Im having the same issue! I thought to try and change the encoding but the best i can get is a "?"

        PdfOptions options = PdfOptions.create();
        options.fontProvider(new IFontProvider()
        { // ensure font
            @Override
            public Font getFont(String s, String s1, float v, int i, Color color)
            {
                return FontFactory.getFont(FontFactory.TIMES, "windows-1252", v, i ,color);
            }
        });

        PdfConverter.getInstance().convert(xwpfDocument, baos, options);
freeRita commented 4 years ago

I found a temporary solution to the problem. To manually replace the

<w:sym w:font="Wingdings 2 w:char="F052"/>

to

<w:r>
    <w:rPr>
        <w:rFonts w:ascii="Wingdings 2" w:hAnsi="Wingdings 2"/>
    </w:rPr>
    <w:t>R</w:t>
</w:r>

or just print "R" in Office Word with "Wingdings 2" font.