polotno-node 0.3.13 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,27 +37,6 @@ run();
37
37
 
38
38
  ## API
39
39
 
40
- ### `instance.run()`
41
-
42
- Run any Polotno store API directly inside web-page context
43
-
44
- ```js
45
- // we can't directly use "json" variable inside the run function
46
- // we MUST pass it as the second argument
47
- const url = await instance.run(async (json) => {
48
- // you can use global "config" object that has some functions from "polotno/config" module
49
- window.config.addGlobalFont({
50
- name: 'MyCustomFont',
51
- url: 'https://example.com/font.otf',
52
- });
53
-
54
- // you can use global "store" object
55
- store.loadJSON(json);
56
- await store.waitLoading();
57
- return store.toDataURL();
58
- }, json);
59
- ```
60
-
61
40
  ### `instance.jsonToDataURL(json, attrs)`
62
41
 
63
42
  Export json into data URL.
@@ -65,8 +44,15 @@ Export json into data URL.
65
44
  ```js
66
45
  const json = JSON.parse(fs.readFileSync('polotno.json'));
67
46
 
47
+ // by default it will export first page only
68
48
  const url = await instance.jsonToDataURL(json);
69
49
  res.json({ url });
50
+
51
+ // export many pages:
52
+ for (const page of json.pages) {
53
+ const url = await instance.jsonToDataURL(json, { pageId: page.id });
54
+ // do something with url
55
+ }
70
56
  ```
71
57
 
72
58
  ### `instance.jsonToImageBase64(json, attrs)`
@@ -76,10 +62,19 @@ Export json into base64 string of image.
76
62
  ```js
77
63
  const json = JSON.parse(fs.readFileSync('polotno.json'));
78
64
 
65
+ // by default it will export first page only
79
66
  const imageBase64 = await instance.jsonToImageBase64(json, {
80
67
  mimeType: 'image/png',
81
68
  }); // also 'image/jpeg' is supported
82
69
  fs.writeFileSync('out.png', imageBase64, 'base64');
70
+
71
+ // export many pages:
72
+ for (const page of json.pages) {
73
+ const imageBase64 = await instance.jsonToImageBase64(json, {
74
+ pageId: page.id,
75
+ });
76
+ // do something with base64
77
+ }
83
78
  ```
84
79
 
85
80
  ### `instance.jsonToPDFBase64(json, attrs)`
@@ -89,6 +84,7 @@ Export json into base64 string of pdf file.
89
84
  ```js
90
85
  const json = JSON.parse(fs.readFileSync('polotno.json'));
91
86
 
87
+ // it will export all pages in the JSON
92
88
  const pdfBase64 = await instance.jsonToPDFBase64(json);
93
89
  fs.writeFileSync('out.pdf', pdfBase64, 'base64');
94
90
  ```
@@ -104,6 +100,27 @@ const url = await instance.jsonToPDFDataURL(json);
104
100
  res.json({ url });
105
101
  ```
106
102
 
103
+ ### `instance.run()`
104
+
105
+ Run any Polotno store API directly inside web-page context
106
+
107
+ ```js
108
+ // we can't directly use "json" variable inside the run function
109
+ // we MUST pass it as the second argument
110
+ const url = await instance.run(async (json) => {
111
+ // you can use global "config" object that has some functions from "polotno/config" module
112
+ window.config.addGlobalFont({
113
+ name: 'MyCustomFont',
114
+ url: 'https://example.com/font.otf',
115
+ });
116
+
117
+ // you can use global "store" object
118
+ store.loadJSON(json);
119
+ await store.waitLoading();
120
+ return store.toDataURL();
121
+ }, json);
122
+ ```
123
+
107
124
  ## Browserless usage
108
125
 
109
126
  By default `polotno-node` will import browser bundle using `chrome-aws-lambda`. But you can use `browserless` instead, to keep your cloud function smaller.