Skip to content

Commit c051092

Browse files
Merge pull request #2250 from syncfusion-content/491995-DocumentApis
491995: Updated document codes are moved to hotfix
2 parents a09dc50 + 3e325f5 commit c051092

17 files changed

Lines changed: 827 additions & 424 deletions

Document-Processing/Web-apis/consume-apis/compress-pdf.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To compress a PDF document, send a request to the /v1/edit-pdf/compress endpoint
1818
{% highlight c# tabtitle="Curl" %}
1919

2020
curl --location 'http://localhost:8003/v1/edit-pdf/compress' \
21-
--form 'file=@"4mb.pdf"' \
21+
--form 'file=@"Input.pdf"' \
2222
--form 'settings="{
2323
\"File\": \"file\",
2424
\"Password\": null,
@@ -36,15 +36,27 @@ curl --location 'http://localhost:8003/v1/edit-pdf/compress' \
3636

3737
const formdata = new FormData();
3838
formdata.append("file", fileInput.files[0], "4mb.pdf");
39-
formdata.append("settings", "{\n \"File\": \"file\",\n \"Password\": null,\n \"ImageQuality\": 50,\n \"OptimizeFont\": true,\n \"RemoveMetadata\": false,\n \"OptimizePageContents\": true,\n \"FlattenFormFields\": true,\n \"FlattenAnnotations\": true\n}");
39+
formdata.append(
40+
"settings",
41+
JSON.stringify({
42+
File: "file",
43+
Password: null,
44+
ImageQuality: 50,
45+
OptimizeFont: true,
46+
RemoveMetadata: false,
47+
OptimizePageContents: true,
48+
FlattenFormFields: true,
49+
FlattenAnnotations: true
50+
})
51+
);
4052

4153
const requestOptions = {
4254
method: "POST",
4355
body: formdata,
4456
redirect: "follow"
4557
};
4658

47-
fetch("http://localhost:4000/v1/edit-pdf/compress", requestOptions)
59+
fetch("http://localhost:8003/v1/edit-pdf/compress", requestOptions)
4860
.then((response) => response.text())
4961
.then((result) => console.log(result))
5062
.catch((error) => console.error(error));
@@ -56,19 +68,26 @@ fetch("http://localhost:4000/v1/edit-pdf/compress", requestOptions)
5668
var client = new HttpClient();
5769
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8003/v1/edit-pdf/compress");
5870
var content = new MultipartFormDataContent();
59-
content.Add(new StreamContent(File.OpenRead("4mb.pdf")), "file", "4mb.pdf");
60-
content.Add(new StringContent("{
61-
\"File\": \"file\",
62-
\"Password\": null,
63-
\"ImageQuality\": 50,
64-
\"OptimizeFont\": true,
65-
\"RemoveMetadata\": false,
66-
\"OptimizePageContents\": true,
67-
\"FlattenFormFields\": true,
68-
\"FlattenAnnotations\": true
69-
}"), "settings");
71+
content.Add(new StreamContent(File.OpenRead("Sample.pdf")), "file1", "Sample.pdf");
72+
73+
var settings = new
74+
{
75+
File = "file",
76+
Password = (string?)null,
77+
ImageQuality = 50,
78+
OptimizeFont = true,
79+
RemoveMetadata = false,
80+
OptimizePageContents = true,
81+
FlattenFormFields = true,
82+
FlattenAnnotations = true
83+
};
84+
85+
var json = JsonSerializer.Serialize(settings);
86+
var settingsContent = new StringContent(json, Encoding.UTF8, "application/json");
87+
content.Add(settingsContent, "settings");
7088
request.Content = content;
71-
var response = await client.SendAsync(request);
89+
90+
using var response = await client.SendAsync(request);
7291
response.EnsureSuccessStatusCode();
7392
Console.WriteLine(await response.Content.ReadAsStringAsync());
7493

@@ -94,7 +113,8 @@ Next, you can retrieve the job status by sending a request to the /v1/edit-pdf/s
94113

95114
{% highlight c# tabtitle="Curl" %}
96115

97-
curl --location 'http://localhost:8003/v1/conversion/status/ef0766ab-bc74-456c-8143-782e730a89df'
116+
curl --location 'http://localhost:8003/v1/conversion/status/9b131bfe-d4eb-4f1d-b946-46443a363eb5' \
117+
--output Output.pdf
98118

99119
{% endhighlight %}
100120

@@ -104,7 +124,7 @@ const requestOptions = {
104124
method: "GET",
105125
redirect: "follow"
106126
};
107-
fetch("http://localhost:4000/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
127+
fetch("http://localhost:8003/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
108128
.then((response) => response.text())
109129
.then((result) => console.log(result))
110130
.catch((error) => console.error(error));

Document-Processing/Web-apis/consume-apis/delete-pdf-pages.md

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,40 @@ To delete PDF pages, send a request to the /v1/edit-pdf/delete-pages endpoint wi
1818
{% highlight c# tabtitle="Curl" %}
1919

2020
curl --location 'http://localhost:8003/v1/edit-pdf/delete-pages' \
21-
--form 'file=@"merge/example.pdf"' \
22-
--form 'settings="{
23-
\"RotationAngle\": \"90\",
24-
\"File\": \"file\",
25-
\"Password\": null,
26-
\"PageRanges\": [
21+
--form 'file=@"Input.pdf"' \
22+
--form 'settings={
23+
"File": "file",
24+
"Password": null,
25+
"PageRanges": [
2726
{
28-
\"Start\": 1,
29-
\"End\": 5
30-
},
31-
{
32-
\"Start\": 6,
33-
\"End\": 10
34-
}
35-
]
36-
}"'
27+
"Start": 1,
28+
"End": 2
29+
}]
30+
}'
3731

3832
{% endhighlight %}
3933

4034
{% highlight javaScript tabtitle="JavaScript" %}
4135

4236
const formdata = new FormData();
43-
formdata.append("file", fileInput.files[0], "merge/example.pdf");
44-
formdata.append("settings", "{\n \"RotationAngle\": \"90\",\n \"File\": \"file\",\n \"Password\": null,\n \"PageRanges\": [\n {\n \"Start\": 1,\n \"End\": 5\n },\n {\n \"Start\": 6,\n \"End\": 10\n }\n ]\n}");
37+
formdata.append("file", fileInput.files[0], "Input.pdf");
38+
formdata.append(
39+
"settings",
40+
JSON.stringify({
41+
File: "file",
42+
Password: null,
43+
PageRanges: [
44+
{ Start: 1, End: 2 } ]
45+
})
46+
);
4547

4648
const requestOptions = {
4749
method: "POST",
4850
body: formdata,
4951
redirect: "follow"
5052
};
5153

52-
fetch("http://localhost:4000/v1/edit-pdf/delete-pages", requestOptions)
54+
fetch("http://localhost:8003/v1/edit-pdf/delete-pages", requestOptions)
5355
.then((response) => response.text())
5456
.then((result) => console.log(result))
5557
.catch((error) => console.error(error));
@@ -61,24 +63,24 @@ fetch("http://localhost:4000/v1/edit-pdf/delete-pages", requestOptions)
6163
var client = new HttpClient();
6264
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8003/v1/edit-pdf/delete-pages");
6365
var content = new MultipartFormDataContent();
64-
content.Add(new StreamContent(File.OpenRead("merge/example.pdf")), "file", "merge/example.pdf");
65-
content.Add(new StringContent("{
66-
\"RotationAngle\": \"90\",
67-
\"File\": \"file\",
68-
\"Password\": null,
69-
\"PageRanges\": [
70-
{
71-
\"Start\": 1,
72-
\"End\": 5
73-
},
66+
content.Add(new StreamContent(File.OpenRead("Input.pdf")), "file1", "Input.pdf");
67+
68+
var settings = new
69+
{
70+
File = "file",
71+
Password = (string?)null,
72+
PageRanges = new[]
7473
{
75-
\"Start\": 6,
76-
\"End\": 10
74+
(Start: 1, End: 2)
7775
}
78-
]
79-
}"), "settings");
76+
};
77+
78+
var json = JsonSerializer.Serialize(settings);
79+
var settingsContent = new StringContent(json, Encoding.UTF8, "application/json");
80+
content.Add(settingsContent, "settings");
8081
request.Content = content;
81-
var response = await client.SendAsync(request);
82+
83+
using var response = await client.SendAsync(request);
8284
response.EnsureSuccessStatusCode();
8385
Console.WriteLine(await response.Content.ReadAsStringAsync());
8486

@@ -104,7 +106,8 @@ Next, you can retrieve the job status by sending a request to the /v1/edit-pdf/s
104106

105107
{% highlight c# tabtitle="Curl" %}
106108

107-
curl --location 'http://localhost:8003/v1/conversion/status/ef0766ab-bc74-456c-8143-782e730a89df' \
109+
curl --location 'http://localhost:8003/v1/conversion/status/9b131bfe-d4eb-4f1d-b946-46443a363eb5' \
110+
--output Output.pdf
108111

109112
{% endhighlight %}
110113

@@ -115,7 +118,7 @@ const requestOptions = {
115118
redirect: "follow"
116119
};
117120

118-
fetch("http://localhost:4000/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
121+
fetch("http://localhost:8003/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
119122
.then((response) => response.text())
120123
.then((result) => console.log(result))
121124
.catch((error) => console.error(error));

Document-Processing/Web-apis/consume-apis/excel-to-pdf.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,35 @@ To convert an Excel document to PDF, send a request to the /v1/conversion/excel-
1818
{% highlight c# tabtitle="Curl" %}
1919

2020
curl --location 'http://localhost:8003/v1/conversion/excel-to-pdf' \
21-
--form 'file=@"ExpenseReport.xlsx"' \
22-
--form 'settings="{
23-
\"File\": \"file\",
24-
\"Password\": null,
25-
\"PdfComplaince\": \"PDF/A-1B\"
26-
}"'
21+
--form 'file=@"Sample.xlsx"' \
22+
--form 'settings={
23+
"File": "file",
24+
"Password": null,
25+
"PdfCompliance": "PDF/A-1B"
26+
}'
2727

2828
{% endhighlight %}
2929

3030
{% highlight javaScript tabtitle="JavaScript" %}
3131

3232
const formdata = new FormData();
33-
formdata.append("file", fileInput.files[0], "ExpenseReport.xlsx");
34-
formdata.append("settings", "{\n \"File\": \"file\",\n \"Password\": null,\n \"PdfComplaince\": \"PDF/A-1B\"\n}");
33+
formdata.append("file", fileInput.files[0], "Input.xlsx");
34+
formdata.append(
35+
"settings",
36+
JSON.stringify({
37+
File: "file",
38+
Password: null,
39+
PdfCompliance: "PDF/A-1B",
40+
})
41+
);
3542

3643
const requestOptions = {
3744
method: "POST",
3845
body: formdata,
3946
redirect: "follow"
4047
};
4148

42-
fetch("http://localhost:4000/v1/conversion/excel-to-pdf", requestOptions)
49+
fetch("http://localhost:8003/v1/conversion/excel-to-pdf", requestOptions)
4350
.then((response) => response.text())
4451
.then((result) => console.log(result))
4552
.catch((error) => console.error(error));
@@ -83,7 +90,8 @@ Next, you can retrieve the job status by sending a request to the /v1/conversion
8390

8491
{% highlight c# tabtitle="Curl" %}
8592

86-
curl --location 'http://localhost:8003/v1/conversion/status/ef0766ab-bc74-456c-8143-782e730a89df' \
93+
curl --location 'http://localhost:8003/v1/conversion/status/7d0b62cd-c5a1-4035-9728-50c4efd1f0e1' \
94+
--output Output.pdf
8795

8896
{% endhighlight %}
8997

@@ -94,7 +102,7 @@ const requestOptions = {
94102
redirect: "follow"
95103
};
96104

97-
fetch("http://localhost:4000/v1/conversion/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
105+
fetch("http://localhost:8003/v1/conversion/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
98106
.then((response) => response.text())
99107
.then((result) => console.log(result))
100108
.catch((error) => console.error(error));

Document-Processing/Web-apis/consume-apis/flatten-pdf.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,37 @@ To flatten a PDF document, send a request to the /v1/edit-pdf/flatten endpoint w
1818
{% highlight c# tabtitle="Curl" %}
1919

2020
curl --location 'http://localhost:8003/v1/edit-pdf/flatten' \
21-
--form 'file=@"Form.pdf"' \
22-
--form 'settings="{
23-
\"File\": \"file\",
24-
\"Password\": null,
25-
\"FlattenFormFields\": true,
26-
\"FlattenAnnotations\": true
27-
}"'
21+
--form 'file=@Input.pdf' \
22+
--form 'settings={
23+
"File": "file",
24+
"Password": null,
25+
"FlattenFormFields": true,
26+
"FlattenAnnotations": true
27+
}'
2828

2929
{% endhighlight %}
3030

3131
{% highlight javaScript tabtitle="JavaScript" %}
3232

3333
const formdata = new FormData();
3434
formdata.append("file", fileInput.files[0], "Form.pdf");
35-
formdata.append("settings", "{\n \"File\": \"file\",\n \"Password\": null,\n \"FlattenFormFields\": true,\n \"FlattenAnnotations\": true\n}");
35+
formdata.append(
36+
"settings",
37+
JSON.stringify({
38+
File: "file",
39+
Password: null,
40+
FlattenFormFields: true,
41+
FlattenAnnotations: true
42+
})
43+
);
3644

3745
const requestOptions = {
3846
method: "POST",
3947
body: formdata,
4048
redirect: "follow"
4149
};
4250

43-
fetch("http://localhost:4000/v1/edit-pdf/flatten", requestOptions)
51+
fetch("http://localhost:8003/v1/edit-pdf/flatten", requestOptions)
4452
.then((response) => response.text())
4553
.then((result) => console.log(result))
4654
.catch((error) => console.error(error));
@@ -52,14 +60,22 @@ fetch("http://localhost:4000/v1/edit-pdf/flatten", requestOptions)
5260
var client = new HttpClient();
5361
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8003/v1/edit-pdf/flatten");
5462
var content = new MultipartFormDataContent();
55-
content.Add(new StreamContent(File.OpenRead("Form.pdf")), "file", "Form.pdf");
56-
content.Add(new StringContent("{
57-
\"File\": \"file\",
58-
\"Password\": null,
59-
\"FlattenFormFields\": true,
60-
\"FlattenAnnotations\": true
61-
}"), "settings");
63+
content.Add(new StreamContent(File.OpenRead("Input.pdf")), "file1", "Input.pdf");
64+
65+
var settings = new
66+
{
67+
File = "file",
68+
Password = (string?)null,
69+
FlattenFormFields = true,
70+
FlattenAnnotations = true
71+
};
72+
73+
var json = JsonSerializer.Serialize(settings);
74+
var settingsContent = new StringContent(json, Encoding.UTF8, "application/json");
75+
// When sending JSON as a field inside multipart, you can still name the part:
76+
content.Add(settingsContent, "settings");
6277
request.Content = content;
78+
6379
var response = await client.SendAsync(request);
6480
response.EnsureSuccessStatusCode();
6581
Console.WriteLine(await response.Content.ReadAsStringAsync());
@@ -86,7 +102,8 @@ Next, you can retrieve the job status by sending a request to the /v1/edit-pdf/s
86102

87103
{% highlight c# tabtitle="Curl" %}
88104

89-
curl --location 'http://localhost:8003/v1/conversion/status/ef0766ab-bc74-456c-8143-782e730a89df' \
105+
curl --location 'http://localhost:8003/v1/conversion/status/f58c9739-622e-41d4-9dd2-57a901dc13c3' \
106+
--output Output.pdf
90107
--header 'Authorization: Bearer {{Placeholder for token}}'
91108

92109
{% endhighlight %}
@@ -98,7 +115,7 @@ const requestOptions = {
98115
redirect: "follow"
99116
};
100117

101-
fetch("http://localhost:4000/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
118+
fetch("http://localhost:8003/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
102119
.then((response) => response.text())
103120
.then((result) => console.log(result))
104121
.catch((error) => console.error(error));

0 commit comments

Comments
 (0)