Sdk: Add links to individual samples in the readme

This commit is contained in:
Ben Olden-Cooligan 2023-12-29 13:33:23 -08:00
parent f66d30bbbd
commit 9a6fb36a8c
2 changed files with 49 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -37,8 +37,6 @@ NAPS2.Sdk is modular, and depending on your needs you may have to reference a di
## Usage
See the [Samples](https://github.com/cyanfish/naps2/tree/master/NAPS2.Sdk.Samples) for more examples and description.
```c#
// Set up
using var scanningContext = new ScanningContext(new GdiImageContext());
@ -69,6 +67,15 @@ var pdfExporter = new PdfExporter(scanningContext);
await pdfExporter.Export("doc.pdf", images);
```
More [samples](https://github.com/cyanfish/naps2/tree/master/NAPS2.Sdk.Samples):
- ["Hello World" scanning](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/HelloWorldSample.cs)
- [Scan and save to PDF/images](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/ScanAndSaveSample.cs)
- [Scan with TWAIN drivers](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/TwainSample.cs)
- [Scan to System.Drawing.Bitmap](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/ScanToBitmapSample.cs)
- [Import and export PDFs](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/PdfImportSample.cs)
- [Store image data on the filesystem](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/FileStorageSample.cs)
- [Share scanners on the local network](https://github.com/cyanfish/naps2/blob/master/NAPS2.Sdk.Samples/NetworkSharingSample.cs)
## Drivers
| | Windows | Mac | Linux |