Reputation: 1060
I am using asppdf to create a PDF from HTML.
It looks like your HTML needs to be in a single line with all whitespace removed, before its passed to the ImportFromUrl method, this is an example from the support site:
str = "<HTML><TABLE><TR><TD>Text1</TD><TD>Text2</TD></TR></TABLE></HTML>"
Doc.ImportFromUrl str
Currently my HTML is pulled in from an external page & it's all formatted, so i need it to be like the above example. Can I use jQuery to do this?
Reference http://www.asppdf.com/manual_13.html#13_5
Upvotes: 1
Views: 5611
Reputation: 606
i use regex "someHtml".replace(/\n\s+|\n/g, "")
. It's not perfect but it will keep the content intact an delete most of the unnecessary white spaces.
var dom = document.documentElement.outerHTML;
$("body").text(dom.replace(/\n\s+|\n/g, ""));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
lorem ipsum
</div>
<div>
more text
</div> <div>
test 123
</div>
Upvotes: 3
Reputation: 4391
Use this regular expression for spaces only:
var HTML = "<h1>hh ee</h1> <h2>heyy heyyy</h2>";
document.getElementById("after").innerText = HTML.replace(/>[ ]+</g, "><");
document.getElementById("before").innerText = HTML;
<h1 id="before"></h1>
Becomes
<h1 id="after"></h1>
var HTML = "<h1>hh ee</h1> <h2>heyy heyyy</h2>";
document.getElementById("after").innerText = HTML.replace(/>[\n\t ]+</g, "><");
document.getElementById("before").innerText = HTML;
<h1 id="before"></h1>
Becomes
<h1 id="after"></h1>
Upvotes: 3