-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg_to_pdf.html
288 lines (285 loc) · 68.1 KB
/
svg_to_pdf.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
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
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="generator" content="VuePress 2.0.0-rc.20" />
<style>
:root {
--vp-c-bg: #fff;
}
[data-theme='dark'] {
--vp-c-bg: #1b1b1f;
}
html,
body {
background-color: var(--vp-c-bg);
}
</style>
<script>
const useChoice = localStorage.getItem('vuepress-color-scheme')
const systemStatus =
'matchMedia' in window
? window.matchMedia('(prefers-color-scheme: dark)').matches
: false
if (useChoice === 'light') {
document.documentElement.dataset.theme = 'light'
} else if (useChoice === 'dark' || systemStatus) {
document.documentElement.dataset.theme = 'dark'
}
</script>
<link rel="icon" href="https://static.pdfai.cn/favicon.ico"><title>SVG转PDF | 宝石PDF - 文档</title><meta name="description" content="宝石PDF文档和API">
<link rel="preload" href="/docs/assets/style-Cmsfp_Jz.css" as="style"><link rel="stylesheet" href="/docs/assets/style-Cmsfp_Jz.css">
<link rel="modulepreload" href="/docs/assets/app-Df7hc8Qg.js"><link rel="modulepreload" href="/docs/assets/svg_to_pdf.html-C9f0oj6G.js">
<link rel="prefetch" href="/docs/assets/index.html-B6vJKCG0.js" as="script"><link rel="prefetch" href="/docs/assets/deployment.html-CNXbwVvv.js" as="script"><link rel="prefetch" href="/docs/assets/faq.html-CpRM9oM9.js" as="script"><link rel="prefetch" href="/docs/assets/get-started.html-ay9UNq6T.js" as="script"><link rel="prefetch" href="/docs/assets/note.html-BzPB0_F6.js" as="script"><link rel="prefetch" href="/docs/assets/readme.bak.html-BP-C5Xq4.js" as="script"><link rel="prefetch" href="/docs/assets/a5_to_a4.html-Bt-KvIEm.js" as="script"><link rel="prefetch" href="/docs/assets/comcompress_pdf.html-CVCTn5-6.js" as="script"><link rel="prefetch" href="/docs/assets/image_to_pdf.html-CoYbrIGf.js" as="script"><link rel="prefetch" href="/docs/assets/merge_pdf.html-MztDvd3K.js" as="script"><link rel="prefetch" href="/docs/assets/pdf_extract_image.html-C8HBkbsS.js" as="script"><link rel="prefetch" href="/docs/assets/pdf_to_grid.html-Cl0ID0d-.js" as="script"><link rel="prefetch" href="/docs/assets/pdf_to_image.html-BmDRbS5h.js" as="script"><link rel="prefetch" href="/docs/assets/rotate_pdf.html-CcoO0fAM.js" as="script"><link rel="prefetch" href="/docs/assets/split_pdf.html-8vkMRca0.js" as="script"><link rel="prefetch" href="/docs/assets/wechat_to_pdf.html-BhoXtAlW.js" as="script"><link rel="prefetch" href="/docs/assets/404.html-DHhtRzPS.js" as="script"><link rel="prefetch" href="/docs/assets/setupDevtools-QXEOFQJV-BFzSaUFN.js" as="script">
</head>
<body>
<div id="app"><!--[--><div class="vp-theme-container external-link-icon" vp-container><!--[--><header class="vp-navbar" vp-navbar><div class="vp-toggle-sidebar-button" title="toggle sidebar" aria-expanded="false" role="button" tabindex="0"><div class="icon" aria-hidden="true"><span></span><span></span><span></span></div></div><span><a class="route-link" href="/docs/"><img class="vp-site-logo" src="https://static.pdfai.cn/static/logo/logo_300.svg" alt="宝石PDF - 文档"><span class="vp-site-name vp-hide-mobile" aria-hidden="true">宝石PDF - 文档</span></a></span><div class="vp-navbar-items-wrapper" style=""><!--[--><!--]--><!----><!--[--><!--]--><button type="button" class="vp-toggle-color-mode-button" title="toggle color mode"><svg class="light-icon" viewbox="0 0 32 32" style=""><path d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z" fill="currentColor"></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z" fill="currentColor"></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z" fill="currentColor"></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg><svg class="dark-icon" viewbox="0 0 32 32" style="display:none;"><path d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z" fill="currentColor"></path></svg></button><!----></div></header><!--]--><div class="vp-sidebar-mask"></div><!--[--><aside class="vp-sidebar" vp-sidebar><!----><!--[--><!--]--><ul class="vp-sidebar-items"><!--[--><li><p tabindex="0" class="vp-sidebar-item vp-sidebar-heading">指南 <!----></p><ul style="" class="vp-sidebar-children"><!--[--><li><a class="route-link auto-link vp-sidebar-item" href="/docs/get-started.html" aria-label="快速开始"><!--[--><!--[--><!--]--><!--]-->快速开始<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/faq.html" aria-label="FAQ"><!--[--><!--[--><!--]--><!--]-->FAQ<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/note.html" aria-label="更新日志"><!--[--><!--[--><!--]--><!--]-->更新日志<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/deployment.html" aria-label="私有化部署"><!--[--><!--[--><!--]--><!--]-->私有化部署<!--[--><!--[--><!--]--><!--]--></a><!----></li><!--]--></ul></li><li><p tabindex="0" class="vp-sidebar-item vp-sidebar-heading active">API <!----></p><ul style="" class="vp-sidebar-children"><!--[--><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/pdf_to_image.html" aria-label="PDF转图片"><!--[--><!--[--><!--]--><!--]-->PDF转图片<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/image_to_pdf.html" aria-label="图片转PDF"><!--[--><!--[--><!--]--><!--]-->图片转PDF<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/pdf_extract_image.html" aria-label="PDF提取图片"><!--[--><!--[--><!--]--><!--]-->PDF提取图片<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/a5_to_a4.html" aria-label="A5合并到A4"><!--[--><!--[--><!--]--><!--]-->A5合并到A4<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/rotate_pdf.html" aria-label="PDF旋转"><!--[--><!--[--><!--]--><!--]-->PDF旋转<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/merge_pdf.html" aria-label="PDF合并"><!--[--><!--[--><!--]--><!--]-->PDF合并<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/split_pdf.html" aria-label="PDF拆分"><!--[--><!--[--><!--]--><!--]-->PDF拆分<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/pdf_to_grid.html" aria-label="PDF网格排列"><!--[--><!--[--><!--]--><!--]-->PDF网格排列<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/comcompress_pdf.html" aria-label="PDF压缩"><!--[--><!--[--><!--]--><!--]-->PDF压缩<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link auto-link vp-sidebar-item" href="/docs/api/wechat_to_pdf.html" aria-label="公众号转PDF"><!--[--><!--[--><!--]--><!--]-->公众号转PDF<!--[--><!--[--><!--]--><!--]--></a><!----></li><li><a class="route-link route-link-active auto-link vp-sidebar-item active" href="/docs/api/svg_to_pdf.html" aria-label="SVG转PDF"><!--[--><!--[--><!--]--><!--]-->SVG转PDF<!--[--><!--[--><!--]--><!--]--></a><!----></li><!--]--></ul></li><!--]--></ul><!--[--><!--]--></aside><!--]--><!--[--><main class="vp-page"><!--[--><!--]--><div vp-content><!--[--><!--]--><div><h1 id="svg转pdf" tabindex="-1"><a class="header-anchor" href="#svg转pdf"><span>SVG转PDF</span></a></h1><p><strong>说明</strong> 将1个SVG文件转成PDF文件</p><ul><li>体验地址 <a href="https://www.pdfai.cn/svg-to-pdf" target="_blank" rel="noopener noreferrer">https://www.pdfai.cn/svg-to-pdf</a></li></ul><h2 id="接口说明" tabindex="-1"><a class="header-anchor" href="#接口说明"><span>接口说明</span></a></h2><ul><li>请求地址 <code>https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf</code></li><li>请求方式 <code>POST</code></li></ul><p><strong>请求Body</strong></p><p>JSON格式</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text" data-title="text"><pre><code><span class="line">{</span>
<span class="line"> "app_key": "app_key_test",</span>
<span class="line"> "input": "https://static.pdfai.cn/static/example/files/1.svg"</span>
<span class="line">}</span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><strong>字段说明</strong></p><table><thead><tr><th>名称</th><th>类型</th><th>必须</th><th>描述</th></tr></thead><tbody><tr><td>app_key</td><td>String</td><td>是</td><td><code>app_key_test</code>,固定值</td></tr><tr><td>input</td><td>String</td><td>是</td><td>输入文件,可访问互联网url,比如 <code>https://static.pdfai.cn/static/example/files/1.svg</code></td></tr></tbody></table><p><strong>代码例子:支持 PHP、Node、Js、Go、C++、Python、Java 等</strong></p><div class="vp-code-tabs"><div class="vp-code-tabs-nav" role="tablist"><button type="button" class="vp-code-tab-nav active" role="tab" aria-controls="codetab-89-0" aria-selected="true">CURL</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-1" aria-selected="false">PHP</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-2" aria-selected="false">Node</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-3" aria-selected="false">Js</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-4" aria-selected="false">Go</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-5" aria-selected="false">C++</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-6" aria-selected="false">Python</button><button type="button" class="vp-code-tab-nav" role="tab" aria-controls="codetab-89-7" aria-selected="false">Java</button></div><!--[--><div class="vp-code-tab active" id="codetab-89-0" role="tabpanel" aria-expanded="true"><div class="vp-code-tab-title">CURL</div><!--[--><div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre><code><span class="line"><span class="token function">curl</span> <span class="token parameter variable">-X</span> <span class="token string">'POST'</span> <span class="token punctuation">\</span></span>
<span class="line"> <span class="token string">'https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf'</span> <span class="token punctuation">\</span></span>
<span class="line"> <span class="token parameter variable">-H</span> <span class="token string">'accept: application/json'</span> <span class="token punctuation">\</span></span>
<span class="line"> <span class="token parameter variable">-H</span> <span class="token string">'Content-Type: application/json'</span> <span class="token punctuation">\</span></span>
<span class="line"> <span class="token parameter variable">-d</span> <span class="token string">'{</span>
<span class="line"> "app_key": "app_key_test",</span>
<span class="line"> "input": "https://static.pdfai.cn/static/example/files/1.svg"</span>
<span class="line">}'</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-1" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">PHP</div><!--[--><div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre><code><span class="line"><span class="token php language-php"><span class="token delimiter important"><?php</span></span>
<span class="line"><span class="token variable">$curl</span> <span class="token operator">=</span> <span class="token function">curl_init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token function">curl_setopt_array</span><span class="token punctuation">(</span><span class="token variable">$curl</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line"> <span class="token constant">CURLOPT_URL</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token constant">CURLOPT_RETURNTRANSFER</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token constant">CURLOPT_POST</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token constant">CURLOPT_HTTPHEADER</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line"> <span class="token string single-quoted-string">'accept: application/json'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string single-quoted-string">'Content-Type: application/json'</span></span>
<span class="line"> <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token constant">CURLOPT_POSTFIELDS</span> <span class="token operator">=></span> <span class="token function">json_encode</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line"> <span class="token string single-quoted-string">'app_key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'app_key_test'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string single-quoted-string">'input'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'https://static.pdfai.cn/static/example/files/1.svg'</span></span>
<span class="line"> <span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$response</span> <span class="token operator">=</span> <span class="token function">curl_exec</span><span class="token punctuation">(</span><span class="token variable">$curl</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$err</span> <span class="token operator">=</span> <span class="token function">curl_error</span><span class="token punctuation">(</span><span class="token variable">$curl</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token function">curl_close</span><span class="token punctuation">(</span><span class="token variable">$curl</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$err</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">echo</span> <span class="token string double-quoted-string">"cURL Error #:"</span> <span class="token operator">.</span> <span class="token variable">$err</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">echo</span> <span class="token variable">$response</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-2" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">Node</div><!--[--><div class="language-javascript line-numbers-mode" data-highlighter="prismjs" data-ext="js" data-title="js"><pre><code><span class="line"><span class="token keyword">const</span> request <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'request'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">const</span> options <span class="token operator">=</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token literal-property property">url</span><span class="token operator">:</span> <span class="token string">'https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">method</span><span class="token operator">:</span> <span class="token string">'POST'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">headers</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string-property property">'Content-Type'</span><span class="token operator">:</span> <span class="token string">'application/json'</span></span>
<span class="line"> <span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">json</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token literal-property property">app_key</span><span class="token operator">:</span> <span class="token string">'app_key_test'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">input</span><span class="token operator">:</span> <span class="token string">'https://static.pdfai.cn/static/example/files/1.svg'</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token function">request</span><span class="token punctuation">(</span>options<span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">error<span class="token punctuation">,</span> response<span class="token punctuation">,</span> body</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">if</span> <span class="token punctuation">(</span>error<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> console<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">'Error:'</span><span class="token punctuation">,</span> error<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span></span>
<span class="line"> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'Response:'</span><span class="token punctuation">,</span> body<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-3" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">Js</div><!--[--><div class="language-javascript line-numbers-mode" data-highlighter="prismjs" data-ext="js" data-title="js"><pre><code><span class="line"><span class="token function">fetch</span><span class="token punctuation">(</span><span class="token string">'https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token literal-property property">method</span><span class="token operator">:</span> <span class="token string">'POST'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">headers</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string-property property">'Content-Type'</span><span class="token operator">:</span> <span class="token string">'application/json'</span></span>
<span class="line"> <span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">body</span><span class="token operator">:</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span><span class="token punctuation">{</span></span>
<span class="line"> <span class="token literal-property property">app_key</span><span class="token operator">:</span> <span class="token string">'app_key_test'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token literal-property property">input</span><span class="token operator">:</span> <span class="token string">'https://static.pdfai.cn/static/example/files/1.svg'</span></span>
<span class="line"> <span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">response</span> <span class="token operator">=></span> response<span class="token punctuation">.</span><span class="token function">json</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">data</span> <span class="token operator">=></span> <span class="token punctuation">{</span></span>
<span class="line"> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'Success:'</span><span class="token punctuation">,</span> data<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">error</span> <span class="token operator">=></span> <span class="token punctuation">{</span></span>
<span class="line"> console<span class="token punctuation">.</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token string">'Error:'</span><span class="token punctuation">,</span> error<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-4" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">Go</div><!--[--><div class="language-go line-numbers-mode" data-highlighter="prismjs" data-ext="go" data-title="go"><pre><code><span class="line"><span class="token keyword">package</span> main</span>
<span class="line"></span>
<span class="line"><span class="token keyword">import</span> <span class="token punctuation">(</span></span>
<span class="line"> <span class="token string">"bytes"</span></span>
<span class="line"> <span class="token string">"encoding/json"</span></span>
<span class="line"> <span class="token string">"fmt"</span></span>
<span class="line"> <span class="token string">"io/ioutil"</span></span>
<span class="line"> <span class="token string">"net/http"</span></span>
<span class="line"><span class="token punctuation">)</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token comment">// 构造请求数据</span></span>
<span class="line"> requestBody<span class="token punctuation">,</span> err <span class="token operator">:=</span> json<span class="token punctuation">.</span><span class="token function">Marshal</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">{</span></span>
<span class="line"> <span class="token string">"app_key"</span><span class="token punctuation">:</span> <span class="token string">"app_key_test"</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string">"input"</span><span class="token punctuation">:</span> <span class="token string">"https://static.pdfai.cn/static/example/files/1.svg"</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token punctuation">}</span><span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span></span>
<span class="line"> fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Error: %v\n"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">return</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 创建请求</span></span>
<span class="line"> req<span class="token punctuation">,</span> err <span class="token operator">:=</span> http<span class="token punctuation">.</span><span class="token function">NewRequest</span><span class="token punctuation">(</span><span class="token string">"POST"</span><span class="token punctuation">,</span> <span class="token string">"https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf"</span><span class="token punctuation">,</span> bytes<span class="token punctuation">.</span><span class="token function">NewBuffer</span><span class="token punctuation">(</span>requestBody<span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span></span>
<span class="line"> fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Error: %v\n"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">return</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 设置请求头</span></span>
<span class="line"> req<span class="token punctuation">.</span>Header<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">"Content-Type"</span><span class="token punctuation">,</span> <span class="token string">"application/json"</span><span class="token punctuation">)</span></span>
<span class="line"> req<span class="token punctuation">.</span>Header<span class="token punctuation">.</span><span class="token function">Set</span><span class="token punctuation">(</span><span class="token string">"accept"</span><span class="token punctuation">,</span> <span class="token string">"application/json"</span><span class="token punctuation">)</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 发送请求</span></span>
<span class="line"> client <span class="token operator">:=</span> <span class="token operator">&</span>http<span class="token punctuation">.</span>Client<span class="token punctuation">{</span><span class="token punctuation">}</span></span>
<span class="line"> resp<span class="token punctuation">,</span> err <span class="token operator">:=</span> client<span class="token punctuation">.</span><span class="token function">Do</span><span class="token punctuation">(</span>req<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span></span>
<span class="line"> fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Error: %v\n"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">return</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"> <span class="token keyword">defer</span> resp<span class="token punctuation">.</span>Body<span class="token punctuation">.</span><span class="token function">Close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 读取响应</span></span>
<span class="line"> body<span class="token punctuation">,</span> err <span class="token operator">:=</span> ioutil<span class="token punctuation">.</span><span class="token function">ReadAll</span><span class="token punctuation">(</span>resp<span class="token punctuation">.</span>Body<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span></span>
<span class="line"> fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">"Error: %v\n"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">return</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">"Response:"</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>body<span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-5" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">C++</div><!--[--><div class="language-cpp line-numbers-mode" data-highlighter="prismjs" data-ext="cpp" data-title="cpp"><pre><code><span class="line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><curl/curl.h></span></span></span>
<span class="line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><string></span></span></span>
<span class="line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string"><iostream></span></span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 回调函数处理响应数据</span></span>
<span class="line">size_t <span class="token function">WriteCallback</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token operator">*</span> contents<span class="token punctuation">,</span> size_t size<span class="token punctuation">,</span> size_t nmemb<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span>string<span class="token operator">*</span> userp<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> userp<span class="token operator">-></span><span class="token function">append</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token keyword">char</span><span class="token operator">*</span><span class="token punctuation">)</span>contents<span class="token punctuation">,</span> size <span class="token operator">*</span> nmemb<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token keyword">return</span> size <span class="token operator">*</span> nmemb<span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> CURL<span class="token operator">*</span> curl <span class="token operator">=</span> <span class="token function">curl_easy_init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> std<span class="token double-colon punctuation">::</span>string response<span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token keyword">if</span><span class="token punctuation">(</span>curl<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token comment">// 构造请求数据</span></span>
<span class="line"> <span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> json <span class="token operator">=</span> <span class="token string">"{\"app_key\":\"app_key_test\","</span></span>
<span class="line"> <span class="token string">"\"input\":\"https://static.pdfai.cn/static/example/files/1.svg\"}"</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 设置请求头</span></span>
<span class="line"> <span class="token keyword">struct</span> <span class="token class-name">curl_slist</span><span class="token operator">*</span> headers <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span></span>
<span class="line"> headers <span class="token operator">=</span> <span class="token function">curl_slist_append</span><span class="token punctuation">(</span>headers<span class="token punctuation">,</span> <span class="token string">"Content-Type: application/json"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> headers <span class="token operator">=</span> <span class="token function">curl_slist_append</span><span class="token punctuation">(</span>headers<span class="token punctuation">,</span> <span class="token string">"accept: application/json"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 配置CURL选项</span></span>
<span class="line"> <span class="token function">curl_easy_setopt</span><span class="token punctuation">(</span>curl<span class="token punctuation">,</span> CURLOPT_URL<span class="token punctuation">,</span> <span class="token string">"https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token function">curl_easy_setopt</span><span class="token punctuation">(</span>curl<span class="token punctuation">,</span> CURLOPT_POSTFIELDS<span class="token punctuation">,</span> json<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token function">curl_easy_setopt</span><span class="token punctuation">(</span>curl<span class="token punctuation">,</span> CURLOPT_HTTPHEADER<span class="token punctuation">,</span> headers<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token function">curl_easy_setopt</span><span class="token punctuation">(</span>curl<span class="token punctuation">,</span> CURLOPT_WRITEFUNCTION<span class="token punctuation">,</span> WriteCallback<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token function">curl_easy_setopt</span><span class="token punctuation">(</span>curl<span class="token punctuation">,</span> CURLOPT_WRITEDATA<span class="token punctuation">,</span> <span class="token operator">&</span>response<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 执行请求</span></span>
<span class="line"> CURLcode res <span class="token operator">=</span> <span class="token function">curl_easy_perform</span><span class="token punctuation">(</span>curl<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> </span>
<span class="line"> <span class="token comment">// 检查错误</span></span>
<span class="line"> <span class="token keyword">if</span><span class="token punctuation">(</span>res <span class="token operator">!=</span> CURLE_OK<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> std<span class="token double-colon punctuation">::</span>cerr <span class="token operator"><<</span> <span class="token string">"Error: "</span> <span class="token operator"><<</span> <span class="token function">curl_easy_strerror</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span> <span class="token operator"><<</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span></span>
<span class="line"> std<span class="token double-colon punctuation">::</span>cout <span class="token operator"><<</span> <span class="token string">"Response: "</span> <span class="token operator"><<</span> response <span class="token operator"><<</span> std<span class="token double-colon punctuation">::</span>endl<span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 清理</span></span>
<span class="line"> <span class="token function">curl_slist_free_all</span><span class="token punctuation">(</span>headers<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token function">curl_easy_cleanup</span><span class="token punctuation">(</span>curl<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-6" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">Python</div><!--[--><div class="language-python line-numbers-mode" data-highlighter="prismjs" data-ext="py" data-title="py"><pre><code><span class="line"><span class="token keyword">import</span> requests</span>
<span class="line"><span class="token keyword">import</span> json</span>
<span class="line"></span>
<span class="line">url <span class="token operator">=</span> <span class="token string">'https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf'</span></span>
<span class="line">headers <span class="token operator">=</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token string">'accept'</span><span class="token punctuation">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string">'Content-Type'</span><span class="token punctuation">:</span> <span class="token string">'application/json'</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line">data <span class="token operator">=</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token string">'app_key'</span><span class="token punctuation">:</span> <span class="token string">'app_key_test'</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token string">'input'</span><span class="token punctuation">:</span> <span class="token string">'https://static.pdfai.cn/static/example/files/1.svg'</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">try</span><span class="token punctuation">:</span></span>
<span class="line"> response <span class="token operator">=</span> requests<span class="token punctuation">.</span>post<span class="token punctuation">(</span>url<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">,</span> json<span class="token operator">=</span>data<span class="token punctuation">)</span></span>
<span class="line"> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'Response:'</span><span class="token punctuation">,</span> response<span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span></span>
<span class="line"> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'Error:'</span><span class="token punctuation">,</span> <span class="token builtin">str</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">)</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><div class="vp-code-tab" id="codetab-89-7" role="tabpanel" aria-expanded="false"><div class="vp-code-tab-title">Java</div><!--[--><div class="language-java line-numbers-mode" data-highlighter="prismjs" data-ext="java" data-title="java"><pre><code><span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>io<span class="token punctuation">.</span></span><span class="token class-name">BufferedReader</span></span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>io<span class="token punctuation">.</span></span><span class="token class-name">InputStreamReader</span></span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>io<span class="token punctuation">.</span></span><span class="token class-name">OutputStream</span></span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>net<span class="token punctuation">.</span></span><span class="token class-name">HttpURLConnection</span></span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>net<span class="token punctuation">.</span></span><span class="token class-name">URL</span></span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">import</span> <span class="token import"><span class="token namespace">java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>charset<span class="token punctuation">.</span></span><span class="token class-name">StandardCharsets</span></span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SvgToPdfExample</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">try</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token class-name">URL</span> url <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">URL</span><span class="token punctuation">(</span><span class="token string">"https://pdf-api.pdfai.cn/v1/pdf/svg_to_pdf"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token class-name">HttpURLConnection</span> conn <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">HttpURLConnection</span><span class="token punctuation">)</span> url<span class="token punctuation">.</span><span class="token function">openConnection</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> conn<span class="token punctuation">.</span><span class="token function">setRequestMethod</span><span class="token punctuation">(</span><span class="token string">"POST"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> conn<span class="token punctuation">.</span><span class="token function">setRequestProperty</span><span class="token punctuation">(</span><span class="token string">"Content-Type"</span><span class="token punctuation">,</span> <span class="token string">"application/json"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> conn<span class="token punctuation">.</span><span class="token function">setRequestProperty</span><span class="token punctuation">(</span><span class="token string">"accept"</span><span class="token punctuation">,</span> <span class="token string">"application/json"</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> conn<span class="token punctuation">.</span><span class="token function">setDoOutput</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 构造请求数据</span></span>
<span class="line"> <span class="token class-name">String</span> jsonInput <span class="token operator">=</span> <span class="token string">"{\"app_key\":\"app_key_test\","</span> <span class="token operator">+</span></span>
<span class="line"> <span class="token string">"\"input\":\"https://static.pdfai.cn/static/example/files/1.svg\"}"</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 发送请求</span></span>
<span class="line"> <span class="token keyword">try</span> <span class="token punctuation">(</span><span class="token class-name">OutputStream</span> os <span class="token operator">=</span> conn<span class="token punctuation">.</span><span class="token function">getOutputStream</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token keyword">byte</span><span class="token punctuation">[</span><span class="token punctuation">]</span> input <span class="token operator">=</span> jsonInput<span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token class-name">StandardCharsets</span><span class="token punctuation">.</span><span class="token constant">UTF_8</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> os<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span>input<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> input<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token comment">// 读取响应</span></span>
<span class="line"> <span class="token keyword">try</span> <span class="token punctuation">(</span><span class="token class-name">BufferedReader</span> br <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">BufferedReader</span><span class="token punctuation">(</span></span>
<span class="line"> <span class="token keyword">new</span> <span class="token class-name">InputStreamReader</span><span class="token punctuation">(</span>conn<span class="token punctuation">.</span><span class="token function">getInputStream</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">StandardCharsets</span><span class="token punctuation">.</span><span class="token constant">UTF_8</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token class-name">StringBuilder</span> response <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">StringBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token class-name">String</span> responseLine<span class="token punctuation">;</span></span>
<span class="line"> <span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>responseLine <span class="token operator">=</span> br<span class="token punctuation">.</span><span class="token function">readLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> response<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>responseLine<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"> <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Response: "</span> <span class="token operator">+</span> response<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line"> <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"> <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Error: "</span> <span class="token operator">+</span> e<span class="token punctuation">.</span><span class="token function">getMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><!--]--></div><!--]--></div><p>返回结果</p><div class="language-text line-numbers-mode" data-highlighter="prismjs" data-ext="text" data-title="text"><pre><code><span class="line">{</span>
<span class="line"> "code": 200,</span>
<span class="line"> "data": {</span>
<span class="line"> "file_url": "https://static.pdfai.cn/static/example/out/svg1.pdf"</span>
<span class="line"> },</span>
<span class="line"> "code_msg": "成功"</span>
<span class="line">}</span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><ul><li>code 等于 200 代表成功,其他值代表失败</li></ul></div><!--[--><!--]--></div><footer class="vp-page-meta"><!----><div class="vp-meta-item git-info"><!----><!----></div></footer><nav class="vp-page-nav" aria-label="page navigation"><a class="route-link auto-link prev" href="/docs/api/wechat_to_pdf.html" aria-label="公众号转PDF"><!--[--><div class="hint"><span class="arrow left"></span> Prev</div><div class="link"><span class="external-link">公众号转PDF</span></div><!--]--></a><!----></nav><!--[--><!--]--></main><!--]--></div><!--[--><!----><!--]--><!--]--></div>
<script type="module" src="/docs/assets/app-Df7hc8Qg.js" defer></script>
</body>
</html>