英文:
How to generate a PDF report from JSP page
问题
抱歉,由于您要求只返回翻译好的部分,我将仅翻译您提供的代码片段。以下是您提供的代码的翻译:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>View JTC</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<% if (session.getAttribute("empid") == null) {
response.sendRedirect("index.jsp?message=Session Expired!!");
}
session.setAttribute("cpage", "production");
%>
<jsp:include page="navigationMenu.jsp" />
</head>
<body>
<section class="container-fluid">
<table class="table table-bordered">
<!-- ... 表格内容 ... -->
</table>
<table class="table table-bordered">
<!-- ... 表格内容 ... -->
</table>
<table class="table table-bordered">
<!-- ... 表格内容 ... -->
</table>
<table class="table table-bordered">
<!-- ... 表格内容 ... -->
</table>
</section>
</div>
<script src="assets/jquery/customjs.js" type="text/javascript"></script>
<script src="assets/jquery/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="assets/jquery/popper.min.js" type="text/javascript"></script>
<script src="assets/jquery/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
由于您提到您需要将此页面导出为横向页面,并将所有内容缩放到一页中,这涉及到生成 PDF 并设置页面的打印属性。在 Java 中,您可以使用一些库来实现这一目标,如 iText
或 Flying Saucer
.
请注意,上述代码片段中涉及到了一些 JSP 和 HTML 代码,但是生成 PDF 并设置打印属性需要使用适当的 Java 代码,因此您需要将这些片段整合到 Java 代码中来实现您的目标。如需更详细的指导,请告知我需要提供哪些帮助。
英文:
I need to Generate PDF report in Java. Earlier when i use Cold Fusion it was easier to export html to PDF, is there any way to convert the html to pdf in JAVA.
I tried JSPDF javascript method to convert this page but that doesn't works.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>View JTC</title>
<link href="assets/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<%
if (session.getAttribute("empid") == null) {
response.sendRedirect("index.jsp?message=Session Expired!!");
}
session.setAttribute("cpage", "production");
%>
<jsp:include page="navigationMenu.jsp" />
</head>
<body>
<section class="container-fluid">
<table class="table table-bordered">
<tr>
<th style="width:30%;vertical-align:middle;text-align:center;">logo</th>
<th colspan="2" style="text-align:center;width:70%">Denholm Yam Contracting Comapany L.L.C</th>
</tr>
<tr>
<th rowspan="2" style="text-align:center;vertical-align:middle;">Job Travel Card</th>
<th style="width:10%;">JTC No:</th>
<th></th>
</tr>
<tr>
<th>Date</th>
<th></th>
</tr>
</table>
<table class="table table-bordered">
<tr >
<td style="width:10%;text-align:left;">Project Number</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:10%;text-align:left;">Unit No. / Tag No.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
<tr>
<td>Area Number</td>
<td colspan="2"></td>
<td>Material Class</td>
<td colspan="4"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Drawing No: / ISO Number</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:15%;text-align:left;">JC No:</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Sheet No</td>
<td style="width:15%;text-align:left;"></td>
<td style="width:10%;text-align:left;">Rev. No.</td>
<td style="width:15%;text-align:left;"></td>
</tr>
<tr>
<td style="width:15%;text-align:left;">Item Description</td>
<td style="width:15%;text-align:left;" colspan="2"></td>
<td style="width:15%;text-align:left;">ITP Stage Nos.</td>
<td style="width:15%;text-align:left;" colspan="4"></td>
</tr>
</table>
<!-- Fitup data -->
<table class="table table-bordered">
<tr>
<th rowspan="12" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Fabrication Assembly Fit-Up
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Weld/joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Item/Position No.</th>
<th colspan="2">Material Spec Grade</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Size</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Thickness</th>
<th colspan="2">Heat/Plate/TestNo</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Welder No. for tracking</th>
<th colspan="2">Fitup Result</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="2" >Sign</th>
</tr>
<tr>
<th>Material 1</th>
<th>Material 2</th>
<th>Material 1</th>
<th>Material 2</th>
<th>Accept</th>
<th>Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
<!-- welding data -->
<table class="table table-bordered">
<tr>
<th rowspan="13" style="text-align:center;vertical-align:middle;">
<span class="verticaltext">
Welding Details
</span>
</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Joint No</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">WPS No.</th>
<th colspan="3" class="text-center">Welding Process</th>
<th colspan="3" class="text-center">Welder/Operation No.</th>
<th colspan="2" rowspan="2" class="text-center" >Visual Inspection</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3">Date</th>
<th style="text-align:center;vertical-align:middle;" rowspan="3" >Sign</th>
</tr>
<tr>
<th colspan="3" class="text-center">Passes</th>
<th colspan="3" class="text-center">Passes</th>
</tr>
<tr>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Root/Hot</th>
<th class="text-center">Fill</th>
<th class="text-center">Cap</th>
<th class="text-center">Accept</th>
<th class="text-center">Reject</th>
</tr>
<c:forEach begin="1" var="xx" end="10">
<tr>
<c:if test="${xx==1}">
</c:if>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:forEach>
<tr>
<td colspan="4">Name & Signature of fabrication foreman</td>
<td colspan="3">Released to</td>
<td colspan="2">
<input type="checkbox">
QC/NDE/DIM.
</td>
<td colspan="1">
<input type="checkbox">
Welding
</td>
<td colspan="4">
<input type="checkbox">
Fabrication/Assembly
</td>
</tr>
<tr>
<td colspan="14">Name & Signature of QC Personel</td>
</tr>
<tr>
<td colspan="7">Date</td>
<td colspan="7">Date</td>
</tr>
</table>
</section>
</div>
<script src="assets/jquery/customjs.js" type="text/javascript"></script>
<script src="assets/jquery/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="assets/jquery/popper.min.js" type="text/javascript"></script>
<script src="assets/jquery/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
I need to export this page in landscape and all this content scaled into one page. Is there any way? Thank you in advance.
答案1
得分: 1
你可以使用Flyingsaucer。
> Flying Saucer是一个纯Java库,用于使用CSS 2.1进行布局和格式化来渲染任意格式良好的XML(或XHTML),输出到Swing面板、PDF和图像。
英文:
You can use Flyingsaucer.
> Flying Saucer is a pure-Java library for rendering arbitrary
> well-formed XML (or XHTML) using CSS 2.1 for layout and formatting,
> output to Swing panels, PDF, and images.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论