GeertPoels Posted July 4, 2007 Share Posted July 4, 2007 Hello, In the design of my report, a certain textfield should be capable of being filled with a string of variable length.So the text can easily surpass the original width.To enable this, I've allowed the textfield to 'stretch with overflow'. This works fine, except that the text is not cut at the end but at a space character somewhere in the text. This is logical for most texts.In our case, it is critical that the text is cut instead of logically split at a space.How to force this ? Geert Link to comment Share on other sites More sharing options...
lucianc Posted July 4, 2007 Share Posted July 4, 2007 This is not directly supported by JasperReports. One way to achieve this is to process your text and insert a zero-width space ( Unicode 200B ) after each character. This way your text will be able to break after each character. You could also post a feature request if you think such a functionality should be present in JasperReports. Regards,LucianPost edited by: lucianc, at: 2007/07/04 15:33 Link to comment Share on other sites More sharing options...
GeertPoels Posted July 5, 2007 Author Share Posted July 5, 2007 Thanks Lucian.I will try this.However this approach will significatly increase the processing time. :unsure: I'll report the enhancement ! Link to comment Share on other sites More sharing options...
GeertPoels Posted July 5, 2007 Author Share Posted July 5, 2007 Enhancement request :http://jasperforge.org/sf/go/artf2340?nav=1 Link to comment Share on other sites More sharing options...
GeertPoels Posted July 5, 2007 Author Share Posted July 5, 2007 Hi Lucian, I just 'enriched' the texts in question with both a zero-width space and its non breakable counterpart.http://www.fileformat.info/info/unicode/char/feff/index.htmhttp://www.fileformat.info/info/unicode/char/200b/index.htm Yet neither gave the result I hoped for.The text is cut at a hyphen sign... . Do you have other ideas ? Thanks already, Geert Link to comment Share on other sites More sharing options...
lucianc Posted July 5, 2007 Share Posted July 5, 2007 Using non-breakable spaces is a rather surprising idea, since the goal is to allow the text to be broken. I'm attaching a report that illustrates my suggestion (if you care about the performance use a direct algorithm in place of the regex replacement). Run it and see whether the result is as expected. Btw, which output format are you after? Regards,Lucian [file name=break.jrxml size=1002]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/break.jrxml[/file] Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 The results are kinda unexpected.In the PDF, the text still is splitted.In the RTF, the text isn't splitted. Yet the special characters causes weird output in Word. [file name=example.pdf size=1308]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/example.pdf[/file] Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 This is the RTF [file name=example.zip size=614]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/example.zip[/file] Post edited by: GeertPoels, at: 2007/07/06 06:37 Link to comment Share on other sites More sharing options...
lucianc Posted July 6, 2007 Share Posted July 6, 2007 I've changed the RTF exporter to convert Unicode 200B chars to RTF zwbo (zero-width break opportunity - "Used to insert break opportunity between two characters" according to the RTF spec) control words. Does the attached RTF show fine in MS Word? [file name=break.zip size=602]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/break.zip[/file]Post edited by: lucianc, at: 2007/07/06 10:13 Link to comment Share on other sites More sharing options...
lucianc Posted July 6, 2007 Share Posted July 6, 2007 Regarding PDF: which JR/iText versions are you using? The PDF produced here look fine (see attached). [file name=break_0_0.pdf size=1344]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/break_0_0.pdf[/file] Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 This is how Word shows your latest RTF.The output is still 'scrambled'. size=352]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/rtf_in_word.jpgPost edited by: GeertPoels, at: 2007/07/06 10:41 Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 Wow ! Indeed your PDF looks splendid. I use the latest Jasper version.This is my code : OutputStream output = null; try { output = new FileOutputStream(pdf); JasperExportManager.exportReportToPdfStream(print, output); } finally { if (output != null) { try { output.close(); } catch (IOException e) { log.error(e); } } } Link to comment Share on other sites More sharing options...
lucianc Posted July 6, 2007 Share Posted July 6, 2007 RTF: I'm left clueless. If the RTF zwbo control word does not work, I don't know what would. I think Word has an option of showing otherwise "non-visible" characters as spaces/newlines/etc and it seems that you have it enabled. Could you try to disable it? PDF: We need to identify what differs between the two environments. Which iText version are you using (i.e. what iText jar do you have on your classpath)? Also, what Java/JRE are you using (probably doesn't affect the PDF output, but it doesn't hurt knowing)? Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 Good news : RTF was indeed because of the non-visible chars. Output is excellent. PDF: I had an older version of iText : 1.4.7, now 2.0.4.Yet, I redid your test with the new iText and the output is the same. [file name=newITEXT.pdf size=1320]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/newITEXT.pdf[/file] My JDK is 1.5.07.Post edited by: GeertPoels, at: 2007/07/06 12:11 Link to comment Share on other sites More sharing options...
GeertPoels Posted July 6, 2007 Author Share Posted July 6, 2007 Here is your compiled jasper report. [file name=break-c57af771c3cbfd087d48d443f6bce499.zip size=4500]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/break-c57af771c3cbfd087d48d443f6bce499.zip[/file] Link to comment Share on other sites More sharing options...
lucianc Posted July 6, 2007 Share Posted July 6, 2007 Sorry, it was not the iText version (my bad). The PDF output is fine once you set the "force line break policy" flag when exporting. You can either set this flag per export using the JRPdfExporterParameter.FORCE_LINEBREAK_POLICY parameter or globally by setting the net.sf.jasperreports.export.pdf.force.linebreak.policy property (in jasperreports.properties). Regards,Lucian Link to comment Share on other sites More sharing options...
GeertPoels Posted July 7, 2007 Author Share Posted July 7, 2007 Hi Lucian, To enable this parameter programmatically. Do I put it in my parameters to the fillReport function ?like : param.put(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, true);JasperPrint print = JasperFillManager.fillReport(report, param, source); Geert Link to comment Share on other sites More sharing options...
lucianc Posted July 9, 2007 Share Posted July 9, 2007 No, this is an export parameter so you need to set it when exporting to PDF:Code:JRPdfExporter exporter = new JRPdfExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);exporter.exportReport(); Regards,Lucian Link to comment Share on other sites More sharing options...
GeertPoels Posted July 9, 2007 Author Share Posted July 9, 2007 This works.Thanks for your patience ! :) Link to comment Share on other sites More sharing options...
imclive Posted June 24, 2008 Share Posted June 24, 2008 one row disappear when page brake (not always).. even though set FORCE_LINEBREAK_POLICY to TRUE.. I don't know how to avoid it.. Link to comment Share on other sites More sharing options...
flacap Posted August 11, 2009 Share Posted August 11, 2009 Hi all,I am new in the forum. I have the following problem:I am using iReport 3.0.0 and jasper reports 2.0.5. I have a report that has several columns and one column has a large content. The content is cut in the last lines. The column has font name “SansSerif” and pdf font name “Helvetica”.I prove putting the FORCE_LINEBREAK_POLICY and the FONT_MAP parameters as following but it didn’t work:Does anyone know what it could be happening?Thanks in advance!!Code:exporter.setParameter(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, Boolean.TRUE);FontKey keyHelvetica = new FontKey("SansSerif", false, false);PdfFont fontHelvetica = new PdfFont("Helvetica", "Cp1252", false);FontKey keyHelveticaBold = new FontKey("SansSerif", true, false);PdfFont fontHelveticaBold = new PdfFont("Helvetica-Bold", "Cp1252", false);Map<FontKey, PdfFont> fontMap = new HashMap<FontKey, PdfFont>();fontMap.put(keyHelvetica, fontHelvetica);fontMap.put(keyHelveticaBold, fontHelveticaBold);exporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap); Link to comment Share on other sites More sharing options...
teodord Posted August 12, 2009 Share Posted August 12, 2009 Hi, What you experience is explained in this FAQ here:http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/faq.html?group_id=252#FAQ25 SansSerif is a Java logical font, not a physical font. It is not a good idea to use logical fonts, because you never know which is the real font behind that name. On different platform, that font is different. On Windows, it might resolve to Arial, on Unix, it might resolve to Helvetica.The solution is to make sure what fonts are used, by shipping the fonts with your application/reports. You can ship the fonts by packaging them in what we call JasperReports font extensions. You can find one such font extension in the /demo/fonts folder of the JasperReports distribution package. All the samples under /demo/samples make use of fonts shipped in that font extension folder, because it is part of the samples classpath when they are run.You could create a similar package and zip it up in a JAR file that you then add to your application classpath and all you have to take care after is the fontName attribute. Nothing else. Not even the FONT_MAP export parameter which is kind of deprecated nowadays, after font extension support was introduced. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
flacap Posted August 12, 2009 Share Posted August 12, 2009 Thank you very much for your quick response!!.I changed the SansSerif font by Arial in the iReport and in the FONT_MAP map but the text is cut anyway.I will see the example you mentioned in the JasperReports distribution package.Thank you again!Regards Link to comment Share on other sites More sharing options...
flacap Posted August 12, 2009 Share Posted August 12, 2009 I have another question, you say that "the FONT_MAP export parameter which is kind of deprecated nowadays, after font extension support was introduced". But I am using iReport 3.0.0 and jasper reports 2.0.5. Is font extension support introduced in this version? Because in the \demo\samples\fonts directory I don't have a font.xml file but a build.xml file. I have a file named jasperreports.properties too. I only have to create the two files (build.xml and jasperreports.properties) and the font directory with the ttf fonts, do I?Thanks in advance!Regards Link to comment Share on other sites More sharing options...
teodord Posted August 13, 2009 Share Posted August 13, 2009 Hi, Font extensions were introduced in JR 3.1.2, back in January. They greatly simplify work with fonts, so I suggest you upgrade.Using version that old you might encounter bugs that are fixed for a long time now and would be basically a waste of time to get around them.And I said /demo/fonts, not /demo/samples/fonts. Thanks,Teodor 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