-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sdk: Add links to individual samples in the readme
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using NAPS2.Images.Gdi; | ||
using NAPS2.Pdf; | ||
using NAPS2.Scan; | ||
|
||
namespace NAPS2.Sdk.Samples; | ||
|
||
public class PdfImportSample | ||
{ | ||
public static async Task PdfImportAppendAndExport() | ||
{ | ||
// Importing PDFs requires the optional NAPS2.Pdfium.Binaries Nuget package to be installed. | ||
|
||
// Set up | ||
using var scanningContext = new ScanningContext(new GdiImageContext()); | ||
var pdfImporter = new PdfImporter(scanningContext); | ||
var images = new List<ProcessedImage>(); | ||
|
||
// Import original PDF | ||
await foreach (var image in pdfImporter.Import("original.pdf")) | ||
{ | ||
images.Add(image); | ||
} | ||
|
||
// Set up scanning | ||
var controller = new ScanController(scanningContext); | ||
var devices = await controller.GetDeviceList(); | ||
var options = new ScanOptions { Device = devices.First() }; | ||
|
||
// Append newly scanned images | ||
await foreach (var image in controller.Scan(options)) | ||
{ | ||
images.Add(image); | ||
} | ||
|
||
// Save all images to a new PDF | ||
// This will retain the structure of the original PDF pages (i.e. they aren't rasterized to flat images) | ||
var pdfExporter = new PdfExporter(scanningContext); | ||
await pdfExporter.Export("doc.pdf", images); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters