dac4457 Posted April 4, 2008 Share Posted April 4, 2008 I have a jasper report that has a Textfield flagged as Markup HTML. I understand from previous topics that it supports formatting tags but not the layout type of tags. I really need a bullited list of sorts but would be satisfied with just having a <br> tag work. I have tried both <br> and <br/> in both upper and lower case and when sending it to a PDF it will not give me a line break. I have tried replacing it with a new line character. The only thing that gives me a new line is the <li> tag. It doesn't give me the bullet mark but does give me a new line. I have tried removing all of the bullited list tags and using the various <br> tags but I do not get a new line.I also have converted the <strong> tags to <b> making sure I have the closing tag and when sending it to a pdf I do not see any bold. Do I have to use style tags? The HTML is stored in the database from a front end application using FCK Editor. It generates the HTML and I could use a StringBuffer to read through the HTML and replace it with simpler HTML or something that the Jasper filler/exporter would be happier with. Any insight on rules and how the HTML should be for the Markup HTML setting to work would be greatly appreciated. ThanksCheri Link to comment Share on other sites More sharing options...
dac4457 Posted April 4, 2008 Author Share Posted April 4, 2008 One other question to ask about the Markup HTML field. Do I need to provide the <HTML>, <HEAD>, <BODY> tags?I believe I tried this in the past and it didn't make a difference.One other note when I use the Markup HTML property I don't set the isStyledText to true. I leave this at false.ThanksCheri Link to comment Share on other sites More sharing options...
C-Box Posted April 7, 2008 Share Posted April 7, 2008 Hi, as I currently switch from JR 2.0.2 to JR 2.0.5 I had some troubles with replacing the old StyledText attribute against the new markup one. I set all elements that had formerly set "isStyledText" to true to new setMarkup("html") as I just use html-syntax within report fields. But as Teodor told me I should have uses setMarkup("styled") instead. IReport just has "RTF" and "HTML" ... so I'm lucky to have my own plugin that does te actual work. Just try to set the attribute within JRXML directly (via editor) and try again your sample. My problem was solved with the tag "styled" instead "html"... (I hope Teodor will explain the differences a bit more in detail) hthC-Box Link to comment Share on other sites More sharing options...
rKT Posted April 19, 2008 Share Posted April 19, 2008 I´m facing the same problem, do you fix it ? When you say method setMarkup(), where you call this method ? In iReport or when you are generating the report in your application ? TnxRodrigo Kerkhoff Link to comment Share on other sites More sharing options...
C-Box Posted April 22, 2008 Share Posted April 22, 2008 The mentioned method setMarkup("styled") is direct JasperReports API.... so I have an own iReport-Plugin that can load many JRXMLs from one directory (and subdirs) and does some manipulations with the JasperDesigns, that are too much work to do it by hand. So you can also edit your JRXML within EDITOR and change the Markup-Tag just to "styled". hthC-Box Link to comment Share on other sites More sharing options...
rnarala Posted June 6, 2008 Share Posted June 6, 2008 Hello,I went thru the forums to fing how to get the HTML markup work in PDF. I read that setting the markup="styled" in jrxml would fix it . But it did not fix it. Given below is my jrxml snippet Code:<textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" ><reportElement mode="Opaque" x="15" y="388" width="555" height="62" backcolor="#C0C0C0" key="textField" positionType="Float"/><box></box><textElement markup="styled"> <font size="12"/> </textElement><textFieldExpression class="java.lang.String"><![CDATA[$F{heading}]]></textFieldExpression></textField> And I followed the MarkUp example in my java code. Given below is my Java code Code:[code]public class ReportServlet extends BaseServlet { /** * */ private static final long serialVersionUID = 1L; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // URI - WebContext/rpt/{templateName}/{treeName}/{timePeriodId}/... ? // or parameters? String qs[] = request.getRequestURI().split("/"«»); String templateName = "/MainReport.jasper"; String treeName = "datatree"; int timePeriodId = 0; if (qs.length == 6) { // TODO: FIX THIS templateName = "/" + qs[3] + ".jasper"; treeName = qs[4]; timePeriodId = Integer.parseInt(qs[5]); } UserSession session = UserSession.login(request, "rnarala", "rnd26575", "de"«»); ServletOutputStream sos = null; try { byte[] bArray = GenerateReport(timePeriodId, session, treeName, templateName); response.setContentLength(bArray.length); response.setHeader("Content-Disposition", "inline; filename=report.pdf"«»); response.setContentType("application/pdf"«»); sos = response.getOutputStream(); sos.write(bArray); sos.flush(); } catch (Exception re) { re.printStackTrace(); response.getOutputStream().println(re.getMessage()); } finally { try { if (sos != null) { sos.flush(); sos.close(); } } catch (Exception e1) { e1.printStackTrace(); } } } /** * @param timePeriodId * The id of time period. * @param session * The user session that is required to build the ReportTree * @param treeName * The data tree name. * @param templateName * The JasperReport template name. * @return PDF byte array The byte array of the generated PDF */ public byte[] GenerateReport(int timePeriodId, UserSession session, String treeName, String templateName) { InputStream is = null; ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); String r = getClass().getResource("/MainReport.jrxml"«»).getPath(); File reports = new File(r.substring(0, r.lastIndexOf('/'))); for (File f : reports.listFiles()) { if (f.getName().endsWith("jrxml"«»)) { System.err.println(f); JasperCompileManager.compileReportToFile(f.getPath(), f .getPath().replaceFirst("jrxml", "jasper"«»)); } } ReportTree tree = session.getReportTree(timePeriodId, treeName); List<ReportTreeNode> rootList = new ArrayList<ReportTreeNode>(); rootList.add(tree.root); JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource( rootList, true); is = this.getClass().getResourceAsStream(templateName); JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap<Object, Object>(), ds); JRPdfExporter exporter = new JRPdfExporter(); Map<Object, Object> fontMap = new HashMap<Object, Object>(); fontMap.put(new FontKey("Arial", true, false), new PdfFont( "Helvetica-Bold", "Cp1252", false)); fontMap.put(new FontKey("Arial", false, true), new PdfFont( "Helvetica-Oblique", "Cp1252", false)); fontMap.put(new FontKey("Arial", true, true), new PdfFont( "Helvetica-BoldOblique", "Cp1252", false)); fontMap.put(new FontKey("Comic Sans MS", false, false), new PdfFont("COMICBD.TTF", "Cp1252", true)); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap); exporter.exportReport(); } catch (JRException jre) { jre.printStackTrace(); throw new RuntimeException( "Exception Filling the template with data", jre); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Exception in GenerateReport", e); } finally { try { if (is != null) { is.close(); } } catch (Exception e1) { e1.printStackTrace(); } } return baos.toByteArray(); }} please let me know if I am missing something. ANy help in this regard is appreciated. regards,Ravi Link to comment Share on other sites More sharing options...
C-Box Posted June 9, 2008 Share Posted June 9, 2008 What's the content of the field: $F{heading} ?? C-Box Link to comment Share on other sites More sharing options...
rnarala Posted June 10, 2008 Share Posted June 10, 2008 it is html content <h1>This is a header text</h1> Link to comment Share on other sites More sharing options...
C-Box Posted June 11, 2008 Share Posted June 11, 2008 Uii... have you already checked the StyledText Sample provided with full JasperReports Download package???? There are just a few html tags supported by StyledText in JR. <h1> is not one of them. :-(Just take a look at it.When I remember right we just use <b> for bold, <i> for italic, <u> for underline and some <font> tags (size, color, family) to render html-styled content. (I think <li> is also supported, but has a bug when line breaks) hthC-Box Link to comment Share on other sites More sharing options...
rnarala Posted June 11, 2008 Share Posted June 11, 2008 even the italics does not work. I tried it with <i>This is a italics text<i> it rendered a plain text Link to comment Share on other sites More sharing options...
teodord Posted June 11, 2008 Share Posted June 11, 2008 Hi, You should start with some sample text fields taken from the /demo/samples/markup sample provided with the project.If you see it working there, then try to do only slight modifications to it and understand when it no longer works. Why? Because everything you have tried so far has been wrong for one reason or another.First you have tried H1 tags in styled text (not supported, as indicated in the /demo/samples/styledtext).Next, you have tried italic text, but in PDF, where special PDF font settings have to be made. This is also shown in those samples and you would have seen them if you would have paid more attention to them. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
C-Box Posted June 11, 2008 Share Posted June 11, 2008 First: Do what Teodor told you! Check the sample (as I also adviced)!!! You'll understand more details than trial & error! and next... it should be:<i>This is a italics text</i> and before you call the exporter you should use this to map the system fonts to the PDF fonts:Code:Map<FontKey,PdfFont> fontMap = new HashMap<FontKey,PdfFont>(); // Arial is Helvetica fontMap.put(new FontKey("Arial", true, false), new PdfFont("Helvetica-Bold", "Cp1252", false)); fontMap.put(new FontKey("Arial", false, true), new PdfFont("Helvetica-Oblique", "Cp1252", false)); fontMap.put(new FontKey("Arial", true, true), new PdfFont("Helvetica-BoldOblique", "Cp1252", false)); // Times bleibt Times fontMap.put(new FontKey("Times New Roman", true, false), new PdfFont("Times-Bold", "Cp1252", false)); fontMap.put(new FontKey("Times New Roman", false, true), new PdfFont("Times-Italic", "Cp1252", false)); fontMap.put(new FontKey("Times New Roman", true, true), new PdfFont("Times-BoldItalic", "Cp1252", false)); // Comic !??! fontMap.put(new FontKey("Comic Sans MS", false, false), new PdfFont("COMICBD.TTF", "Cp1252", true)); exporter.setParameter(JRExporterParameter.FONT_MAP, fontMap); hthC-Box Link to comment Share on other sites More sharing options...
joeherbet Posted July 23, 2008 Share Posted July 23, 2008 It seems that the html support when using markup="html" is extremely limited. Even text alignment does not work. Is this the case? Link to comment Share on other sites More sharing options...
lucianc Posted July 23, 2008 Share Posted July 23, 2008 Joe wrote: It seems that the html support when using markup="html" is extremely limited. Even text alignment does not work. Is this the case? You're right, text alignment is ignored when using markup="html". See this thread for some details on this.Regards,Lucian Link to comment Share on other sites More sharing options...
prammadhavan Posted June 30, 2009 Share Posted June 30, 2009 Hi ,I am new to this.From where i can find the /demo/samples/markup in the project. Thanks.Madhavan Link to comment Share on other sites More sharing options...
wjones14 Posted July 1, 2009 Share Posted July 1, 2009 Can anyone tell me why the HTML underline tag does work in my textField, but the HTML bold tag does not? <u>MyText</u> works<b>MyText</b> does not work We are using JasperReports 3.0, iReport 3.0, JDK 1.5. The properties of the textField are:Font Name = Courier NewPDF Font Name = CourierMarkup = HTMLIsStyledText not checkedPDF Embedded not checked. We are using the JasperRunManager.runReportToPDF() method to stream the report. Link to comment Share on other sites More sharing options...
lucianc Posted July 1, 2009 Share Posted July 1, 2009 madhavanasokanWrote: Hi , I am new to this.From where i can find the /demo/samples/markup in the project. Thanks. Madhavan See the READ THIS FIRST! - Documentation and Samples Here! topic found on the top of the JR forum page.Regards,LucianPost Edited by lucianc at 07/01/2009 15:31 Link to comment Share on other sites More sharing options...
lucianc Posted July 1, 2009 Share Posted July 1, 2009 wjones14Wrote: Can anyone tell me why the HTML underline tag does work in my textField, but the HTML bold tag does not? You need to configure a bold PDF font for the text field.You can either do this by using the FONT_MAP export parameter (as seen here), or font extension on newer JR versions.Regards,Lucian Link to comment Share on other sites More sharing options...
PlexPro Posted October 22, 2009 Share Posted October 22, 2009 Here is an example of a text box which is a combination of a parameter, static text, and a field, where I wanted the field to have distinct attributes, and the output is PDF. The default PDF-font is Times-Roman, size 16 points, without other special characteristics. Text Field Expression (see Code box below). Here is the result: 10082 : Alpha IncorporatedCode:Text Field Expression:$P{customerId} +" : <style isBold="true" pdfFontName="Times-BoldItalic">" +$F{SoldToName} + "</style>"Post Edited by PlexPro at 10/22/2009 19:34 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