xdev-software / vaadin-grid-exporter

Makes it possible to export Vaadin Grids to different formats
Apache License 2.0
23 stars 2 forks source link

PDF Export encoding #237

Closed nero404 closed 2 months ago

nero404 commented 2 months ago

Checklist

What is/are your question(s)?

Is there a simple way to change the encoding format in PDF export? Adding EncodingConfigComponent to PdfFormat does not work.

Thanks for the answer.

Additional information

No response

AB-xdev commented 2 months ago

Currently there is no built-in way to do this as we never had this situation before.

AFAIK PDFs have no classic "encoding" as have text files: https://stackoverflow.com/a/42118616

According to the PDF spec there can be certain string encodings.

In JasperReports you can do it like this, but it's recommended to use Fonts with the correct encoding instead.

nero404 commented 2 months ago

Thank you very much. The problem solved by overriding the property values.

@Configuration
public class JasperReportsConfig {

    @Bean
    public JasperReportsContext jasperReportsContext() {
        JasperReportsContext jasperReportsContext = DefaultJasperReportsContext.getInstance();

        JRPropertiesUtil.getInstance(jasperReportsContext).setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
        JRPropertiesUtil.getInstance(jasperReportsContext).setProperty("net.sf.jasperreports.default.pdf.font.name", "fonts/arial.ttf");

        return jasperReportsContext;
    }
}