Skip to content

Adding accessibility information to a PDF #1083

@bencyoung-Fignum

Description

@bencyoung-Fignum

I'm trying to use PdfPig to add some metadata to an existing PDF. The PDF has fairly good accessibility but fails the checker for metadata reasons:

Image

So I'm using the merge example to try and take the existing PDF and add the metadata

using var existing = PdfDocument.Open("htmlTest.pdf");

using var output = File.OpenWrite(htmlTest2.pdf");
using var created = new PdfDocumentBuilder(output, false, PdfWriterType.Default);

created.ArchiveStandard = PdfAStandard.None;

created.IncludeDocumentInformation = true;
created.DocumentInformation.Title = "A test title";
created.DocumentInformation.Creator = "Ben";
created.DocumentInformation.Subject = "A test subject";
created.DocumentInformation.Keywords = "test, pdf, pig, example";
created.DocumentInformation.Author = "Ben";
created.DocumentInformation.Producer = "Producer";
created.DocumentInformation.CreationDate = DateTime.Now.Date.ToString("yyyy-MM-dd");

created.XmpMetadata = XDocument.Parse("""
    <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 9.1-c001 79.2a0d8d9, 2023/03/14-11:19:46        ">
       <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
          <rdf:Description rdf:about=""
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:xmp="http://ns.adobe.com/xap/1.0/"
                xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
             <dc:format>application/pdf</dc:format>
             <dc:title>
                <rdf:Alt>
                   <rdf:li xml:lang="x-default">Vendor Report: VENDOR NAME</rdf:li>
                </rdf:Alt>
             </dc:title>
             <xmp:ModifyDate>2023-05-26T13:40:11-04:00</xmp:ModifyDate>
             <xmp:CreateDate>2023-05-26T13:40:11-04:00</xmp:CreateDate>
             <xmp:MetadataDate>2023-05-26T13:40:11-04:00</xmp:MetadataDate>
             <xmpMM:DocumentID>uuid:befe056c-5bfe-4c4d-9d90-0d6b1d008200</xmpMM:DocumentID>
             <xmpMM:InstanceID>uuid:580f188e-cc85-be41-bc8d-a82bdfe70206</xmpMM:InstanceID>
          </rdf:Description>
       </rdf:RDF>
    </x:xmpmeta>
    """);

foreach (var page in existing.GetPages())
{
    created.AddPage(existing, page.Number);
}

Which runs, but the roundtrip seems to have made things worse!

Image

Has anyone managed to get something like this working, or is there a sub-part of PdfPig I may be able to use to try and implement this manually?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions