farrukh.najm Posted December 27, 2016 Share Posted December 27, 2016 I am migrating some legacy JasperReports client code from Jasper 3.7 to Jasper 6.3. The code uses PdfFont class to do font mapping when exporting report to PDF. The font mapping API in Jasper 6.3 seems to have changed a lot from 3.7 and I cannot find any examples of how to replace code to match new API. The current code looks like this: String jasperTemplateFileName = ....; JasperPrint jp = JasperFillManager.fillReport( jasperTemplateFileName, _jasperParams ); File generatedPDFFile = ...; String outputFileName = generatedPDFFile.getAbsolutePath(); JRExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, outputFileName); //Do font mapping. This is where I am having trouble HashMap fontMap = new HashMap(); PdfFont boldPdfFont = new PdfFont(REPORT_FONTS_PATH + "arialbd.ttf", "Cp1252", true); FontKey fontKey = new FontKey("SansSerif",true,false); fontMap.put(fKey, boldPdfFont); exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap); exporter.exportReport();[/code] There is no PdfFont class in Jasper 6.3 and the replacement code is not obvious to me. Here is what I have so far: Exporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput(jp)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFileName)); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setPermissions(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); //How to do font mapping here?? exporter.exportReport();[/code] TIA for any guidance. Link to comment Share on other sites More sharing options...
hozawa Posted December 28, 2016 Share Posted December 28, 2016 JasperReports 6.x will use the font specified in the font name as the pdf font so there's no more need to specify pdffont. Just remove all the pdffont statements and it'll be alright. Link to comment Share on other sites More sharing options...
farrukh.najm Posted December 29, 2016 Author Share Posted December 29, 2016 @hozawa Thanks for your help. Can you be more specific as to what the code would look like if I want to set default font for normal, bold, italic, boldItalic font face and sepcifu pdf Encoding and whether the font is embedded or not for my entire report. I created a FontFamily using code below but then I do not know how to set this as the default for my entire PDF report:SimpleFontFamily fontFamily = new SimpleFontFamily(); fontFamily.supportsLocale(reportLocale);fontFamily.setPdfEmbedded(Boolean.TRUE); SimpleFontFace fontFace = new SimpleFontFace(_reportContext); fontFace.setTtf(REPORT_FONTS_PATH + "arial.ttf"); fontFamily.setNormalFace(fontFace); fontFace = new SimpleFontFace(_reportContext); fontFace.setTtf(REPORT_FONTS_PATH + "arialbd.ttf"); fontFamily.setBoldFace(fontFace); fontFace = new SimpleFontFace(_reportContext); fontFace.setTtf(REPORT_FONTS_PATH + "ariali.ttf"); fontFamily.setItalicFace(fontFace); fontFace = new SimpleFontFace(_reportContext); fontFace.setTtf(REPORT_FONTS_PATH + "arialbi.ttf"); fontFamily.setPdfEncoding("Cp1252");At this point I have a FontFamily all good to go but how to I set this for my entire report as default? How can I pass this FontFamily to my JRPdfExporter? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now