⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamic pdf creation from database.txt

📁 This a sample JSP which creates an XML definition for a PDF file.
💻 TXT
📖 第 1 页 / 共 2 页
字号:
<tr>
<td border-bottom="1">
<p class="total">Total amount due</p>
</td>
<td border-bottom="1">
<p class="total"><%=amtf.format(amount*(1+tax))%></p>
</td>
<td></td>
</tr>
</table>

<!-- Second part of the right column. The "Dear Customer" bit
and the barcode.
-->

<table margin-top="8">
<tr>
<td margin-right="1in">
<p class="info">Dear Customer</p>
<ul>
<li><p>Please fill in parts 1 to 3 and insert a total next to the &pound; sign below.</p></li>
<li>Details of how to pay are shown overleaf.</li>
<li>Please do not send cash by post.</li>
</ul>
</td>
<td valign="middle">
<barcode value="<%=account%>"/>
</td>
</tr>
</table>

<!-- Third part of the right column. A 6 column table.
1st column = "Bank Details" text and the sort code box
2nd column = "Signature" and "Date" text
3rd column = blank, but has a bottom border to creat the underlines
4th column = "Cash" and "Cheques" text and the pound sign
5th column = the pounds box (would be the dollars box in the US)
6th column = the pennies box (would be the cents box in the US)
-->

<table margin-top="10">
<tr>
<td valign="bottom">
<p>
Bank Details<br/>
Big Faceless Banking Corp.<br/>
Head Office Collection Acct.
</p>
<p class="sortcode">12-34-56</p>
</td>
<td valign="middle">1 Signature</td>
<td margin-right="0.2in"></td>
<td valign="middle">3 Cash</td>
<td class="poundbox"></td>
<td class="pennybox"></td>
</tr>
<tr>
<td valign="middle">2 Date</td>
<td margin-right="0.2in"></td>
<td valign="middle">or cheques</td>
<td class="poundbox"></td>
<td class="pennybox"></td>
</tr>
<tr>
<td valign="middle"><p class="giro">&pound;</p></td>
<td class="poundbox"></td>
</tr>
</table>

<!-- Fourth part of the right side - the footnote -->

<p class="smallprint">
Please do not fold, pin or staple this slip or write below this line
</p>
</td>
</tr>
      </table>

      <!-- Create a black line at the bottom. Ideally we'd do this by setting a
the bottom border for the surrounding div, but we've already set the
top border to "dotted", and currently we can only set one border-style
for all the borders. We'll probably fix this in a later release
      -->
      <div background-color="black"/>

    </div>
  </macro>

  <macro id="header">
    <!--
         This header is used on every page, and contains the
logo, address (ours and theres) and so on.
    -->

    <div>
      <table width="100%">
<tr>
<!-- First the logo and it's accompanying text -->

<td>
<table>
<tr>
<td>
<img dpi="300"/>
</td>
<td valign="middle">
<p class="heading">Big Faceless Telecommunications Ltd.</p>
</td>
</tr>
</table>
</td>

<!-- Next the customer number and our address -->

<td align="right">
<table>
<tr>
<td>
<p padding-right="0.5in">Your Customer No.</p>
</td>
<td>
<p><%=account%></p>
</td>
</tr>
<tr border-bottom="1">
<td>
<p class="info">Date</p>
</td>
<td>
<p><%=datef.format(new java.util.Date())%></p>
</td>
</tr>
<tr border-bottom="2">
<td colspan="2">
Big Faceless Telecommunications Ltd.<br/>
A fictitious company<br/>
Invented to demonstrate<br/>
The Report Generator<br/>
<br/>
http://big.faceless.org/products/report
</td>
</tr>
</table>
</td>

</tr>
<tr>

<!-- On the next row, the customers address -->

<td valign="bottom"><pre class="address">
<%=name %>
<%=address%>
</pre></td>
</tr>
      </table>

      <!-- Last of all, the title and pagenumber of the document -->

      <table class="heading">
<tr>
<td>
Phone Bill for <%=name%>
</td>
<td>
<p align="right">Page <currentpage/> of <totalpages/></p>
</td>
</tr>
      </table>
    </div>
  </macro>
</macrolist>

</head>

<!--

Now we begin the actual body of the document. In this example most
of the work is done in the headers and footers, so this bit is
fairly simple

Notice how we use the header="header" attribute. The quoted value is
just the ID of the appropriate macro to include - it could be called
anything, there's nothing special about it being called "header"

We also set the language for the whole document here - this is taken
from the locale, and is done in the form "en-US" or "de-DE". The
country part is used to format the currency values.

-->


<body size="<%=pagesize%>" header="header" header-height="180" padding="0.25in" font-size="10" lang="<%=loc.getLanguage()+"-"+loc.getCountry()%>">


<!-- First the heading table, giving the total amount of the bill -->

<table font-size="11" margin-bottom="10" >
  <tr>
    <td padding-bottom="5">
      <p><%=amtf.format(amount)%></p>
    </td>
    <td>Call Charges</td>
  </tr>
  <tr>
    <td padding-bottom="5">
      <p><%=amtf.format(amount)%></p>
    </td>
    <td>Subtotal excluding VAT</td>
  </tr>
  <tr>
    <td border-bottom="2">
      <p><%=amtf.format(amount*tax)%></p>
    </td>
    <td>Tax at <%=new DecimalFormat("#0.0%").format(tax)%></td>
  </tr>
  <tr font-weight="bold">
    <td class="amounttable">
      <p><%=amtf.format(amount*(1+tax))%></p>
    </td>
    <td>Total due</td>
  </tr>
</table>


<!-- Now the main table with the itemized calls. Because most of the
     styling information is done in the stylesheet back in the document
     head, this is surprisingly simple.

     We use the database again to get the call information.
-->

<table class="breakdown">
  <thead>
    <tr>
      <td>Date</td>
      <td>Number</td>
      <td>Destination</td>
      <td>Duration (seconds)</td>
      <td>Cost</td>
    </tr>
  </thead>
  <tbody>
<%
s = c.createStatement();
r = s.executeQuery("select date, callee, seconds, charges.name, charges.persecond from calls, charges where charges.type=calls.chargetype and accno="+account+" order by date");

while (r.next()) {
%>
<tr>
<td><%=datetimef.format(r.getTimestamp("date"))%></td>
<td><%=r.getString("callee")%></td>
<td><%=r.getString("name")%></td>
<td><%=r.getInt("seconds")%></td>
<td><%=amtf.format(r.getInt("seconds") * r.getDouble("persecond"))%></td>
</tr>
<%
}
r.close();
s.close();
%>
  </tbody>
</table>

<!--

That's the call breakdown, now we place the final items on the statement,
the graphs analyzing the calls.

Again most of the styling for these graphs is done in the stylesheet in
the document head, so all we need to do here is put in the graph values

-->


<table margin-top="20">
  <thead>
    <tr margin-bottom="8">
      <td class="heading">Call analysis</td>
    </tr>
  </thead>
  <tr>
    <td align="center">
      <h4>Number of calls</h4>

      <!-- First the Pie Graph -->

      <piegraph id="numcalls">
<%
s = c.createStatement();
r = s.executeQuery("select charges.name, count(*) as tot from charges, calls where calls.chargetype=charges.type group by charges.name;");
while (r.next()) {
%>
        <gdata name="<%=r.getString("name")%>" value="<%=r.getDouble("tot")%>"/>
<%
}
r.close();
s.close();
%>
      </piegraph>
    </td>
    <td align="center">

      <h4>Cost of calls</h4>

      <!-- Then the Bar Graph -->

      <bargraph id="callcost">
<%
s = c.createStatement();
r = s.executeQuery("select charges.name, sum(seconds)*persecond as tot from charges, calls where calls.chargetype=charges.type group by charges.name, charges.persecond");
while (r.next()) {
%>
        <gdata name="<%=r.getString("name")%>" value="<%=r.getDouble("tot")%>"/>
<%
}
r.close();
s.close();
c.close();
%>
      </bargraph>
    </td>
  </tr>
</table>

<!--

All done! Close the PDF. The final } brace matches the "if (account==null)"
test way back near the start of the document

-->
    

</body>
</pdf>
<% } %>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -