2
votes

I am using fop to tranform fo file to pdf. See Exception:

org.apache.fop.fo.ValidationException: Invalid property encountered on "fo:block-container": display (See position 44:73)

I use jTidy to convert xhtml and xalan to convert xhtml to fo file with xsl style from antennahouse.

It is line 44 of fo file:

<fo:block-container role="html:div" display="inline-block" width="30px"><fo:block start-indent="0pt" end-indent="0pt">Prov:</fo:block></fo:block-container>

How to solve this. Thanks.

UPDATE: XHTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>Untitled Document</title>
   <style type="text/css">
      * {
         margin: 0;
         padding: 0;
         font-family: Arial, Helvetica, sans-serif;
         font-size: 12px;
         color: #333;
      }

      table.iss-account-aging-page {
         border-collapse: collapse;
         margin: 0 auto;
         width: 100%;
         font-size: 12px;
         padding: 0;
         color: #000;
         border: 1px solid #666;
      }

      table.iss-account-aging-page tr {
         page-break-inside: avoid;
      }

      table.iss-account-aging-page tr th {
         text-align: center;
         padding: 3px;
         font-weight: bold;
         color: #165ba8;
         font-size: 12px;
         border-bottom: 1px solid #666;
      }

      table.iss-account-aging-page tr th span {
         color: #165ba8;
      }

      table.iss-account-aging-page tr td {
         padding: 3px;
         font-size: 12px;
         color: #000;
         border-bottom: 1px solid #666;
      }

      .iss-page-print-report-patient-left-info {
         margin: 0 0 6px 0;
      }

      label.iss-page-print-report-patient-left-info {
         width: 60px;
         float: left;
         text-align: right;
         margin: 0 4px 0 0;
         display: block;
         clear: both;
         font-weight: bold;
         color: #444;
         font-size: 11px;
      }

      .iss-account-aging-page-practice-name {
         color: #2288FD;
         font-family: Georgia, "Times New Roman", Times, serif;
         font-size: 18px;
         font-weight: bold;
         text-align: center;
         width: 100%;
      }

      table.iss-account-aging-page-footer-tbl {
         float: right;
         border-collapse: collapse;
         margin-top: 10px;
         width: 60%;
         font-size: 12px;
      }

      table.iss-account-aging-page-footer-tbl tr td {
         border: 1px solid #666;
         padding: 3px 0;
         color: #045e98;
         text-align: center;
      }

      table.iss-account-aging-page-footer-tbl tr th {
         text-align: center;
         text-transform: uppercase;
         font-weight: bold;
         color: #03628b;
         border: 1px solid #666;
         padding: 3px 0;
      }

   </style>
</head>

<body>
<div style="width:795px; margin:5px auto; overflow:hidden; padding:0;">
   <div class="iss-account-aging-page-practice-name">
      Sonas DDS             
   </div>
   <div style="float:left; margin-left:10px; padding-bottom:5px;">
      <p>ADdress </p>

      <p>Montclair, CA 91763</p>

      <p>Phone:&nbsp;<span>111-111-1111</span></p>

      <p>Fax:&nbsp;<span></span></p>
   </div>
   <div style="clear:both; margin: 5px 0 5px 0; border-top: 1px solid #ccc;"></div>
   <div style="padding-left: 10px;"><span style="font-weight:bold;">Date:&nbsp;</span>11/07/2014</div>
   <div style="clear:both; text-align:center; margin-bottom: 10px;">
      <p style="font-family: Georgia, Times New Roman,Times,serif; font-size: 16px; font-weight: bold; text-transform: uppercase">
         Reports
      </p>
   </div>
   <table class="iss-account-aging-page-footer-tbl">
      <tr>
         <th>0 - 30 DAYS</th>
         <th>31 - 60 DAYS</th>
         <th>61 - 90 DAYS</th>
         <th>91+ DAYS</th>
      </tr>
      <tr>
         <td>$0.00</td>
         <td>$0.00</td>
         <td>$0.00</td>
         <td>$3,748,199.10</td>
      </tr>
   </table>
   <div style="clear:both;">&nbsp;</div>

   <table class="iss-account-aging-page">
      <tr>
         <th colspan="2">PATIENT INFORMATION</th>
         <th style="text-align:right;">0-30</th>
         <th style="text-align:right;">31-60</th>
         <th style="text-align:right;">61-90</th>
         <th style="text-align:right;">91+</th>
      </tr>
                     <tr>
            <td style="width:174px; vertical-align:top; padding-left:4px; padding-right:26px;">
               <p style="font-family: Georgia, Times New Roman,Times,serif; font-size: 13px; font-weight: bold;">A Patient</p>

                                 <p>ADdress2</p>

                                 <p style="padding-bottom: 6px;">LA</p>

               <p style="padding-bottom: 6px;">E-Mail: &nbsp;</p>

               <div style="float:left; padding-bottom: 6px;">
                  <div style="display: inline-block; width: 30px;">Item:</div>
                  <div style="display: inline-block;">item info</div>
               </div>
               <div style="clear: both;"></div>
               <p style="padding-bottom: 6px;">item 2: item info</p>

               <p style="padding-bottom: 6px;">item 3: item info</p>
            </td>
            <td style="width:166px; vertical-align:top;">
               <p class="iss-page-print-report-patient-left-info">
                  <label class="iss-page-print-report-patient-left-info">Phone:</label>(H) 111-111-1111
               </p>
               <p class="iss-page-print-report-patient-left-info">
                  <label class="iss-page-print-report-patient-left-info">&nbsp;</label>(M) &nbsp;
               </p>

               <p class="iss-page-print-report-patient-left-info">
                  <label class="iss-page-print-report-patient-left-info">&nbsp;</label>(O) &nbsp;
               </p>

               <p class="iss-page-print-report-patient-left-info" style="text-transform: capitalize">
                  <label class="iss-page-print-report-patient-left-info">Status:</label>Single
               </p>

               <p class="iss-page-print-report-patient-left-info">
                  <label class="iss-page-print-report-patient-left-info">ID:</label>123456
               </p>

               <p class="iss-page-print-report-patient-left-info" style="text-transform: capitalize">
                  <label class="iss-page-print-report-patient-left-info">Gender:</label>Male
               </p>

               <p class="iss-page-print-report-patient-left-info">
                  <label class="iss-page-print-report-patient-left-info">Birth Date:</label>&nbsp;
               </p>
            </td>
            <td style="vertical-align:top; width:70px;">
               <div style="text-align:right;">$0.00</div>
            </td>
            <td style="vertical-align:top; width:70px;">
               <div style="text-align:right;">$0.00</div>
            </td>
            <td style="vertical-align:top; width:70px;">
               <div style="text-align:right;">$0.00</div>
            </td>
            <td style="vertical-align:top; width:70px;">
               <div style="text-align:right;">$2,950.00</div>
            </td>
         </tr>
    </table>
</div>
</body>
</html>

Here is my java code

FileInputStream FIS= null;
      try {
         //tidy
         FIS = new FileInputStream("D:\\Test.xhtml");
         FileOutputStream FOS = new FileOutputStream("D:\\testXHTML.xHtml");
         Tidy T=new Tidy();
         T.setXHTML(true);
         Document D = T.parseDOM(FIS,FOS);

         //xalan
         DOMSource xmlDomSource = new DOMSource(D);
         DOMResult domResult = new DOMResult();
         Transformer transformerXalan = getTransformer("D:\\Test\\xhtml2fo-xsl-read-only\\xhtml2fo.xsl");
         transformerXalan.transform(xmlDomSource, new StreamResult(new FileOutputStream("D:\\result.fo")));

         //fop
         FopFactory fopFactory = FopFactory.newInstance();
         OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("D:/myfile.pdf")));
         org.apache.fop.apps.Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
         TransformerFactory factory = TransformerFactory.newInstance();
         Transformer transformer = factory.newTransformer(); // identity transformer
         Source src = new StreamSource(new File("D:\\result.fo"));
         Result res = new SAXResult(fop.getDefaultHandler());
         transformer.transform(src, res);
         out.close();
      } catch (Exception e) {
         e.printStackTrace();
      }

And my output enter image description here

1
FOP is telling you that the property "display" is not a valid xsl-fo property: you have to remove it.lfurini
Thank you. I removed display property in style in xhtml file and walkthrough this error but output dont keep css style.sonas sonas
You'd have to be a bit more specific than "dont keep css style". What exactly is wrong with the output? Also, your question lacks your original XHTML input, your XSLT code (or XSL-FO code) - and what the expected result would look like.Mathias Müller

1 Answers

2
votes

So, you are using an XSLT stylesheet from AntennaHouse to convert xhtml to fo, and then using Apache FOP to produce the pdf output.

A comment at the beginning of those stylesheets states that (emphasis added):

Since this stylesheet is originally developed by Antenna House to be used with XSL Formatter, it may not be compatible with another XSL-FO processors.

So, it should not come as a surprise that other formatters have issues with their output; in particular, XSL Formatter supports CSS properties (and display among them) while FOP doesn't.

However, the desired output (inline-stacked areas with a fixed width) can be achieved by using standard fo elements and properties, in particular inline-containers:

<fo:block>
    <!-- first "inline block" -->
    <fo:inline-container role="html:div" width="40px">
        <fo:block start-indent="0pt" end-indent="0pt" background-color="#AAFFFF">Alpha</fo:block>
    </fo:inline-container>
    <!-- second "inline block" -->
    <fo:inline-container role="html:div" width="40px">
        <fo:block start-indent="0pt" end-indent="0pt" background-color="#FFAAFF">Beta</fo:block>
    </fo:inline-container>
    <!-- third "inline block" -->
    <fo:inline-container role="html:div" width="40px">
        <fo:block start-indent="0pt" end-indent="0pt" background-color="#FFFFAA">A a a a a a a</fo:block>
    </fo:inline-container>
    ...
</fo:block>

Edit: I forgot to mention that the suggested solution works with the trunk version of FOP, as the implementation of fo:inline-container was completed after the release of FOP 1.1.