Skip to content

Commit

Permalink
new feature: extract pages out of a pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
apexdodge committed Mar 13, 2022
1 parent 45ce780 commit 87e2010
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,5 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/

Api2Pdf.DotNet/Test.cs
Api2Pdf.DotNet/Test.cs
.vscode/
6 changes: 3 additions & 3 deletions Api2Pdf.DotNet/Api2Pdf.DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<RepositoryUrl>https://github.com/Api2Pdf/api2pdf.dotnet/</RepositoryUrl>
<PackageTags>pdf wkhtmtopdf headless chrome libreoffice</PackageTags>
<Description>
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
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
</Description>
<Version>2.0.1</Version>
<Version>2.1.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions Api2Pdf.DotNet/Api2Pdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public interface IPdfSharp
Task<Api2PdfResult> SetBookmarksAsync(PdfBookmarkRequest request);
Api2PdfResult SetPassword(PdfPasswordRequest request);
Task<Api2PdfResult> SetPasswordAsync(PdfPasswordRequest request);
Api2PdfResult ExtractPages(PdfExtractPagesRequest request);
Task<Api2PdfResult> ExtractPagesAsync(PdfExtractPagesRequest request);

}

Expand Down Expand Up @@ -436,6 +438,20 @@ public async Task<Api2PdfResult> SetPasswordAsync(PdfPasswordRequest request)
var response = await MakeRequestAsync(route, request);
return response;
}

public Api2PdfResult ExtractPages(PdfExtractPagesRequest request)
{
string route = "/extract-pages";
var response = MakeRequest(route, request);
return response;
}

public async Task<Api2PdfResult> ExtractPagesAsync(PdfExtractPagesRequest request)
{
string route = "/extract-pages";
var response = await MakeRequestAsync(route, request);
return response;
}
}

public class Api2PdfUtility : Api2PdfBase, IApi2PdfUtility
Expand Down
6 changes: 6 additions & 0 deletions Api2Pdf.DotNet/RequestModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,11 @@ public class PdfPasswordRequest : UrlRequest
public string OwnerPassword { get; set; }
}

public class PdfExtractPagesRequest : UrlRequest
{
public int Start { get; set; } = 0;
public int End { get; set; } = 0;
}

#endregion
}
11 changes: 11 additions & 0 deletions Api2Pdf.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static void Main(string[] args)
string sampleHtmlFile = "http://www.api2pdf.com/wp-content/uploads/2021/01/sampleHtml.html";
string sampleHtmlToXlsxFile = "http://www.api2pdf.com/wp-content/uploads/2021/01/sampleTables.html";
string samplePdf = "http://www.api2pdf.com/wp-content/uploads/2021/01/1a082b03-2bd6-4703-989d-0443a88e3b0f-4.pdf";
string sampleLongPdf = "http://www.api2pdf.com/wp-content/uploads/2022/03/7b66d080-3120-477a-a213-87938b1b0c08.pdf";

Api2PdfResult result;

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

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

//PdfSharp - extract pages
result = a2pClient.PdfSharp.ExtractPages(new PdfExtractPagesRequest
{
Url = sampleLongPdf,
Start = 0,
End = 2
});

Console.WriteLine($"PdfSharp - extract pages: {result.FileUrl}");

//Delete PDF
result = a2pClient.Chrome.HtmlToPdf(new ChromeHtmlToPdfRequest
{
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ To use the merge endpoint, supply a list of urls to existing PDFs. The engine wi
UserPassword = "password"
};
var apiResponse = a2pClient.PdfSharp.SetPassword(request);

**Extract pages out of an existing PDF**

[More details here](https://www.api2pdf.com/extract-pages-out-of-a-pdf-with-rest-api/)

var request = new PdfExtractPagesRequest
{
Url = "https://LINK-TO-PDF",
Start = 0,
End = 0
};
var apiResponse = a2pClient.PdfSharp.ExtractPages(request);

---

Expand Down

0 comments on commit 87e2010

Please sign in to comment.