You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.NET bindings for [Api2Pdf REST API](https://www.api2pdf.com/documentation)
2
+
.NET bindings for [Api2Pdf REST API](https://www.api2pdf.com/documentation/v2)
3
3
4
-
Api2Pdf.com is a REST API for instantly generating PDF documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), and images. The API also supports merge / concatenation of two or more PDFs. Api2Pdf is a wrapper for popular libraries such as **wkhtmltopdf**, **Headless Chrome**, and **LibreOffice**.
4
+
Api2Pdf.com is a powerful REST API for instantly generating PDF and Office documents from HTML, URLs, Microsoft Office Documents (Word, Excel, PPT), Email files, and images. The API also supports merge / concatenation of two or more PDFs, setting passwords on PDFs, and adding bookmarks to PDFs. Api2Pdf is a wrapper for popular libraries such as **wkhtmltopdf**, **Headless Chrome**, **PdfSharp**, and **LibreOffice**.
5
5
6
6
-[Installation](#installation)
7
7
-[Resources](#resources)
@@ -42,57 +42,84 @@ All usage starts by initializing the client by passing your API key as a paramet
42
42
43
43
Once you initialize the client, you can make calls like so:
44
44
45
-
var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello, World</p>");
46
-
Console.WriteLine(apiResponse.Pdf);
45
+
var request = new ChromeHtmlToPdfRequest
46
+
{
47
+
Html = "<p>Hello World</p>"
48
+
};
49
+
var apiResponse = a2pClient.Chrome.HtmlToPdf(request);
50
+
Console.WriteLine(apiResponse.FileUrl);
47
51
Console.ReadLine();
52
+
53
+
For each endpoint there are common options you can specify too:
54
+
55
+
-*Inline* - set to True if you would like the PDF to be opened up in a browser window. Set to false if you want the browser to "download" the file.
56
+
-*FileName* - specify your own file name such as "sample.pdf". Inline option above should be set to false if you specify your own file name. If no file name is provided, a random file name will be generated for you.
48
57
49
58
### Result Object
50
59
51
-
An `Api2PdfResponse` object is returned from every API call. If a call is unsuccessful then `success` will show False and the `error` will provide the reason for failure. Additional attributes include the total data usage in, out, and the cost for the API call, typically very small fractions of a penny.
60
+
An `Api2PdfResult` object is returned from every API call. If a call is unsuccessful then `success` will show False and the `error` will provide the reason for failure. Additional attributes include the bandwidth out, seconds of compute, and the cost for the API call, typically very small fractions of a penny.
var apiResponse = a2pClient.LibreOffice.PdfToHtml(request);
149
224
150
225
---
151
226
152
-
## <aname="merge"></a>Merge / Concatenate Two or More PDFs
227
+
## <aname="merge"></a>PdfSharp
228
+
229
+
**Merge PDFs from list of URLs to existing PDFs**
153
230
154
231
To use the merge endpoint, supply a list of urls to existing PDFs. The engine will consume all of the PDFs and merge them into a single PDF, in the order in which they were provided in the list.
155
232
156
-
**Merge PDFs from list of URLs to existing PDFs**
233
+
var pdfsToMerge = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
234
+
var request = new PdfMergeRequest
235
+
{
236
+
Urls = pdfsToMerge
237
+
};
238
+
var apiResponse = a2pClient.PdfSharp.MergePdfs(request);
239
+
240
+
**Add PDF bookmarks to an existing PDF**
157
241
158
-
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
159
-
var apiResponse = a2pClient.Merge(links_to_pdfs);
242
+
var bookmarks = new List<PdfBookmark>()
243
+
{
244
+
new PdfBookmark
245
+
{
246
+
Page = 0,
247
+
Title = "Introduction"
248
+
},
249
+
new PdfBookmark
250
+
{
251
+
Page = 1,
252
+
Title = "Second Page"
253
+
}
254
+
}
255
+
var request = new PdfBookmarkRequest
256
+
{
257
+
Url = "https://LINK-TO-PDF,
258
+
Bookmarks = bookmarks
259
+
};
260
+
var apiResponse = a2pClient.PdfSharp.SetBookmarks(request);
160
261
161
-
**Merge PDFs from list of URLs to existing PDFs (load PDF in browser window and specify a file name)**
262
+
**Add password to existing PDF**
162
263
163
-
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
164
-
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");
264
+
var request = new PdfPasswordRequest
265
+
{
266
+
Url = "https://LINK-TO-PDF",
267
+
UserPassword = "password"
268
+
};
269
+
var apiResponse = a2pClient.PdfSharp.SetPassword(request);
165
270
166
271
---
167
272
168
273
## <aname="helpers"></a>Helper Methods
169
274
170
-
**Api2PdfResponse Delete(string responseId)**
275
+
**Delete a file conversion on command from API2PDF servers**
171
276
172
-
By default, Api2Pdf will delete your PDF 24 hours after it has been generated. For those with high security needs, you may want to delete your PDF on command. You can do so by making an DELETE api call with the `responseId` attribute that was returned on the original JSON payload.
277
+
By default, Api2Pdf will delete your generated file 24 hours after it has been generated. For those with high security needs, you may want to delete your file on command. You can do so by making an DELETE api call with the `responseId` attribute that was returned on the original JSON payload.
173
278
174
279
var a2pClient = Api2Pdf("YOUR-API-KEY");
175
-
var apiResponse = a2pClient.HeadlessChrome.FromHtml("<p>Hello World</p>");
176
-
var responseId = apiResponse.ResponseId;
177
-
//delete PDF
178
-
a2pClient.Delete(responseId);
280
+
var request = new ChromeHtmlToPdfRequest
281
+
{
282
+
Html = "<p>Hello World</p>"
283
+
};
284
+
var apiResponse = a2pClient.Chrome.HtmlToPdf(request);
On any `Api2PdfResponse` that succesfully generated a pdf, you can use the handy `SavePdf(string localPdf)` method to download the pdf to a local cache.
291
+
On any `Api2PdfResult` that succesfully generated a file, you can use the handy `SaveFile(string localPath)` method to download the file to a local cache.
183
292
184
293
var a2pClient = Api2Pdf("YOUR-API-KEY");
185
-
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
186
-
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");
187
-
apiResponse.SavePdf("path-to-local-folder");
294
+
var request = new ChromeHtmlToPdfRequest
295
+
{
296
+
Html = "<p>Hello World</p>"
297
+
};
298
+
var apiResponse = a2pClient.Chrome.HtmlToPdf(request);
299
+
apiResponse.SaveFile("path-to-local-folder");
188
300
189
-
**byte[]Api2PdfResponse.GetPdfBytes()**
301
+
**byte[]Api2PdfResult.GetFileBytes()**
190
302
191
-
You can use `GetPdfBytes()` method to download the pdf to a byte array.
303
+
You can use `GetFileBytes()` method to download the file to a byte array.
192
304
193
305
var a2pClient = Api2Pdf("YOUR-API-KEY");
194
-
var links_to_pdfs = new List<string>() {"https://LINK-TO-PDF", "https://LINK-TO-PDF"};
195
-
var apiResponse = a2pClient.Merge(links_to_pdfs, inline: true, outputFileName: "test.pdf");
196
-
apiResponse.GetPdfBytes();
306
+
var request = new ChromeHtmlToPdfRequest
307
+
{
308
+
Html = "<p>Hello World</p>"
309
+
};
310
+
var apiResponse = a2pClient.Chrome.HtmlToPdf(request);
0 commit comments