Generate pdf through jsp page when button is clicked
up vote
1
down vote
favorite
I am using springboot and using jsp for UI.
I have fetched the booking details from database and displayed using a table.When click on the (DownloadPDF) button all the booking details shown in the UI should be downloaded in pdf format.
I have used HTML-to-PDF with jQuery (docraptor.com) in script tag . I am getting pdf as portrait mode so only partial details shown by pdf but i want pdf in landscape mode. How to resolve this issue?
booking.jsp:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
.marquee {
background: blue;
white-space: nowrap;
-webkit-animation: rightThenLeft 20s linear;
margin-right: 10000px;
}
@-webkit-keyframes rightThenLeft {
0% {margin-right:100%;}
50% {margin-right:0;}
100% {margin-right:100%;}
@media print {
#pdf-button {
display: none;
}
}
}
</style>
<script src="https://docraptor.com/docraptor-1.0.0.js"></script>
<script type="text/javascript">
var downloadPDF = function() {
DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
test: true,
type: "pdf",
document_content: document.querySelector('#f1').innerHTML,
})
}
</script>
</head>
<body bgcolor="pink">
<div id="render">
<div class="c1" id="f1" >
<form class="bookings" method="post" action="getAllBooking" >
<table id="table1" class="table1" border="1" align="center" cellspacing="8" cellpadding="8" bgcolor="grey">
<h2 align="center" class="marquee">Booking details</h2>
<%
int len=0;
String id=request.getParameter("User");
String driver="com.mysql.jdbc.Driver";
String con="jdbc:mysql://localhost:3306/";
String db="carui";
String User="root";
String Password="oracle@123";
try
{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
Connection conn=null;
Statement st=null;
ResultSet rs=null;
%>
<%
try
{
conn=DriverManager.getConnection(con+db,User,Password);
st=conn.createStatement();
String sql="select *from bookings";
rs=st.executeQuery(sql);
%>
<tr>
<th>Car Id</th>
<th>Booking Id</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Persons</th>
<th>Mobile</th>
<th>Email</th>
<th>Place1</th>
<th>Place2</th>
<th>Person Name</th>
</tr>
<tbody>
<%
while(rs.next())
{
%>
<%
int carId=rs.getInt("cars_id");
int id1=rs.getInt("id");
String start=rs.getString("startdate");
String end=rs.getString("enddate");
int persons=rs.getInt("persons");
String mobile=rs.getString("p_number");
String mail=rs.getString("p_email");
String place1=rs.getString("place1");
String place2=rs.getString("place2");
String name=rs.getString("p_name");
%>
<tr>
<td><%=carId%></td>
<td><%=id1%></td>
<td><%=start%></td>
<td><%=end%></td>
<td><%=persons%></td>
<td><%=mobile%></td>
<td><%=mail %></td>
<td><%=place1 %></td>
<td><%=place2 %></td>
<td><%=name %></td>
</tr>
<%
}
%>
</tbody>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</form>
</div>
</div>
<form>
<div id="f2">
<input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</div>
</form>
</body>
</html>
jsp spring-boot
add a comment |
up vote
1
down vote
favorite
I am using springboot and using jsp for UI.
I have fetched the booking details from database and displayed using a table.When click on the (DownloadPDF) button all the booking details shown in the UI should be downloaded in pdf format.
I have used HTML-to-PDF with jQuery (docraptor.com) in script tag . I am getting pdf as portrait mode so only partial details shown by pdf but i want pdf in landscape mode. How to resolve this issue?
booking.jsp:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
.marquee {
background: blue;
white-space: nowrap;
-webkit-animation: rightThenLeft 20s linear;
margin-right: 10000px;
}
@-webkit-keyframes rightThenLeft {
0% {margin-right:100%;}
50% {margin-right:0;}
100% {margin-right:100%;}
@media print {
#pdf-button {
display: none;
}
}
}
</style>
<script src="https://docraptor.com/docraptor-1.0.0.js"></script>
<script type="text/javascript">
var downloadPDF = function() {
DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
test: true,
type: "pdf",
document_content: document.querySelector('#f1').innerHTML,
})
}
</script>
</head>
<body bgcolor="pink">
<div id="render">
<div class="c1" id="f1" >
<form class="bookings" method="post" action="getAllBooking" >
<table id="table1" class="table1" border="1" align="center" cellspacing="8" cellpadding="8" bgcolor="grey">
<h2 align="center" class="marquee">Booking details</h2>
<%
int len=0;
String id=request.getParameter("User");
String driver="com.mysql.jdbc.Driver";
String con="jdbc:mysql://localhost:3306/";
String db="carui";
String User="root";
String Password="oracle@123";
try
{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
Connection conn=null;
Statement st=null;
ResultSet rs=null;
%>
<%
try
{
conn=DriverManager.getConnection(con+db,User,Password);
st=conn.createStatement();
String sql="select *from bookings";
rs=st.executeQuery(sql);
%>
<tr>
<th>Car Id</th>
<th>Booking Id</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Persons</th>
<th>Mobile</th>
<th>Email</th>
<th>Place1</th>
<th>Place2</th>
<th>Person Name</th>
</tr>
<tbody>
<%
while(rs.next())
{
%>
<%
int carId=rs.getInt("cars_id");
int id1=rs.getInt("id");
String start=rs.getString("startdate");
String end=rs.getString("enddate");
int persons=rs.getInt("persons");
String mobile=rs.getString("p_number");
String mail=rs.getString("p_email");
String place1=rs.getString("place1");
String place2=rs.getString("place2");
String name=rs.getString("p_name");
%>
<tr>
<td><%=carId%></td>
<td><%=id1%></td>
<td><%=start%></td>
<td><%=end%></td>
<td><%=persons%></td>
<td><%=mobile%></td>
<td><%=mail %></td>
<td><%=place1 %></td>
<td><%=place2 %></td>
<td><%=name %></td>
</tr>
<%
}
%>
</tbody>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</form>
</div>
</div>
<form>
<div id="f2">
<input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</div>
</form>
</body>
</html>
jsp spring-boot
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using springboot and using jsp for UI.
I have fetched the booking details from database and displayed using a table.When click on the (DownloadPDF) button all the booking details shown in the UI should be downloaded in pdf format.
I have used HTML-to-PDF with jQuery (docraptor.com) in script tag . I am getting pdf as portrait mode so only partial details shown by pdf but i want pdf in landscape mode. How to resolve this issue?
booking.jsp:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
.marquee {
background: blue;
white-space: nowrap;
-webkit-animation: rightThenLeft 20s linear;
margin-right: 10000px;
}
@-webkit-keyframes rightThenLeft {
0% {margin-right:100%;}
50% {margin-right:0;}
100% {margin-right:100%;}
@media print {
#pdf-button {
display: none;
}
}
}
</style>
<script src="https://docraptor.com/docraptor-1.0.0.js"></script>
<script type="text/javascript">
var downloadPDF = function() {
DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
test: true,
type: "pdf",
document_content: document.querySelector('#f1').innerHTML,
})
}
</script>
</head>
<body bgcolor="pink">
<div id="render">
<div class="c1" id="f1" >
<form class="bookings" method="post" action="getAllBooking" >
<table id="table1" class="table1" border="1" align="center" cellspacing="8" cellpadding="8" bgcolor="grey">
<h2 align="center" class="marquee">Booking details</h2>
<%
int len=0;
String id=request.getParameter("User");
String driver="com.mysql.jdbc.Driver";
String con="jdbc:mysql://localhost:3306/";
String db="carui";
String User="root";
String Password="oracle@123";
try
{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
Connection conn=null;
Statement st=null;
ResultSet rs=null;
%>
<%
try
{
conn=DriverManager.getConnection(con+db,User,Password);
st=conn.createStatement();
String sql="select *from bookings";
rs=st.executeQuery(sql);
%>
<tr>
<th>Car Id</th>
<th>Booking Id</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Persons</th>
<th>Mobile</th>
<th>Email</th>
<th>Place1</th>
<th>Place2</th>
<th>Person Name</th>
</tr>
<tbody>
<%
while(rs.next())
{
%>
<%
int carId=rs.getInt("cars_id");
int id1=rs.getInt("id");
String start=rs.getString("startdate");
String end=rs.getString("enddate");
int persons=rs.getInt("persons");
String mobile=rs.getString("p_number");
String mail=rs.getString("p_email");
String place1=rs.getString("place1");
String place2=rs.getString("place2");
String name=rs.getString("p_name");
%>
<tr>
<td><%=carId%></td>
<td><%=id1%></td>
<td><%=start%></td>
<td><%=end%></td>
<td><%=persons%></td>
<td><%=mobile%></td>
<td><%=mail %></td>
<td><%=place1 %></td>
<td><%=place2 %></td>
<td><%=name %></td>
</tr>
<%
}
%>
</tbody>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</form>
</div>
</div>
<form>
<div id="f2">
<input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</div>
</form>
</body>
</html>
jsp spring-boot
I am using springboot and using jsp for UI.
I have fetched the booking details from database and displayed using a table.When click on the (DownloadPDF) button all the booking details shown in the UI should be downloaded in pdf format.
I have used HTML-to-PDF with jQuery (docraptor.com) in script tag . I am getting pdf as portrait mode so only partial details shown by pdf but i want pdf in landscape mode. How to resolve this issue?
booking.jsp:
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
.marquee {
background: blue;
white-space: nowrap;
-webkit-animation: rightThenLeft 20s linear;
margin-right: 10000px;
}
@-webkit-keyframes rightThenLeft {
0% {margin-right:100%;}
50% {margin-right:0;}
100% {margin-right:100%;}
@media print {
#pdf-button {
display: none;
}
}
}
</style>
<script src="https://docraptor.com/docraptor-1.0.0.js"></script>
<script type="text/javascript">
var downloadPDF = function() {
DocRaptor.createAndDownloadDoc("YOUR_API_KEY_HERE", {
test: true,
type: "pdf",
document_content: document.querySelector('#f1').innerHTML,
})
}
</script>
</head>
<body bgcolor="pink">
<div id="render">
<div class="c1" id="f1" >
<form class="bookings" method="post" action="getAllBooking" >
<table id="table1" class="table1" border="1" align="center" cellspacing="8" cellpadding="8" bgcolor="grey">
<h2 align="center" class="marquee">Booking details</h2>
<%
int len=0;
String id=request.getParameter("User");
String driver="com.mysql.jdbc.Driver";
String con="jdbc:mysql://localhost:3306/";
String db="carui";
String User="root";
String Password="oracle@123";
try
{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
Connection conn=null;
Statement st=null;
ResultSet rs=null;
%>
<%
try
{
conn=DriverManager.getConnection(con+db,User,Password);
st=conn.createStatement();
String sql="select *from bookings";
rs=st.executeQuery(sql);
%>
<tr>
<th>Car Id</th>
<th>Booking Id</th>
<th>StartDate</th>
<th>EndDate</th>
<th>Persons</th>
<th>Mobile</th>
<th>Email</th>
<th>Place1</th>
<th>Place2</th>
<th>Person Name</th>
</tr>
<tbody>
<%
while(rs.next())
{
%>
<%
int carId=rs.getInt("cars_id");
int id1=rs.getInt("id");
String start=rs.getString("startdate");
String end=rs.getString("enddate");
int persons=rs.getInt("persons");
String mobile=rs.getString("p_number");
String mail=rs.getString("p_email");
String place1=rs.getString("place1");
String place2=rs.getString("place2");
String name=rs.getString("p_name");
%>
<tr>
<td><%=carId%></td>
<td><%=id1%></td>
<td><%=start%></td>
<td><%=end%></td>
<td><%=persons%></td>
<td><%=mobile%></td>
<td><%=mail %></td>
<td><%=place1 %></td>
<td><%=place2 %></td>
<td><%=name %></td>
</tr>
<%
}
%>
</tbody>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</form>
</div>
</div>
<form>
<div id="f2">
<input id="pdf-button" type="button" value="Download PDF" onclick="downloadPDF()" />
</div>
</form>
</body>
</html>
jsp spring-boot
jsp spring-boot
edited Nov 19 at 10:58
asked Nov 19 at 7:18
Divya
24
24
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52
add a comment |
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369944%2fgenerate-pdf-through-jsp-page-when-button-is-clicked%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Landscape printing from HTML
– Alan Hay
Nov 19 at 15:58
upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
Nov 20 at 9:52