Search code examples
.netpdfzugferd

How do I add an attachment to a pdf file with (PDF/A-3) file format?


I want to create a PDF/A-3 Document and then add an attachment to it.

I tried using the Interop Services.

Dim xl As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application

Dim wkb As Microsoft.Office.Interop.Excel.Workbook = xl.Workbooks.Open("C:\SourceFile.xlsx")
        wkb.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, "C:\Test.pdf")

        xl.Quit()

Is there a way to produce a PDF/A-3 compatible file and add an attachment to it without use of external libraries?

If not, what external library are you recommending considering B2B use.


Solution

  • I tried using the Interop Services.

    As @joelgeraci mentioned, if you use newer versions of MS Excel, Office 365 in particular, you can use Interop to get a PDF/A-3a version. Theoretically you could use earlier versions of MS Excel, since a valid PDF/A-1 and PDF/A-2 should also be valid PDF/A-3 files, though you would have to edit the Metadata entry to change the PDF/A conformance level the file claims to be.

    Is there a way to produce a PDF/A-3 compatible file and add an attachment to it without use of external libraries?

    Technically, you could edit the PDF using .Net, to embed the data, but you would be deep diving into the PDF standard, and making binary changes to the PDF. So in a practical sense, no you need a library to add the attachment.

    If not, what external library are you recommending considering B2B use.

    PDFTron, the company I work for, has a blog post describing how to make a Zugferd compliant PDF.

    As for the Excel to PDF conversion, you could continue to use MS Excel interop as you are, or use our internal converter. By using our internal converter, you could do this process using .NET Core, and therefore on Linux, and avoiding MS Office and MS Windows licensing costs.