-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchromium.go
More file actions
364 lines (297 loc) · 11.7 KB
/
Copy pathchromium.go
File metadata and controls
364 lines (297 loc) · 11.7 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
package gotenberg
import (
"context"
"io"
"strconv"
"time"
)
// ConvertHTML creates a request to convert HTML content to PDF.
// The html parameter should contain the HTML content to be converted.
func (r *Chromium) ConvertHTML(ctx context.Context, html io.Reader) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/convert/html").File("files", "index.html", html)
return r
}
// ConvertURL creates a request to convert a web page at the given URL to PDF.
func (r *Chromium) ConvertURL(ctx context.Context, url string) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/convert/url").Param("url", url)
return r
}
// ConvertMarkdown creates a request to convert Markdown content to PDF.
func (r *Chromium) ConvertMarkdown(ctx context.Context, html io.Reader) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/convert/markdown").File("files", "index.html", html)
return r
}
// ScreenshotURL creates a request to take a screenshot of a web page at the given URL.
func (r *Chromium) ScreenshotURL(ctx context.Context, url string) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/screenshot/url").Param("url", url)
return r
}
// ScreenshotHTML creates a request to take a screenshot of HTML content.
func (r *Chromium) ScreenshotHTML(ctx context.Context, html io.Reader) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/screenshot/html").File("files", "index.html", html)
return r
}
// ScreenshotMarkdown creates a request to take a screenshot of Markdown content.
func (r *Chromium) ScreenshotMarkdown(ctx context.Context, html io.Reader) *Chromium {
r.Req = r.HttpStream.Multipart(ctx, "/forms/chromium/screenshot/markdown").File("files", "index.html", html)
return r
}
// Send executes the conversion request and returns the response.
func (r *Chromium) Send() (*Response, error) {
return r.Request.Send()
}
// Header adds an HTTP header to the conversion request.
func (r *Chromium) Header(key, value string) *Chromium {
r.Request.Header(key, value)
return r
}
// Param adds a form parameter to the conversion request.
func (r *Chromium) Param(key, value string) *Chromium {
r.Request.Param(key, value)
return r
}
// Bool adds a boolean form parameter to the conversion request.
func (r *Chromium) Bool(fieldName string, value bool) *Chromium {
r.Request.Bool(fieldName, value)
return r
}
// Float adds a float64 form parameter to the conversion request.
func (r *Chromium) Float(fieldName string, value float64) *Chromium {
r.Request.Float(fieldName, value)
return r
}
// File adds a file to the conversion request.
func (r *Chromium) File(filename string, content io.Reader) *Chromium {
r.Request.File(filename, content)
return r
}
// WebhookURL sets the webhook URL and HTTP method for successful conversions.
func (r *Chromium) WebhookURL(url, method string) *Chromium {
r.Request.WebhookURL(url, method)
return r
}
// WebhookErrorURL sets the webhook URL and HTTP method for failed conversions.
func (r *Chromium) WebhookErrorURL(url, method string) *Chromium {
r.Request.WebhookErrorURL(url, method)
return r
}
// WebhookEventsURL sets the webhook events URL for structured JSON event callbacks.
func (r *Chromium) WebhookEventsURL(url string) *Chromium {
r.Request.WebhookEventsURL(url)
return r
}
// WebhookHeader adds a custom header to be sent with webhook requests.
func (r *Chromium) WebhookHeader(key, value string) *Chromium {
r.Request.WebhookHeader(key, value)
return r
}
// DownloadFrom sets the downloadFrom parameter for downloading files from URLs.
func (r *Chromium) DownloadFrom(url string, headers map[string]string) *Chromium {
r.Request.DownloadFrom(url, headers)
return r
}
// OutputFilename sets the output filename for the generated PDF.
func (r *Chromium) OutputFilename(filename string) *Chromium {
r.Request.OutputFilename(filename)
return r
}
// Trace sets the request trace identifier for debugging and monitoring.
func (r *Chromium) Trace(trace string) *Chromium {
r.Request.Trace(trace)
return r
}
// Timeout sets a timeout for the request.
func (r *Chromium) Timeout(duration time.Duration) *Chromium {
r.Request.Timeout(duration)
return r
}
// Metadata sets the metadata for the operation.
func (r *Chromium) Metadata(key, value string) *Chromium {
r.Request.Metadata(key, value)
return r
}
// ScreenshotWidth sets the device screen width in pixels.
func (r *Chromium) ScreenshotWidth(width int) *Chromium {
return r.Param("width", strconv.Itoa(width))
}
// ScreenshotHeight sets the device screen height in pixels.
func (r *Chromium) ScreenshotHeight(height int) *Chromium {
return r.Param("height", strconv.Itoa(height))
}
// ScreenshotClip defines whether to clip the screenshot according to the device dimensions.
func (r *Chromium) ScreenshotClip(clip bool) *Chromium {
return r.Bool("clip", clip)
}
// ScreenshotFormat sets the image compression format.
func (r *Chromium) ScreenshotFormat(format string) *Chromium {
return r.Param("format", format)
}
// ScreenshotQuality sets the compression quality from range 0 to 100 (jpeg only).
func (r *Chromium) ScreenshotQuality(quality int) *Chromium {
return r.Param("quality", strconv.Itoa(quality))
}
// ScreenshotOmitBackground hides the default white background and allows generating screenshots with transparency.
func (r *Chromium) ScreenshotOmitBackground(omit bool) *Chromium {
return r.Bool("omitBackground", omit)
}
// ScreenshotOptimizeForSpeed defines whether to optimize image encoding for speed, not for resulting size.
func (r *Chromium) ScreenshotOptimizeForSpeed(optimize bool) *Chromium {
return r.Bool("optimizeForSpeed", optimize)
}
// PaperSize sets the paper size for the PDF using width and height in inches.
func (r *Chromium) PaperSize(width, height float64) *Chromium {
return r.PaperWidth(width).PaperHeight(height)
}
// PaperSizeA4 sets the paper size to A4 format.
func (r *Chromium) PaperSizeA4() *Chromium {
return r.PaperSize(8.27, 11.7)
}
// PaperSizeA6 sets the paper size to A6 format.
func (r *Chromium) PaperSizeA6() *Chromium {
return r.PaperSize(4.13, 5.83)
}
// PaperSizeLetter sets the paper size to Letter format.
func (r *Chromium) PaperSizeLetter() *Chromium {
return r.PaperSize(8.5, 11)
}
// Margins sets the page margins for the PDF in inches.
func (r *Chromium) Margins(top, right, bottom, left float64) *Chromium {
return r.MarginTop(top).MarginRight(right).MarginBottom(bottom).MarginLeft(left)
}
// SinglePage sets whether to print the entire content in one single page.
func (r *Chromium) SinglePage() *Chromium {
return r.Bool("singlePage", true)
}
// PaperWidth sets the paper width in inches.
func (r *Chromium) PaperWidth(value float64) *Chromium {
return r.Float("paperWidth", value)
}
// PaperHeight sets the paper height in inches.
func (r *Chromium) PaperHeight(value float64) *Chromium {
return r.Float("paperHeight", value)
}
// MarginTop sets the top margin in inches.
func (r *Chromium) MarginTop(value float64) *Chromium {
return r.Float("marginTop", value)
}
// MarginBottom sets the bottom margin in inches.
func (r *Chromium) MarginBottom(value float64) *Chromium {
return r.Float("marginBottom", value)
}
// MarginLeft sets the left margin in inches.
func (r *Chromium) MarginLeft(value float64) *Chromium {
return r.Float("marginLeft", value)
}
// MarginRight sets the right margin in inches.
func (r *Chromium) MarginRight(value float64) *Chromium {
return r.Float("marginRight", value)
}
// PreferCssPageSize sets whether to prefer page size as defined by CSS.
func (r *Chromium) PreferCssPageSize() *Chromium {
return r.Bool("preferCssPageSize", true)
}
// GenerateDocumentOutline sets whether the document outline should be embedded into the PDF.
func (r *Chromium) GenerateDocumentOutline() *Chromium {
return r.Bool("generateDocumentOutline", true)
}
// GenerateTaggedPdf sets whether to generate tagged (accessible) PDF.
func (r *Chromium) GenerateTaggedPdf() *Chromium {
return r.Bool("generateTaggedPdf", true)
}
// PrintBackground sets whether to print the background graphics.
func (r *Chromium) PrintBackground() *Chromium {
return r.Bool("printBackground", true)
}
// OmitBackground hides the default white background and allows generating PDFs with transparency.
func (r *Chromium) OmitBackground() *Chromium {
return r.Bool("omitBackground", true)
}
// Landscape sets the paper orientation to landscape.
func (r *Chromium) Landscape() *Chromium {
return r.Bool("landscape", true)
}
// Scale sets the scale of the page rendering.
func (r *Chromium) Scale(value float64) *Chromium {
return r.Float("scale", value)
}
// NativePageRanges sets the page ranges to print, e.g., '1-5, 8, 11-13'.
func (r *Chromium) NativePageRanges(value string) *Chromium {
return r.Param("nativePageRanges", value)
}
// WaitDelay sets the duration to wait when loading an HTML document before converting it into PDF.
func (r *Chromium) WaitDelay(value string) *Chromium {
return r.Param("waitDelay", value)
}
// WaitForExpression sets the JavaScript expression to wait before converting an HTML document into PDF.
func (r *Chromium) WaitForExpression(value string) *Chromium {
return r.Param("waitForExpression", value)
}
// WaitForSelector waits for a specific node matching the given CSS selector to become visible before converting.
func (r *Chromium) WaitForSelector(selector string) *Chromium {
return r.Param("waitForSelector", selector)
}
// IgnoreResourceHttpStatusDomains excludes resources from check.
func (r *Chromium) IgnoreResourceHttpStatusDomains(domainsJSON string) *Chromium {
return r.Param("ignoreResourceHttpStatusDomains", domainsJSON)
}
// EmulatedMediaFeatures sets CSS media features to simulate.
func (r *Chromium) EmulatedMediaFeatures(featuresJSON string) *Chromium {
return r.Param("emulatedMediaFeatures", featuresJSON)
}
// SkipNetworkAlmostIdleEvent controls network wait.
func (r *Chromium) SkipNetworkAlmostIdleEvent(skip bool) *Chromium {
return r.Bool("skipNetworkAlmostIdleEvent", skip)
}
// EmbedsMetadata sets per-file metadata.
func (r *Chromium) EmbedsMetadata(metadataJSON string) *Chromium {
return r.Param("embedsMetadata", metadataJSON)
}
// ScreenshotDeviceScaleFactor controls the pixel density.
func (r *Chromium) ScreenshotDeviceScaleFactor(factor float64) *Chromium {
return r.Float("deviceScaleFactor", factor)
}
// UserPassword sets the password required to open the PDF.
func (r *Chromium) UserPassword(password string) *Chromium {
r.Request.UserPassword(password)
return r
}
// OwnerPassword sets the password required to change permissions or edit the PDF.
func (r *Chromium) OwnerPassword(password string) *Chromium {
r.Request.OwnerPassword(password)
return r
}
// AllowPrinting permits printing the document.
func (r *Chromium) AllowPrinting(allow bool) *Chromium {
r.Request.AllowPrinting(allow)
return r
}
// AllowCopying permits extracting text and graphics.
func (r *Chromium) AllowCopying(allow bool) *Chromium {
r.Request.AllowCopying(allow)
return r
}
// AllowModifying permits changing the document content.
func (r *Chromium) AllowModifying(allow bool) *Chromium {
r.Request.AllowModifying(allow)
return r
}
// AllowAnnotating permits adding or modifying annotations.
func (r *Chromium) AllowAnnotating(allow bool) *Chromium {
r.Request.AllowAnnotating(allow)
return r
}
// AllowFillingForms permits filling in form fields.
func (r *Chromium) AllowFillingForms(allow bool) *Chromium {
r.Request.AllowFillingForms(allow)
return r
}
// AllowAssembling permits inserting, deleting, and rotating pages.
func (r *Chromium) AllowAssembling(allow bool) *Chromium {
r.Request.AllowAssembling(allow)
return r
}
// Embeds adds a file to be embedded in the resulting PDF.
func (r *Chromium) Embeds(filename string, content io.Reader) *Chromium {
r.Request.Embeds(filename, content)
return r
}