let data = "Rivermark Community Credit Union PO BOX 4044 Beaverton, OR 97076 First American Mortgage Solutions C/O American Pacific Mortgage Attn: Final Document Department Mail Stop: 152-C 1795 International Way Idaho Falls, ID 83402 First American Mortgage Solutions C/O American Pacific Mortgago Attn: Final Document Department - Mail Stop: 152-C 1795 International Way Idaho Falls, ID 83402 Columbia Credit Union P.O. Box 324 Vancouver, WA 98666 GUILD MORTGAGE C/O DOC PROBE MAIL STOP CODE: DP1960 1133 OCEAN AVENUE LAKEWOOD, NJ 08701 UNITED WHOLESALE MORTGAGE, LLC 585 SOUTH BOULEVARD E PONTIAC, MI 48341 Rocket Mortgage, LIC 1050 Woodward Ave Detroit, MI 48226-1906 Academy Mortgage Corporation Final Docs Department 339 West 13490 South Draper, UT 84020"
/*
insert \n after word if that word goes over the wrap count per line
*/
let length = 26;
let words = data.split(" ");
let lines = [""];
for (let i = 0; i < words.length; i++) {
words[i] = words[i].substr(0,1).toUpperCase() + words[i].substr(1,words[i].length).toLowerCase();
if (words[i] == "Lic") {
words[i] = "LLC"
}
if (words[i].length == 2) {
words[i] = words[i].toUpperCase();
}
if (lines[lines.length-1].length + words[i].length > length) {
if (words[i].length > length) {
//errpr
} else {
lines.push(lines.length + words[i]);
}
} else {
lines[lines.length -1] += " " + words[i];
}
}
lines = lines.join("\n")
var doc = new jsPDF()
doc.text(lines, 2, 6);
doc.save('labels.pdf')
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.