add pdf/a2-a support

This commit is contained in:
Eliot Jones 2020-04-16 20:50:21 +01:00
parent ab94746252
commit 635ae13a77
4 changed files with 21 additions and 62 deletions

View File

@ -494,40 +494,16 @@
} }
} }
[Fact] [Theory]
public void CanGeneratePdfA1BFile() [InlineData(PdfAStandard.A1B)]
[InlineData(PdfAStandard.A1A)]
[InlineData(PdfAStandard.A2B)]
[InlineData(PdfAStandard.A2A)]
public void CanGeneratePdfAFile(PdfAStandard standard)
{ {
var builder = new PdfDocumentBuilder var builder = new PdfDocumentBuilder
{ {
ArchiveStandard = PdfAStandard.A1B ArchiveStandard = standard
};
var page = builder.AddPage(PageSize.A4);
var font = builder.AddTrueTypeFont(TrueTypeTestHelper.GetFileBytes("Roboto-Regular.ttf"));
page.AddText("Howdy!", 12, new PdfPoint(25, 670), font);
var bytes = builder.Build();
WriteFile(nameof(CanGeneratePdfA1BFile), bytes);
using (var pdf = PdfDocument.Open(bytes, ParsingOptions.LenientParsingOff))
{
Assert.Equal(1, pdf.NumberOfPages);
Assert.True(pdf.TryGetXmpMetadata(out var xmp));
Assert.NotNull(xmp.GetXDocument());
}
}
[Fact]
public void CanGeneratePdfA1AFile()
{
var builder = new PdfDocumentBuilder
{
ArchiveStandard = PdfAStandard.A1A
}; };
var page = builder.AddPage(PageSize.A4); var page = builder.AddPage(PageSize.A4);
@ -537,39 +513,11 @@
var font = builder.AddTrueTypeFont(TrueTypeTestHelper.GetFileBytes("Roboto-Regular.ttf")); var font = builder.AddTrueTypeFont(TrueTypeTestHelper.GetFileBytes("Roboto-Regular.ttf"));
page.AddText("Howdy PDF/A-1A!", 10, new PdfPoint(25, 700), font); page.AddText($"Howdy PDF/{standard}!", 10, new PdfPoint(25, 700), font);
var bytes = builder.Build(); var bytes = builder.Build();
WriteFile(nameof(CanGeneratePdfA1AFile), bytes); WriteFile(nameof(CanGeneratePdfAFile) + standard, bytes);
using (var pdf = PdfDocument.Open(bytes, ParsingOptions.LenientParsingOff))
{
Assert.Equal(1, pdf.NumberOfPages);
Assert.True(pdf.TryGetXmpMetadata(out var xmp));
Assert.NotNull(xmp.GetXDocument());
}
}
[Fact]
public void CanGeneratePdfA2BFile()
{
var builder = new PdfDocumentBuilder
{
ArchiveStandard = PdfAStandard.A2B
};
var page = builder.AddPage(PageSize.A4);
var font = builder.AddTrueTypeFont(TrueTypeTestHelper.GetFileBytes("Roboto-Regular.ttf"));
page.AddText("Howdy PDF/A-2B and welcome!", 10, new PdfPoint(25, 700), font);
var bytes = builder.Build();
WriteFile(nameof(CanGeneratePdfA2BFile), bytes);
using (var pdf = PdfDocument.Open(bytes, ParsingOptions.LenientParsingOff)) using (var pdf = PdfDocument.Open(bytes, ParsingOptions.LenientParsingOff))
{ {

View File

@ -20,6 +20,10 @@
/// <summary> /// <summary>
/// Compliance with PDF/A2-B. Level B (basic) conformance are standards necessary for the reliable reproduction of a document's visual appearance. /// Compliance with PDF/A2-B. Level B (basic) conformance are standards necessary for the reliable reproduction of a document's visual appearance.
/// </summary> /// </summary>
A2B = 3 A2B = 3,
/// <summary>
/// Compliance with PDF/A2-A. Level A (accessible) conformance are PDF/A2-B standards in addition to features intended to improve a document's accessibility.
/// </summary>
A2A = 4
} }
} }

View File

@ -352,6 +352,9 @@ namespace UglyToad.PdfPig.Writer
break; break;
case PdfAStandard.A2B: case PdfAStandard.A2B:
break; break;
case PdfAStandard.A2A:
PdfA1ARuleBuilder.Obey(catalogDictionary);
break;
} }
} }

View File

@ -143,6 +143,10 @@ namespace UglyToad.PdfPig.Writer.Xmp
part = 2; part = 2;
conformance = "B"; conformance = "B";
break; break;
case PdfAStandard.A2A:
part = 2;
conformance = "A";
break;
default: default:
throw new ArgumentOutOfRangeException(nameof(standard), standard, null); throw new ArgumentOutOfRangeException(nameof(standard), standard, null);
} }