Skip to content

Commit a91a3c9

Browse files
committed
Merge pull request #1 from marcbachmann/image-support
Support remote images in pdf
2 parents 613840d + 3f3a36d commit a91a3c9

4 files changed

Lines changed: 51 additions & 18 deletions

File tree

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.2.0
2+
=====
3+
- Support remote images in html template
4+
5+
16
0.1.3
27
=====
38
- Update phantomjs node module dependency, some cdn changed

lib/scripts/pdf_a4_portrait.coffee

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,23 @@ else
5656

5757
page.paperSize = paperSize
5858

59+
page.onLoadFinished = (status) ->
60+
# Output to parent process
61+
fileOptions =
62+
type: options.type || 'pdf'
63+
quality: options.quality || 75
5964

65+
# Option 1: Output file to stdout
66+
# Not working in Ubuntu 12.04 (at least not in my environment)
67+
if options.buffer
68+
page.render('/dev/stdout', fileOptions)
6069

61-
# Output to parent process
62-
fileOptions =
63-
type: options.type || 'pdf'
64-
quality: options.quality || 75
6570

66-
# Option 1: Output file to stdout
67-
# Not working in Ubuntu 12.04 (at least not in my environment)
68-
if options.buffer
69-
page.render('/dev/stdout', fileOptions)
70-
71-
72-
# Option 2: Output filename to stdout
73-
else
74-
filename = options.filename || ("#{options.directory || '/tmp'}/html-pdf-#{sys.pid}-#{size}.#{fileOptions.type}")
75-
page.render(filename, fileOptions)
76-
sys.stdout.write(filename)
71+
# Option 2: Output filename to stdout
72+
else
73+
filename = options.filename || ("#{options.directory || '/tmp'}/html-pdf-#{sys.pid}-#{size}.#{fileOptions.type}")
74+
page.render(filename, fileOptions)
75+
sys.stdout.write(filename)
7776

7877

79-
phantom.exit(0)
78+
phantom.exit(0)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-pdf",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "HTML to PDF converter that uses phantomjs",
55
"main": "index.js",
66
"directories": {

test/businesscard.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,46 @@
2222
}
2323

2424
.group {
25-
margin-top: 6mm;
25+
margin-top: 3mm;
2626
}
2727

2828
.line {
2929
color: white;
3030
position: relative;
3131
}
32+
33+
.ghost {
34+
position: relative;
35+
text-align: center;
36+
-webkit-transform: scale(0.6);
37+
}
38+
39+
.ghost .body {
40+
z-index: 1;
41+
position: relative;
42+
height: 176px;
43+
width: 125px;
44+
}
45+
46+
.ghost .eyes {
47+
z-index: 10;
48+
position: absolute;
49+
left: 50%;
50+
margin-left: -22px;
51+
top: 25%;
52+
width: 44px;
53+
height: 25px;
54+
background: url('http://static.suitart.com/templates/eyes.gif');
55+
}
56+
3257
</style>
3358
</head>
3459
<body>
3560
<div class="bottom">
61+
<div class="ghost">
62+
<div class="eyes"></div>
63+
<img class="body" src="http://static.suitart.com/templates/ghost.png">
64+
</div>
3665
<div class="line">Marc Bachmann</div>
3766
<div class="line">cto</div>
3867

0 commit comments

Comments
 (0)