Skip to content

Commit 87e2010

Browse files
committed
new feature: extract pages out of a pdf
1 parent 45ce780 commit 87e2010

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,5 @@ ASALocalRun/
329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331331

332-
Api2Pdf.DotNet/Test.cs
332+
Api2Pdf.DotNet/Test.cs
333+
.vscode/

Api2Pdf.DotNet/Api2Pdf.DotNet.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
<RepositoryUrl>https://github.com/Api2Pdf/api2pdf.dotnet/</RepositoryUrl>
1313
<PackageTags>pdf wkhtmtopdf headless chrome libreoffice</PackageTags>
1414
<Description>
15-
This client library is a wrapper for the Api2Pdf.com REST API. See full REST api documentation at https://www.api2pdf.com/documentation/v2. Api2Pdf is a powerful API that supports HTML to PDF, URL to PDF, HTML to Image, URL to Image, Thumbnail / image preview of an Office file, Office files (Word to PDF), HTML to Docx, HTML to excel, PDF to HTML, merge PDFs together, add bookmarks to PDFs, add passwords to PDFs
15+
This client library is a wrapper for the Api2Pdf.com REST API. See full REST api documentation at https://www.api2pdf.com/documentation/v2. Api2Pdf is a powerful API that supports HTML to PDF, URL to PDF, HTML to Image, URL to Image, Thumbnail / image preview of an Office file, Office files (Word to PDF), HTML to Docx, HTML to excel, PDF to HTML, merge PDFs together, add bookmarks to PDFs, add passwords to PDFs, extract pages out of a PDF
1616
</Description>
17-
<Version>2.0.1</Version>
17+
<Version>2.1.0</Version>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
21+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2222
</ItemGroup>
2323

2424
</Project>

Api2Pdf.DotNet/Api2Pdf.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public interface IPdfSharp
4848
Task<Api2PdfResult> SetBookmarksAsync(PdfBookmarkRequest request);
4949
Api2PdfResult SetPassword(PdfPasswordRequest request);
5050
Task<Api2PdfResult> SetPasswordAsync(PdfPasswordRequest request);
51+
Api2PdfResult ExtractPages(PdfExtractPagesRequest request);
52+
Task<Api2PdfResult> ExtractPagesAsync(PdfExtractPagesRequest request);
5153

5254
}
5355

@@ -436,6 +438,20 @@ public async Task<Api2PdfResult> SetPasswordAsync(PdfPasswordRequest request)
436438
var response = await MakeRequestAsync(route, request);
437439
return response;
438440
}
441+
442+
public Api2PdfResult ExtractPages(PdfExtractPagesRequest request)
443+
{
444+
string route = "/extract-pages";
445+
var response = MakeRequest(route, request);
446+
return response;
447+
}
448+
449+
public async Task<Api2PdfResult> ExtractPagesAsync(PdfExtractPagesRequest request)
450+
{
451+
string route = "/extract-pages";
452+
var response = await MakeRequestAsync(route, request);
453+
return response;
454+
}
439455
}
440456

441457
public class Api2PdfUtility : Api2PdfBase, IApi2PdfUtility

Api2Pdf.DotNet/RequestModels.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,11 @@ public class PdfPasswordRequest : UrlRequest
293293
public string OwnerPassword { get; set; }
294294
}
295295

296+
public class PdfExtractPagesRequest : UrlRequest
297+
{
298+
public int Start { get; set; } = 0;
299+
public int End { get; set; } = 0;
300+
}
301+
296302
#endregion
297303
}

Api2Pdf.Examples/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static void Main(string[] args)
2525
string sampleHtmlFile = "http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html";
2626
string sampleHtmlToXlsxFile = "http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html";
2727
string samplePdf = "http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
28+
string sampleLongPdf = "http://www.api2pdf.com/wp-content/uploads/2022/03/7b66d080-3120-477a-a213-87938b1b0c08.pdf";
2829

2930
Api2PdfResult result;
3031

@@ -189,6 +190,16 @@ static void Main(string[] args)
189190

190191
Console.WriteLine($"PdfSharp - set password: {result.FileUrl}");
191192

193+
//PdfSharp - extract pages
194+
result = a2pClient.PdfSharp.ExtractPages(new PdfExtractPagesRequest
195+
{
196+
Url = sampleLongPdf,
197+
Start = 0,
198+
End = 2
199+
});
200+
201+
Console.WriteLine($"PdfSharp - extract pages: {result.FileUrl}");
202+
192203
//Delete PDF
193204
result = a2pClient.Chrome.HtmlToPdf(new ChromeHtmlToPdfRequest
194205
{

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,18 @@ To use the merge endpoint, supply a list of urls to existing PDFs. The engine wi
290290
UserPassword = "password"
291291
};
292292
var apiResponse = a2pClient.PdfSharp.SetPassword(request);
293+
294+
**Extract pages out of an existing PDF**
295+
296+
[More details here](https://www.api2pdf.com/extract-pages-out-of-a-pdf-with-rest-api/)
297+
298+
var request = new PdfExtractPagesRequest
299+
{
300+
Url = "https://LINK-TO-PDF",
301+
Start = 0,
302+
End = 0
303+
};
304+
var apiResponse = a2pClient.PdfSharp.ExtractPages(request);
293305

294306
---
295307

0 commit comments

Comments
 (0)