Skip to content

Commit

Permalink
Sdk: Add links to individual samples in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Dec 29, 2023
1 parent f66d30b commit 9a6fb36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
40 changes: 40 additions & 0 deletions NAPS2.Sdk.Samples/PdfImportSample.cs
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);
}
}
11 changes: 9 additions & 2 deletions NAPS2.Sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit 9a6fb36

Please sign in to comment.