mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 07:15:31 +03:00
Sdk: Add links to individual samples in the readme
This commit is contained in:
parent
f66d30bbbd
commit
9a6fb36a8c
40
NAPS2.Sdk.Samples/PdfImportSample.cs
Normal file
40
NAPS2.Sdk.Samples/PdfImportSample.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -37,8 +37,6 @@ NAPS2.Sdk is modular, and depending on your needs you may have to reference a di
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
See the [Samples](https://github.com/cyanfish/naps2/tree/master/NAPS2.Sdk.Samples) for more examples and description.
|
|
||||||
|
|
||||||
```c#
|
```c#
|
||||||
// Set up
|
// Set up
|
||||||
using var scanningContext = new ScanningContext(new GdiImageContext());
|
using var scanningContext = new ScanningContext(new GdiImageContext());
|
||||||
@ -69,6 +67,15 @@ var pdfExporter = new PdfExporter(scanningContext);
|
|||||||
await pdfExporter.Export("doc.pdf", images);
|
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
|
## Drivers
|
||||||
|
|
||||||
| | Windows | Mac | Linux |
|
| | Windows | Mac | Linux |
|
||||||
|
Loading…
Reference in New Issue
Block a user