使用jsPDF将html导出为pdf

时间:2015-11-17 03:54:27

标签: javascript pdf pdf-generation jspdf export-to-pdf

您好我想将html导出为pdf,我已经使用jsPDF所有正在工作的pdf也导出但我想在pdf中获得相同的HTML,html样式不起作用我可以做什么,任何人都可以帮助我吗?他们有什么办法在jsPDF中使用html样式?这是我的HTML代码。我从这个链接http://jsfiddle.net/xzZ7n/1/

获得了一个脚本函数
   <div class="panel col-xs-12 col-sm-12 col-md-11" style="" id="quotation">


    <header><img src="~/images/doc/header_footer/TOUR_Header.png" width="600" /></header>
    <table width="600" border="0" style="font-size:12px;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="300" border="0" style="font-size:12px;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="600" 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:150px;"><b>Hotel name</b></td>
            <td style="width:300px;">{{product.hotel_name}}</td>
            <td style="width:150px;"><b>No of rooms</b></td>
            <td style="width:300px;">{{product.no_of_rooms}}</td>
        </tr>
        <tr>
            <td style="width:150px;"><b>Location</b></td>
            <td style="width:300px;">{{product.city_code}}</td>
            <td style="width:150px;">Room view</td>
            <td style="width:300px;">{{product.product_hotel_room_views.roomview_name}}</td>
        </tr>
        <tr>
            <td style="width:150px;"><b>Checkin</b></td>
            <td style="width:300px;">{{product.check_in| date:fullDate}}</td>
            <td style="width:150px;">Room type</td>
            <td style="width:300px;">{{product.product_hotel_room_types.room_type_name}}</td>
        </tr>
        <tr>
            <td style="width:150px;"><b>Checkout</b></td>
            <td style="width:300px;">{{product.check_out| date:fullDate}}</td>
            <td style="width:150px;">Board basis</td>
            <td style="width:300px;">{{product.product_hotel_board_basis.bb_name}}</td>
        </tr>
        <tr>
            <td style="width:150px;"><b>No of nights</b></td>
            <td style="width:300px;">&nbsp;</td>
            <td style="width:150px;">&nbsp;</td>
            <td style="width:300px;">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="4">
                <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="600" 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:150px;"><b>Depatur City</b></td>
            <td style="width:300px;">{{product_flight.departure_city}}</td>
            <td style="width:150px;"><b>Arrival City</b></td>
            <td style="width:300px;">{{product_flight.arrival_city}}</td>

        </tr>
        <tr>
            <td style="width:150px;"><b>Depature date</b></td>
            <td style="width:300px;">{{product_flight.depature_date | date:fullDate}}</td>
            <td style="width:150px;"><b>Arrival Date</b></td>
            <td style="width:300px;">{{product_flight.arrival_date | date:fullDate}}</td>
        </tr>

        <tr>
            <td colspan="4">
                <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>Commision</b>&nbsp;&nbsp; {{product_flight.commission_on}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>
    <table width="600" 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: 178px;"><b>Pick Up</b></td>
            <td style="width:300px;">{{product_car.pickup}}</td>
            <td style="width: 178px;"><b>Drop off</b></td>
            <td style="width:300px;">{{product_car.dropoff}}</td>
        </tr>
        <tr>
            <td style="width: 178px;"><b>Pick Up date</b></td>
            <td style="width:300px;">{{product_car.datein | date:fullDate}}</td>
            <td style="width: 178px;"><b>Drop off Date</b></td>
            <td style="width:300px;">{{product_car.dateout | date:fullDate}}</td>
        </tr>

        <tr>
            <td style="width: 178px;"><b>Pick Up Time</b></td>
            <td style="width:300px;">{{product_car.timein | date:fullDate}}</td>
            <td style="width: 180px;"><b>Drop off Time</b></td>
            <td style="width:300px;">{{product_car.timeout | date:fullDate}}</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Car Type</b></td>
            <td style="width:300px;">{{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>Commision</b>&nbsp;&nbsp;{{product_car.commissionon}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>
    <table width="600" 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:150px;"><b>Pick Up</b></td>
            <td style="width:300px;">{{product_tour.pick_up}}</td>
            <td style="width:150px;"><b>Drop off</b></td>
            <td style="width:300px;">{{product_tour.drop_off}}</td>
        </tr>
        <tr>
            <td style="width:165px;"><b>Pick Up date</b></td>
            <td style="width:300px;">{{product_tour.departure_date | date:fullDate}}</td>
            <td style="width:165px;"><b>Drop off Date</b></td>
            <td style="width:300px;">{{product_tour.dateout | date:fullDate}}</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Pick Up Time</b></td>
            <td style="width:300px;">{{product_tour.timein | date:fullDate}}</td>
            <td style="width:165px;"><b>Drop off Time</b></td>
            <td style="width:300px;">{{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>Commision</b>&nbsp;&nbsp;{{product_tour.commissionon}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>
    <table width="600" 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:150px;"><b>Departure</b></td>
            <td style="width:300px;">{{product_rail.departurecity}}</td>
            <td style="width:150px;"><b>Arrival</b></td>
            <td style="width:300px;">{{product_rail.arrivalcity}}</td>
        </tr>
        <tr>
            <td style="width:165px;"><b>Type</b></td>
            <td style="width:300px;">{{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:165px;"><b>Quote Price</b>&nbsp;&nbsp;{{product_rail.quote_price}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>

    <table width="600" 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:150px;"><b>From City</b></td>
            <td style="width:300px;">{{product_transfer.from_city}}</td>
            <td style="width:150px;"><b>To City</b></td>
            <td style="width:300px;">{{product_transfer.to_city}}</td>
        </tr>
        <tr>
            <td style="width:165px;"><b>Vehicle Type</b></td>
            <td style="width:300px;">{{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:165px;"><b>Payable</b>&nbsp;&nbsp;{{product_transfer.payable}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>
    <table width="600" 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:150px;"><b>Departure City</b></td>
            <td style="width:300px;">{{product_cruise.departure_city}}</td>
            <td style="width:150px;"><b>Arrival City</b></td>
            <td style="width:300px;">{{product_cruise.arrival_city}}</td>
        </tr>
        <tr>
            <td style="width:165px;"><b>Type</b></td>
            <td style="width:300px;">{{product_cruise.vehicle_type}}</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Departure date</b></td>
            <td style="width:300px;">{{product_cruise.departure_date | date:fullDate}}</td>
            <td style="width:165px;"><b>Arrival Date</b></td>
            <td style="width:300px;">{{product_cruise.arrival_date | date:fullDate}}</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Depature Time</b></td>
            <td style="width:300px;">{{product_cruise.departure_time | date:fullDate}}</td>
            <td style="width:165px;"><b>Arivalo Time</b></td>
            <td style="width:300px;">{{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:165px;"><b>Commistion Amount</b>&nbsp;&nbsp;{{product_cruise.commission_amount}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>

    <table width="600" 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:150px;"><b>Departure City</b></td>
            <td style="width:300px;">{{product_insurance.departure_city}}</td>
            <td style="width:150px;"><b>Arrival City</b></td>
            <td style="width:300px;">{{product_insurance.arrival_city}}</td>
        </tr>
        <tr>
            <td style="width:165px;"><b>Type</b></td>
            <td style="width:300px;">{{product_insurance.vehicle_type}}</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Departure date</b></td>
            <td style="width:300px;">{{product_insurance.departure_date | date:fullDate}}</td>
            <td style="width:165px;"><b>Arrival Date</b></td>
            <td style="width:300px;">{{product_insurance.arrival_date | date:fullDate}}</td>
        </tr>

        <tr>
            <td style="width:165px;"><b>Depature Time</b></td>
            <td style="width:300px;">{{product_insurance.departure_time | date:fullDate}}</td>
            <td style="width:165px;"><b>Arivalo Time</b></td>
            <td style="width:300px;">{{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:165px;"><b>Commistion Amount</b>&nbsp;&nbsp;{{product_insurance.commission_amount}}</td>
            <td>&nbsp;</td>
        </tr>
    </table>


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

</div>

2 个答案:

答案 0 :(得分:2)

Sub HowTo_GetFileList()
    Const MATCHVALUE As String = "Demo"
    Dim f, FileList, FilteredList
    FileList = getFileList("C:\Users\Owner\Downloads")
    FilteredList = Filter(FileList, MATCHVALUE)

    For Each f In FilteredList
        'Do Something
    Next

End Sub

Function getFileList(localRoot As String, Optional fld, Optional ftpArray)
    Dim fso, f, baseFolder, subFolder, ftpFile, i

    Set fso = CreateObject("Scripting.Filesystemobject")

    If IsMissing(fld) Then
        Set baseFolder = fso.GetFolder(localRoot)
    Else
        Set baseFolder = fld
    End If

    For Each f In baseFolder.Files

        If IsMissing(ftpArray) Then
            ReDim ftpArray(0)
        Else
            i = UBound(ftpArray) + 1
            ReDim Preserve ftpArray(i)
        End If
        ftpArray(i) = f.Path

    Next

    For Each subFolder In baseFolder.SubFolders
        getFileList localRoot, subFolder, ftpArray
    Next

    getFileList = ftpArray
End Function

答案 1 :(得分:1)

迟到的答案!!

  1. 使用Html2Canvas插件将div转换为画布

  2. 然后将画布图像添加到JsPDF doc