Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bold Half Words (made by ChatGPT)</title>
- <style>
- body {
- background-color: lightyellow;
- font-family: sans-serif;
- }
- </style>
- </head>
- <body>
- <h1>Bold Half Words</h1>
- <label for="input">Input:</label>
- <br>
- <textarea id="input" rows="10" cols="50" oninput="boldHalf()"></textarea>
- <br>
- <button onclick="downloadPdf()">Download PDF</button>
- <br>
- <label for="output">Output:</label>
- <br>
- <div id="output"></div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.min.js"></script>
- <script>
- function boldHalf() {
- // Get input text and split into words
- var inputText = document.getElementById("input").value;
- var words = inputText.split(/\b/);
- // Create output text with first half of each word in bold
- var outputText = "";
- for (var i = 0; i < words.length; i++) {
- var word = words[i];
- if (/\w/.test(word)) {
- var halfLength = Math.floor(word.length / 2);
- outputText += "<b>" + word.slice(0, halfLength) + "</b>" + word.slice(halfLength);
- } else {
- outputText += word;
- }
- }
- // Display output text
- document.getElementById("output").innerHTML = outputText;
- }
- function downloadPdf() {
- // Get output text
- var outputText = document.getElementById("output").innerHTML;
- // Convert output text to PDF
- var element = document.createElement("div");
- element.innerHTML = outputText;
- html2pdf(element, {
- margin: [10, 10, 10, 10],
- filename: "bold_half_words.pdf",
- image: { type: 'jpeg', quality: 0.98 },
- html2canvas: { dpi: 192, letterRendering: true },
- jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
- });
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment