-
Notifications
You must be signed in to change notification settings - Fork 100
/
example1.html
68 lines (65 loc) · 1.97 KB
/
example1.html
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
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
<script type="text/javascript" src="../rapipdf-min.js"></script>
<style>
rapi-pdf{ display:none; }
.btn-default {
font-size: 16px;
padding: 6px 16px;
text-align: center;
white-space: nowrap;
background-color:orangered;
color:white;
border: 0px solid #333;
cursor: pointer;
}
</style>
</head>
<body>
<rapi-pdf id="thedoc"> </rapi-pdf>
<button id="btn" class="btn-default" type="button">Generate PDF from JSON </button>
<script>
var btnEl = document.getElementById("btn");
btnEl.addEventListener('click', (ev) => {
let docEl = document.getElementById("thedoc");
let strSpec = `
{
"swagger": "2.0",
"info": { "description": "Sample to test" },
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"produces" : [ "application/json"],
"responses": {
"200": {
"description": "A list of pets.",
"schema": {
"type" : "array",
"items": { "$ref": "#/definitions/Pet"}
}
}
}
}
}
},
"definitions": {
"Pet": {
"type": "object",
"properties": {
"id" : { "type": "integer" },
"name": { "type": "string" },
"tag" : { "type": "string" }
}
}
}
}`;
let objSpec = JSON.parse(strSpec);
docEl.generatePdf(objSpec);
})
</script>
</body>
</html>