JSFiddle - React, Tailwind, and code Playground

by frogggeee McFrogggeee

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.debug.js"></script>

JavaScript

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')