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>









share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of Landscape printing from HTML
    – Alan Hay
    yesterday










  • upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
    – master ArSuKa
    yesterday















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>









share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of Landscape printing from HTML
    – Alan Hay
    yesterday










  • upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
    – master ArSuKa
    yesterday













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>









share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago





















New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Divya

63




63




New contributor




Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Divya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Possible duplicate of Landscape printing from HTML
    – Alan Hay
    yesterday










  • upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
    – master ArSuKa
    yesterday


















  • Possible duplicate of Landscape printing from HTML
    – Alan Hay
    yesterday










  • upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
    – master ArSuKa
    yesterday
















Possible duplicate of Landscape printing from HTML
– Alan Hay
yesterday




Possible duplicate of Landscape printing from HTML
– Alan Hay
yesterday












upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
yesterday




upvoted as I am working on the same, I hope I can use your current steps to achieve what you did
– master ArSuKa
yesterday

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Divya is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Divya is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Divya is a new contributor. Be nice, and check out our Code of Conduct.













Divya is a new contributor. Be nice, and check out our Code of Conduct.












Divya is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules