Skip to content

Commit 38bc719

Browse files
committed
Merge pull request #414 from Flamenco/fix-margin
[css] margin not working in html plugin #413
2 parents ec65985 + 912eaae commit 38bc719

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

jspdf.plugin.from_html.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 2014 Diego Casorran, https://github.com/diegocr
66
* 2014 Daniel Husar, https://github.com/danielhusar
77
* 2014 Wolfgang Gassler, https://github.com/woolfg
8+
* 2014 Steven Spungin, https://github.com/flamenco
89
*
910
* Permission is hereby granted, free of charge, to any person obtaining
1011
* a copy of this software and associated documentation files (the
@@ -811,13 +812,13 @@
811812
out,
812813
paragraphspacing_after,
813814
paragraphspacing_before,
814-
priorblockstype,
815+
priorblockstyle,
815816
styles,
816817
fontSize;
817818
fragments = PurgeWhiteSpace(this.paragraph.text);
818819
styles = this.paragraph.style;
819820
blockstyle = this.paragraph.blockstyle;
820-
priorblockstype = this.paragraph.blockstyle || {};
821+
priorblockstyle = this.paragraph.priorblockstyle || {};
821822
this.paragraph = {
822823
text : [],
823824
style : [],
@@ -832,8 +833,11 @@
832833
maxLineHeight = void 0;
833834
defaultFontSize = 12;
834835
fontToUnitRatio = defaultFontSize / this.pdf.internal.scaleFactor;
835-
paragraphspacing_before = (Math.max((blockstyle["margin-top"] || 0) - (priorblockstype["margin-bottom"] || 0), 0) + (blockstyle["padding-top"] || 0)) * fontToUnitRatio;
836+
this.priorMarginBottom = this.priorMarginBottom || 0;
837+
paragraphspacing_before = (Math.max((blockstyle["margin-top"] || 0) - this.priorMarginBottom, 0) + (blockstyle["padding-top"] || 0)) * fontToUnitRatio;
836838
paragraphspacing_after = ((blockstyle["margin-bottom"] || 0) + (blockstyle["padding-bottom"] || 0)) * fontToUnitRatio;
839+
this.priorMarginBottom = blockstyle["margin-bottom"] || 0;
840+
837841
out = this.pdf.internal.write;
838842
i = void 0;
839843
l = void 0;
@@ -863,8 +867,9 @@
863867
indentMove = wantedIndent - currentIndent;
864868
currentIndent = wantedIndent;
865869
}
870+
var indentMore = (Math.max(blockstyle["margin-left"] || 0, 0)) * fontToUnitRatio;
866871
//move the cursor
867-
out(indentMove, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
872+
out(indentMove + indentMore, (-1 * defaultFontSize * maxLineHeight).toFixed(2), "Td");
868873
i = 0;
869874
l = line.length;
870875
while (i !== l) {

0 commit comments

Comments
 (0)