Wkhtmltopdf


Avant de commencer

Version 0.12.3 : Qt 4.8.5
Dépendances : zlib, fontconfig, freetype, X11 libs
Front
Front
$scope.print = ->
html = document.getElementsByTagName('html')[0]
body = {html: html}
$http.post('api/stored-files/print', body, responseType: 'arraybuffer')
.success (response) ->
file = new Blob [ response ], type: 'application/pdf'
FileSaver.saveAs file, 'dashboard.pdf'
"angular-file-saver": "1.1.0"FileSaver :
'ngFileSaver'Back
Back
StoredFile.print = (req, res, done) ->
html = req.body.html
projectLocation = __dirname + '/../../'
CSSLocation = projectLocation + 'client/www/style/' + 'main.css'
wkBinPath = projectLocation + 'bin/wkhtmltopdf'
wkhtmltopdf.command = wkBinPath
options =
'user-style-sheet': CSSLocation
stream = wkhtmltopdf html, options
res.set 'Content-Disposition', 'attachment; filename=transcript.pdf'
res.set 'Content-Type', "application/pdf"
stream.pipe res
donewkhtmltopdf = require 'wkhtmltopdf'"wkhtmltopdf": "0.1.5"Front V2
Front V2
body = {
html: DomManipulationService.processBeforePrint htmlElement
size: DomManipulationService.getSize htmlElement
realHeight: DomManipulationService.getRealHeight htmlElement
}getSize = (html) ->
width: html.offsetWidth
height: html.offsetHeightgetRealHeight = (html) ->
initial = html.style.height
html.style.height = 'auto'
realHeight = html.offsetHeight
html.style.height = initial
realHeightprocessBeforePrint = (html) ->
clone = angular.copy html
addPdfId clone
removeHeaderButton clone
removeScroll clone
removeBuildingChart clone
clone.outerHTMLBack V2
Back V2
# Change img src for absolute path
html = html.replace(/static\/images\//g, projectLocation + 'client/www/static/images/')options =
'viewport-size': size.width + 'x' + size.height
# I found a 0.271 ratio, and there is 20 margin
'page-width': (size.width * 0.271) + 20
'page-height': (realHeight * 0.271) + 20
'load-error-handling': 'ignore'
'margin-top': 10
'margin-bottom': 10
'margin-left': 10
'margin-right': 10
'user-style-sheet': CSSLocationQuoi d'autres ?
- Header / Footer
- Débugger
- ...
Wkhtmltopdf
By Vincent Langlet
Wkhtmltopdf
- 338