#127 add pdf/a2-b compliance to the builder

This commit is contained in:
Eliot Jones
2020-04-04 17:49:27 +01:00
parent 729234477a
commit cf46230c05
5 changed files with 44 additions and 3 deletions

View File

@@ -532,6 +532,9 @@
var page = builder.AddPage(PageSize.A4);
var imgBytes = File.ReadAllBytes(IntegrationHelpers.GetDocumentPath("smile-250-by-160.jpg", false));
page.AddJpeg(imgBytes, new PdfRectangle(50, 70, 150, 130));
var font = builder.AddTrueTypeFont(TrueTypeTestHelper.GetFileBytes("Roboto-Regular.ttf"));
page.AddText("Howdy PDF/A-1A!", 10, new PdfPoint(25, 700), font);
@@ -550,6 +553,34 @@
}
}
[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))
{
Assert.Equal(1, pdf.NumberOfPages);
Assert.True(pdf.TryGetXmpMetadata(out var xmp));
Assert.NotNull(xmp.GetXDocument());
}
}
private static void WriteFile(string name, byte[] bytes)
{
try

View File

@@ -6,7 +6,7 @@ using UglyToad.PdfPig.Writer.Xmp;
namespace UglyToad.PdfPig.Writer
{
internal static class PdfA1BRuleBuilder
internal static class PdfABaselineRuleBuilder
{
public static void Obey(Dictionary<NameToken, IToken> catalog, Func<IToken, ObjectToken> writerFunc,
PdfDocumentBuilder.DocumentInformationBuilder documentInformationBuilder,

View File

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

View File

@@ -343,13 +343,15 @@ namespace UglyToad.PdfPig.Writer
{
Func<IToken, ObjectToken> writerFunc = x => context.WriteObject(memory, x);
PdfA1BRuleBuilder.Obey(catalogDictionary, writerFunc, DocumentInformation, ArchiveStandard);
PdfABaselineRuleBuilder.Obey(catalogDictionary, writerFunc, DocumentInformation, ArchiveStandard);
switch (ArchiveStandard)
{
case PdfAStandard.A1A:
PdfA1ARuleBuilder.Obey(catalogDictionary);
break;
case PdfAStandard.A2B:
break;
}
}

View File

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