使用jsPDF将html导出为pdf

原学程将引见应用jsPDF将html导出为pdf的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

使用jsPDF将html导出为pdf 教程 第1张

成绩描写

嗨,我想将html导出为pdf,我曾经应用jsPDF一切的任务pdf也导出,但是我想获得雷同的html在pdf,html款式没有任务我能做甚么,有人能助我吗?有甚么办法不妨在jsPDF中应用html款式吗?这是我的html代码。我今后链交http://jsfiddle.net/xzZ七n/一/

取得了1个剧本函数

<div class="panel col-xs⑴二 col-sm⑴二 col-md⑴一" style="" id="quotation">


 <header><img src="~/images/doc/header_footer/TOUR_Header.png" width="六00" /></header>
 <table width="六00" border="0" style="font-size:一二px;border:none;" ng-repeat="endetails in enquiryQuote" id="enq_details">

  <tr>
<td><b>Enquiry Date</b></td>
<td>{{endetails.system_date_time | date:fullDate}}</td>
<td><b>Enquiry ref.</b></td>
<td>{{endetails.reference_no}}</td>
  </tr>
  <tr>
<td><b>Dep. date</b></td>
<td>{{endetails.departing_date | date:fullDate}}</td>
<td><b>Depart. from</b></td>
<td>{{endetails.departing_from}}</td>
  </tr>
  <tr>
<td><b>Ret. date</b></td>
<td>{{endetails.returning_date | date:fullDate}}</td>
<td><b>Travel. to</b></td>
<td>{{endetails.travelling_to}}</td>
  </tr>

  <tr>
<td><b>Customer</b></td>
<td>{{endetails.name}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
 </table>

 <table width="三00" border="0" style="font-size:一二px;border:none;" ng-repeat="total in invoice_total">
  <tr>
<td><b>Total Price</b></td>
<td>{{total.total_amount}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
 </table>

 <table width="六00" border="0" style="" ng-repeat="product in invheader[0].invoice_hotel">
  <tr>
<td><font color="red;">Hotel Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Hotel name</b></td>
<td style="width:三00px;">{{product.hotel_name}}</td>
<td style="width:一五0px;"><b>No of rooms</b></td>
<td style="width:三00px;">{{product.no_of_rooms}}</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Location</b></td>
<td style="width:三00px;">{{product.city_code}}</td>
<td style="width:一五0px;">Room view</td>
<td style="width:三00px;">{{product.product_hotel_room_views.roomview_name}}</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Checkin</b></td>
<td style="width:三00px;">{{product.check_in| date:fullDate}}</td>
<td style="width:一五0px;">Room type</td>
<td style="width:三00px;">{{product.product_hotel_room_types.room_type_name}}</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Checkout</b></td>
<td style="width:三00px;">{{product.check_out| date:fullDate}}</td>
<td style="width:一五0px;">Board basis</td>
<td style="width:三00px;">{{product.product_hotel_board_basis.bb_name}}</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>No of nights</b></td>
<td style="width:三00px;">&nbsp;</td>
<td style="width:一五0px;">&nbsp;</td>
<td style="width:三00px;">&nbsp;</td>
  </tr>
  <tr>
<td colspan="四">
 <b>Passengers - Rooms</b>
 <div ng-repeat="item in product.product_hotel_room"><b>Adult :</b> {{item.adults}} and <b>Child :</b> {{item.child}}</div>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b></td>
<td>{{product.payable}}</td>
<td><b>Rate</b></td>
<td>{{product.rate}}</td>
  </tr>

 </table>
 <table width="六00" border="0" style="" ng-repeat="product_flight in invheader[0].invoice_flight">
  <tr>
<td><font color="red;">Flight Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Depatur City</b></td>
<td style="width:三00px;">{{product_flight.departure_city}}</td>
<td style="width:一五0px;"><b>Arrival City</b></td>
<td style="width:三00px;">{{product_flight.arrival_city}}</td>

  </tr>
  <tr>
<td style="width:一五0px;"><b>Depature date</b></td>
<td style="width:三00px;">{{product_flight.depature_date | date:fullDate}}</td>
<td style="width:一五0px;"><b>Arrival Date</b></td>
<td style="width:三00px;">{{product_flight.arrival_date | date:fullDate}}</td>
  </tr>

  <tr>
<td colspan="四">
 <b>Passengers</b>
 <br />
 <div ng-repeat="item_flight_pass in product_flight.invoice_flight_passengers"><b>Name :</b>{{item_flight_pass.title}}.{{item_flight_pass.first_name}}&nbsp;{{item_flight_pass.last_name}} </div>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp; {{product_flight.budget}}</td>
<td><b>Total</b>&nbsp;&nbsp; {{product_flight.total_sell_amt}} </td>
<td><b>Co妹妹ision</b>&nbsp;&nbsp; {{product_flight.co妹妹ission_on}}</td>
<td>&nbsp;</td>
  </tr>
 </table>
 <table width="六00" border="0" style="" ng-repeat="product_car in invheader[0].invoice_car">
  <tr>
<td><font color="red;">Car Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width: 一七8px;"><b>Pick Up</b></td>
<td style="width:三00px;">{{product_car.pickup}}</td>
<td style="width: 一七8px;"><b>Drop off</b></td>
<td style="width:三00px;">{{product_car.dropoff}}</td>
  </tr>
  <tr>
<td style="width: 一七8px;"><b>Pick Up date</b></td>
<td style="width:三00px;">{{product_car.datein | date:fullDate}}</td>
<td style="width: 一七8px;"><b>Drop off Date</b></td>
<td style="width:三00px;">{{product_car.dateout | date:fullDate}}</td>
  </tr>

  <tr>
<td style="width: 一七8px;"><b>Pick Up Time</b></td>
<td style="width:三00px;">{{product_car.timein | date:fullDate}}</td>
<td style="width: 一80px;"><b>Drop off Time</b></td>
<td style="width:三00px;">{{product_car.timeout | date:fullDate}}</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Car Type</b></td>
<td style="width:三00px;">{{product_car.type}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>

  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_car.payable}}</td>
<td><b>Total</b>&nbsp;&nbsp;{{product_car.buyamount}}</td>
<td><b>Co妹妹ision</b>&nbsp;&nbsp;{{product_car.co妹妹issionon}}</td>
<td>&nbsp;</td>
  </tr>
 </table>
 <table width="六00" border="0" style="" ng-repeat="product_tour in invheader[0].invoice_tour">

  <tr>
<td><font color="red;">Tour Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td>Tour Details</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Pick Up</b></td>
<td style="width:三00px;">{{product_tour.pick_up}}</td>
<td style="width:一五0px;"><b>Drop off</b></td>
<td style="width:三00px;">{{product_tour.drop_off}}</td>
  </tr>
  <tr>
<td style="width:一六五px;"><b>Pick Up date</b></td>
<td style="width:三00px;">{{product_tour.departure_date | date:fullDate}}</td>
<td style="width:一六五px;"><b>Drop off Date</b></td>
<td style="width:三00px;">{{product_tour.dateout | date:fullDate}}</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Pick Up Time</b></td>
<td style="width:三00px;">{{product_tour.timein | date:fullDate}}</td>
<td style="width:一六五px;"><b>Drop off Time</b></td>
<td style="width:三00px;">{{product_tour.timeout | date:fullDate}}</td>
  </tr>

  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_tour.payable}}</td>
<td><b>Total</b>&nbsp;&nbsp;{{product_tour.buyamount}}</td>
<td><b>Co妹妹ision</b>&nbsp;&nbsp;{{product_tour.co妹妹issionon}}</td>
<td>&nbsp;</td>
  </tr>
 </table>
 <table width="六00" border="0" style="" ng-repeat="product_rail in invheader[0].invoice_rail">
  <tr>
<td><font color="red;">Rail Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Departure</b></td>
<td style="width:三00px;">{{product_rail.departurecity}}</td>
<td style="width:一五0px;"><b>Arrival</b></td>
<td style="width:三00px;">{{product_rail.arrivalcity}}</td>
  </tr>
  <tr>
<td style="width:一六五px;"><b>Type</b></td>
<td style="width:三00px;">{{product_rail.type}}</td>

  </tr>

  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_rail.budget}}</td>
<td><b>Total</b>&nbsp;&nbsp;{{product_rail.amount}}</td>
<td style="width:一六五px;"><b>Quote Price</b>&nbsp;&nbsp;{{product_rail.quote_price}}</td>
<td>&nbsp;</td>
  </tr>
 </table>

 <table width="六00" border="0" style="" ng-repeat="product_transfer in invheader[0].invoice_transfers">
  <tr>
<td><font color="red;">Transfers Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>From City</b></td>
<td style="width:三00px;">{{product_transfer.from_city}}</td>
<td style="width:一五0px;"><b>To City</b></td>
<td style="width:三00px;">{{product_transfer.to_city}}</td>
  </tr>
  <tr>
<td style="width:一六五px;"><b>Vehicle Type</b></td>
<td style="width:三00px;">{{product_transfer.vehicle_type}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>

  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_transfer.budget}}</td>
<td><b>Buy Amount</b>&nbsp;&nbsp;{{product_transfer.amount}}</td>
<td style="width:一六五px;"><b>Payable</b>&nbsp;&nbsp;{{product_transfer.payable}}</td>
<td>&nbsp;</td>
  </tr>
 </table>
 <table width="六00" border="0" style="" ng-repeat="product_cruise in invheader[0].invoice_cruise">
  <tr>
<td><font color="red;">Cruise Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Departure City</b></td>
<td style="width:三00px;">{{product_cruise.departure_city}}</td>
<td style="width:一五0px;"><b>Arrival City</b></td>
<td style="width:三00px;">{{product_cruise.arrival_city}}</td>
  </tr>
  <tr>
<td style="width:一六五px;"><b>Type</b></td>
<td style="width:三00px;">{{product_cruise.vehicle_type}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Departure date</b></td>
<td style="width:三00px;">{{product_cruise.departure_date | date:fullDate}}</td>
<td style="width:一六五px;"><b>Arrival Date</b></td>
<td style="width:三00px;">{{product_cruise.arrival_date | date:fullDate}}</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Depature Time</b></td>
<td style="width:三00px;">{{product_cruise.departure_time | date:fullDate}}</td>
<td style="width:一六五px;"><b>Arivalo Time</b></td>
<td style="width:三00px;">{{product_cruise.arrival_time | date:fullDate}}</td>
  </tr>
  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_cruise.budget}}</td>
<td><b>Amount</b>&nbsp;&nbsp;{{product_cruise.amount}}</td>
<td style="width:一六五px;"><b>Co妹妹istion Amount</b>&nbsp;&nbsp;{{product_cruise.co妹妹ission_amount}}</td>
<td>&nbsp;</td>
  </tr>
 </table>

 <table width="六00" border="0" style="" ng-repeat="product_insurance in invheader[0].invoice_insurance">
  <tr>
<td><font color="red;">Insurance Details</font></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td style="width:一五0px;"><b>Departure City</b></td>
<td style="width:三00px;">{{product_insurance.departure_city}}</td>
<td style="width:一五0px;"><b>Arrival City</b></td>
<td style="width:三00px;">{{product_insurance.arrival_city}}</td>
  </tr>
  <tr>
<td style="width:一六五px;"><b>Type</b></td>
<td style="width:三00px;">{{product_insurance.vehicle_type}}</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Departure date</b></td>
<td style="width:三00px;">{{product_insurance.departure_date | date:fullDate}}</td>
<td style="width:一六五px;"><b>Arrival Date</b></td>
<td style="width:三00px;">{{product_insurance.arrival_date | date:fullDate}}</td>
  </tr>

  <tr>
<td style="width:一六五px;"><b>Depature Time</b></td>
<td style="width:三00px;">{{product_insurance.departure_time | date:fullDate}}</td>
<td style="width:一六五px;"><b>Arivalo Time</b></td>
<td style="width:三00px;">{{product_insurance.arrival_time | date:fullDate}}</td>
  </tr>
  <tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
  </tr>
  <tr>
<td><b>Budget</b>&nbsp;&nbsp;{{product_insurance.budget}}</td>
<td><b>Amount</b>&nbsp;&nbsp;{{product_insurance.amount}}</td>
<td style="width:一六五px;"><b>Co妹妹istion Amount</b>&nbsp;&nbsp;{{product_insurance.co妹妹ission_amount}}</td>
<td>&nbsp;</td>
  </tr>
 </table>


 <footer><img src="~/images/doc/header_footer/TOUR_Footer.png" width="六00" /></footer>

</div>

推举谜底

<div class="rightpan" id='printablediv'>
<p>Print Content</p>
<input type='button' id="cmd" value="Download" class="button一 sbtbutton" />
<div>
<div style="display: none;" id="editor"></div>


<script src="http://code.jquery.com/jquery⑵.一.一.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html二canvas/0.四.一/html二canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/一.五.三/jspdf.min.js"></script>

<script>
 var element = $("#printablediv"); // global variable
var getCanvas; // global variable

$("#cmd").on('click', function () {

 html二canvas(element, {
  onrendered: function (canvas) {
$("#editor").append(canvas);
getCanvas = canvas;

var img = canvas.toDataURL("image/png"),
doc = new jsPDF({
 unit: 'px',
 format: 'a四'
});
doc.addImage(img, 'JPEG', 二0, 二0);
doc.save('Vistordetails.pdf');
form.width(cache_width);
  }
 });
});

佳了闭于应用jsPDF将html导出为pdf的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。