polotno-node 0.3.14 → 1.1.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,18 @@ 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(
54
+ { ...json, pages: [page] }, // for optimization, we can modify JSON to include only one page
55
+ { pageId: page.id }
56
+ );
57
+ // do something with url
58
+ }
70
59
  ```
71
60
 
72
61
  ### `instance.jsonToImageBase64(json, attrs)`
@@ -76,10 +65,20 @@ Export json into base64 string of image.
76
65
  ```js
77
66
  const json = JSON.parse(fs.readFileSync('polotno.json'));
78
67
 
68
+ // by default it will export first page only
79
69
  const imageBase64 = await instance.jsonToImageBase64(json, {
80
70
  mimeType: 'image/png',
81
71
  }); // also 'image/jpeg' is supported
82
72
  fs.writeFileSync('out.png', imageBase64, 'base64');
73
+
74
+ // export many pages:
75
+ for (const page of json.pages) {
76
+ const imageBase64 = await instance.jsonToImageBase64(
77
+ { ...json, pages: [page] }, // for optimization, we can modify JSON to include only one page
78
+ { pageId: page.id }
79
+ );
80
+ // do something with base64
81
+ }
83
82
  ```
84
83
 
85
84
  ### `instance.jsonToPDFBase64(json, attrs)`
@@ -89,6 +88,7 @@ Export json into base64 string of pdf file.
89
88
  ```js
90
89
  const json = JSON.parse(fs.readFileSync('polotno.json'));
91
90
 
91
+ // it will export all pages in the JSON
92
92
  const pdfBase64 = await instance.jsonToPDFBase64(json);
93
93
  fs.writeFileSync('out.pdf', pdfBase64, 'base64');
94
94
  ```
@@ -104,6 +104,27 @@ const url = await instance.jsonToPDFDataURL(json);
104
104
  res.json({ url });
105
105
  ```
106
106
 
107
+ ### `instance.run()`
108
+
109
+ Run any Polotno store API directly inside web-page context
110
+
111
+ ```js
112
+ // we can't directly use "json" variable inside the run function
113
+ // we MUST pass it as the second argument
114
+ const url = await instance.run(async (json) => {
115
+ // you can use global "config" object that has some functions from "polotno/config" module
116
+ window.config.addGlobalFont({
117
+ name: 'MyCustomFont',
118
+ url: 'https://example.com/font.otf',
119
+ });
120
+
121
+ // you can use global "store" object
122
+ store.loadJSON(json);
123
+ await store.waitLoading();
124
+ return store.toDataURL();
125
+ }, json);
126
+ ```
127
+
107
128
  ## Browserless usage
108
129
 
109
130
  By default `polotno-node` will import browser bundle using `chrome-aws-lambda`. But you can use `browserless` instead, to keep your cloud function smaller.