-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
58 lines (47 loc) · 1.2 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
$(document).ready(function ()
{
$("#uiGen").click(GenPDF);
});
function GenPDF()
{
// Get the text (vary this)
let txt = $("#uiTxt").val();
// Get jsPDF object
const { jsPDF } = window.jspdf;
// Create a document
var doc = new jsPDF('p', 'mm', 'letter', true);
// Write out the text
doc.text(txt, 10, 10);
// Set the filename
let file = $("#uiRnd").prop('checked') ? crypto.randomUUID() : "mypdf";
if (iOS())
{
// Create an anchor
let a = document.createElement("a")
// Set anchor properties
a.download = file;
a.href = doc.output('bloburl');
// Simulate a click
a.click();
// Remove the anchor again
document.body.removeChild(a)
}
else
{
// A random name is always generated automatically on Windows-Chrome
window.open(doc.output('bloburl'));
}
}
function iOS()
{
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}