mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 04:31:25 +08:00
add option to strip annotation (#492)
* add option to strip annotation * fix implementation and tests --------- Co-authored-by: arne.hansen <arne.hansen@digitecgalaxus.ch> Co-authored-by: Eliot Jones <elioty@hotmail.co.uk>
This commit is contained in:
parent
377eb507e8
commit
3b318e1944
@ -129,6 +129,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanFastAddPageAndStripAllAnnots()
|
||||
{
|
||||
var first = IntegrationHelpers.GetDocumentPath("outline.pdf");
|
||||
var contents = File.ReadAllBytes(first);
|
||||
|
||||
byte[] results = null;
|
||||
using (var existing = PdfDocument.Open(contents, ParsingOptions.LenientParsingOff))
|
||||
using (var output = new PdfDocumentBuilder())
|
||||
{
|
||||
output.AddPage(existing, 1, false);
|
||||
results = output.Build();
|
||||
var pg = existing.GetPage(1);
|
||||
var annots = pg.ExperimentalAccess.GetAnnotations().ToList();
|
||||
Assert.NotEmpty(annots);
|
||||
}
|
||||
|
||||
using (var rewritten = PdfDocument.Open(results, ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var pg = rewritten.GetPage(1);
|
||||
var annots = pg.ExperimentalAccess.GetAnnotations().ToList();
|
||||
Assert.Empty(annots);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanReadSingleBlankPage()
|
||||
{
|
||||
|
@ -307,8 +307,9 @@ namespace UglyToad.PdfPig.Writer
|
||||
/// </summary>
|
||||
/// <param name="document">Source document.</param>
|
||||
/// <param name="pageNumber">Page to copy.</param>
|
||||
/// <param name="keepAnnotations">Flag to set whether annotation of page should be kept</param>
|
||||
/// <returns>A builder for editing the page.</returns>
|
||||
public PdfPageBuilder AddPage(PdfDocument document, int pageNumber)
|
||||
public PdfPageBuilder AddPage(PdfDocument document, int pageNumber, bool keepAnnotations = true)
|
||||
{
|
||||
return AddPage(document, pageNumber, null);
|
||||
}
|
||||
@ -453,6 +454,11 @@ namespace UglyToad.PdfPig.Writer
|
||||
|
||||
if (kvp.Key == NameToken.Annots)
|
||||
{
|
||||
if (!keepAnnotations)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var val = kvp.Value;
|
||||
if (kvp.Value is IndirectReferenceToken ir)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user