Skip to content

Commit

Permalink
Adds a couple of tests showing operations with the library
Browse files Browse the repository at this point in the history
  • Loading branch information
svengeance committed Jan 6, 2024
1 parent f1d94c6 commit eef5f20
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/QPdfSharp.Tests/QPdfExamplesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright © Stephen (Sven) Vernyi and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using QPdfSharp.Options;

namespace QPdfSharp.Tests;

public class QPdfExamplesTests
{
[Fact]
public void Can_read_optimize_write_pdf()
{
// Read PDF
using var qpdf = new QPdf(TestAssets.Grug);

// Write with optimizations
qpdf.WriteFile("optimized.pdf", new QPdfWriteOptions
{
CompressStreams = true,
Linearize = true
});
}

[Fact]
public void Can_add_watermark_page_to_pdf()
{
// This watermark could be safely cached in memory with a long-held reference to QPdf.
using var watermark = new QPdf(TestAssets.QPdfWatermark);
using var qpdf = new QPdf(TestAssets.Grug);

// Prepend watermark page
qpdf.PrependPage(watermark.GetPage(0));

// Write PDF
qpdf.WriteFile("watermarked.pdf");
}
}
1 change: 1 addition & 0 deletions tests/QPdfSharp.Tests/TestAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public static class TestAssets
{
public const string Grug = "Assets/grug.pdf";
public const string GrugJson = "Assets/grug.json";
public const string QPdfWatermark = "Assets/watermark.pdf";
}

0 comments on commit eef5f20

Please sign in to comment.