Create PDF/A-4 Documents for Long-Term Archiving in C#
Tags: csharp, dotnet, pdf
Published: 2022-08-10 13:19:00

---
title: Create PDF/A-4 Documents for Long-Term Archiving in C#
published: true
date: 2022-08-10 10:00:18 UTC
tags: csharp, dotnet, pdf
canonical_url: https://www.syncfusion.com/blogs/post/create-pdf-a-4-documents-for-long-term-archiving-in-c.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6frbmqtgp6fq1iv863wk.png
---

The Syncfusion [.NET PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net "Syncfusion .NET PDF Library") allows you to create, edit, and modify PDF documents in your .NET applications. We have provided support for PDF/A-4 conformance level in the [2022 Volume 2 (20.2.0.36) release](https://www.syncfusion.com/forums/175975/essential-studio-2022-volume-2-main-release-v20-2-0-36-is-available-for-download "Essential Studio 2022 Volume 2").

In this article, we will see how to create PDF/A-4 documents from the scratch and convert existing normal PDF documents to PDF/A-4 format using the Syncfusion .NET PDF Library.

## PDF/A-4 conformance

[PDF/A-4](https://en.wikipedia.org/wiki/PDF/A#PDF/A-4 "Wikipedia page for PDF/A-4") (ISO 19005-4: 2020) is based on the latest PDF version 2.0 (ISO 32000-2) standard. It is an evolution of PDF/A-3, which is based on ISO 32000-2 (PDF 1.7).

The main difference between PDF/A-4 and the previous conformance level is that it simplifies the PDF standard by removing conformance levels like -a (accessibility), -u (unicode), and -b (basic). So, the PDF/A-4 conformance documents may or may not contain PDF tags.

PDF/A-4 supports the following two conformance levels:

- **PDF/A-4e** : PDF/A-4e (engineering) is intended for technical documents and replaces PDF/E format. It supports 3D models, rich media, 3D annotations, and embedded files.
- **PDF/A-4f** : PDF/A-4f allows us to embed any files in PDF documents as attachments similar to the PDF/A-3 conformance level.

## Create a PDF/A-4 document

With the Syncfusion .NET PDF Library, you can easily create PDF documents with PDF/A-4 conformance support.

To do so, first, install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/ "Syncfusion.Pdf.Net.Core NuGet Package") NuGet package as a reference to your .NET app from the [NuGet Gallery](https://www.nuget.org/ "NuGet Gallery").

Refer to the following image.

![Install the Syncfusion.Pdf.Net.Core NuGet package](https://www.syncfusion.com/blogs/wp-content/uploads/2022/08/Install-the-Syncfusion.Pdf.Net_.Core-NuGet-package.png)

Refer to the following code example to create a PDF/A-4 document using the Syncfusion .NET PDF Library.

```csharp
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
 
//Create a new document with the PDF/A-4 standard.
PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4);
 
//Add a page to the document.
PdfPage page = document.Pages.Add();
 
//Create the PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
 
//Load the TrueType font from the local file.
FileStream fontStream = new FileStream("../../../arial.ttf", FileMode.Open, FileAccess.Read);
PdfFont font = new PdfTrueTypeFont(fontStream, 14);
 
//Draw the text.
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
 
//Create the stream object.
FileStream stream = new FileStream("output.pdf",FileMode.Create);
 
//Save the document into the memory stream.
document.Save(stream);
 
//Close the document.
document.Close(true);
```

By executing the previous code example, we will get a PDF document similar to the following screenshot.

![Creating PDF/A-4 conformance document using Syncfusion .NET PDF Library](https://www.syncfusion.com/blogs/wp-content/uploads/2022/08/Creating-PDF-A-4-conformance-document-using-Syncfusion-.NET-PDF-Library.png)
We have learned how to create a PDF/A- 4 conformance document. Let’s see how to create PDF/A-4e and 4f documents.

### Create a PDF/A-4e PDF document

PDF/A-4e allows us to create PDF documents with technical information such as construction plans, 3D technical drawings, and modern geospatial data. You can also embed these PDF documents.

It supports RichMedia annotation that helps us embed video, audio, and 3D models within the page content.

Refer to the following code example to create a PDF/A-4e document with 3D annotation.

```csharp
using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Drawing;
using Syncfusion.Pdf.Graphics;
 
//Create a new PDF document. 
PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4E);
 
//Create a new page. 
PdfPage page = document.Pages.Add(); 
FileStream inputStream = new FileStream("../../../box.u3d", FileMode.Open, FileAccess.Read);
 
//Create a new PDF 3D annotation. 
Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream);
 
//Handle the activation of the 3D annotation. 
Pdf3DActivation activation = new Pdf3DActivation(); 
activation.ActivationMode = Pdf3DActivationMode.PageOpen; 
activation.ShowToolbar = true; 
pdf3dAnnotation.Activation = activation; 
pdf3dAnnotation.Appearance.Normal.Graphics.DrawRectangle(PdfBrushes.Red, new RectangleF(10, 50, 300, 150));
 
//Add annotation to page. 
page.Annotations.Add(pdf3dAnnotation);
 
//Save the document into the stream. 
FileStream stream = new FileStream("sample.pdf",FileMode.Create); 
document.Save(stream);
 
//Close the document. 
document.Close(true);
```

By executing the previous code example, we will get a PDF document similar to the following screenshot.

![Creating a PDF/A-4e conformance document using Syncfusion .NET PDF Library](https://www.syncfusion.com/blogs/wp-content/uploads/2022/08/Creating-a-PDF-A-4e-conformance-document-using-Syncfusion-.NET-PDF-Library.png)

### Create a PDF/A-4f PDF document

With PDF/A-4f conformance, you can even embed non-PDF files in your PDF document as attachments.

Refer to the following code example to create a PDF/A-4f document with an attachment.

```csharp
using Syncfusion.Pdf;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Drawing;
using Syncfusion.Pdf.Graphics;
 
//Create a new PDF document. 
PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A4F);
 
//Create a new page. 
PdfPage page = document.Pages.Add(); 
page.Graphics.DrawRectangle(PdfBrushes.Red, new RectangleF(10, 50, 300, 150)); 
FileStream data = new FileStream("../../../input.txt", FileMode.Open);
 
//Create an attachment.
PdfAttachment attachment = new PdfAttachment(@"Input.txt", data); 
attachment.Relationship = PdfAttachmentRelationship.Alternative; 
attachment.ModificationDate = DateTime.Now; 
attachment.Description = "Input.txt"; 
attachment.MimeType = "application/txt";
 
//Add the attachment to the document. 
document.Attachments.Add(attachment);
 
//Save the document into the stream. 
FileStream stream = new FileStream("sample.pdf",FileMode.Create); 
document.Save(stream);
 
//Close the document. 
document.Close(true);
```

By executing the previous code example, we will get a PDF document similar to the following screenshot.

![Creating a PDF/A-4f conformance document using Syncfusion .NET PDF Library](https://www.syncfusion.com/blogs/wp-content/uploads/2022/08/Creating-a-PDF-A-4f-conformance-document-using-Syncfusion-.NET-PDF-Library.png)

## Convert a PDF to a PDF/A-4 document

With Syncfusion’s .NET PDF Library, you can easily convert an existing PDF to a PDF/A-4 document for archiving and long-term preservation.

As per the PDF/A-4 conformance rules, all the fonts must be embedded in the PDF document. So, we use the **SubstituteFont** event to get the font data from the system and embed it into the PDF document. In the following example, we use the [Skiasharp](https://www.nuget.org/packages/SkiaSharp/2.88.1-preview.91 "SkiaSharp NuGet Package") NuGet package to get the font details.

**Note:** To convert the existing PDF to a PDF/A conformance document, you have to add the [Syncfusion.Pdf.Imaging.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Imaging.Net.Core "Syncfusion.Pdf.Imaging.Net.Core NuGet Package") NuGet package to your .NET Core project.

Refer to the following code example to convert the existing PDF to a PDF/A-4 document.

```csharp
using SkiaSharp;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
 
FileStream docStream = new FileStream(@"../../../invoice.pdf", FileMode.Open, FileAccess.Read);
 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
 
//Sample level font event handling. 
loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
 
//Convert the loaded document to PDF/A document. 
loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A4E); 
FileStream stream = new FileStream("output.pdf",FileMode.Create);
 
//Save the document. 
loadedDocument.Save(stream);
 
 
//Close the document. 
loadedDocument.Close(true);
 
 
static void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args)
{
  //Get the font name. 
  string fontName = args.FontName.Split(',')[0];
 
  //Get the font style. 
  PdfFontStyle fontStyle = args.FontStyle; 
  SKFontStyle sKFontStyle = SKFontStyle.Normal;
 
  if (fontStyle != PdfFontStyle.Regular)
  {
    if (fontStyle == PdfFontStyle.Bold)
    {
       sKFontStyle = SKFontStyle.Bold;
    }
    else if (fontStyle == PdfFontStyle.Italic)
    {
        sKFontStyle = SKFontStyle.Italic;
    }
    else if (fontStyle == (PdfFontStyle.Italic | PdfFontStyle.Bold))
    {
        sKFontStyle = SKFontStyle.BoldItalic;
    }
  }
 
  SKTypeface typeface = SKTypeface.FromFamilyName(fontName, sKFontStyle); 
  SKStreamAsset typeFaceStream = typeface.OpenStream(); 
  MemoryStream memoryStream = null;
 
  if (typeFaceStream != null && typeFaceStream.Length > 0)
  {
    //Create the fontData from the type face stream. 
    byte[] fontData = new byte[typeFaceStream.Length - 1]; 
    typeFaceStream.Read(fontData, typeFaceStream.Length); 
    typeFaceStream.Dispose();
  
    //Create the new memory stream from the font data. 
    memoryStream = new MemoryStream(fontData);
  }
 
  //Set the font stream to the event args. 
  args.FontStream = memoryStream;
}
```

By executing the previous code example, we will get a PDF document similar to the following screenshot.

![Converting an existing PDF to PDF/A-4 conformance document](https://www.syncfusion.com/blogs/wp-content/uploads/2022/08/Converting-an-existing-PDF-to-PDF-A-4-conformance-document.png)

## GitHub reference

For more details, refer to the [creating a PDF/4-A conformance document using the Syncfusion .NET PDF Library](https://github.com/SyncfusionExamples/PDF_A4_conformance "Creating a PDF/4-A conformance document using the Syncfusion .NET PDF Library GitHub demo") demo on GitHub.

## Conclusion

Thanks for reading! In this blog post, we have seen how to create PDF/A-4 documents and convert existing PDFs to PDF/4-A conformance documents using the Syncfusion [.NET PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net "Syncfusion .NET PDF Library"). Try out the steps in this blog post and leave your feedback.

Take a moment to peruse our [PDF/A- 4 conformance documentation](https://help.syncfusion.com/file-formats/pdf/working-with-pdf-conformance#pdfa-4-conformance "PDF/A- 4 conformance documentation"), where you’ll find other options and features, all with accompanying code examples.

For questions, you can contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion support forum"), [support portal](https://support.syncfusion.com "Syncfusion support portal"), or [feedback portal](https://www.syncfusion.com/feedback/pdf "Syncfusion feedback portal"). We are always happy to assist you!

## Related blogs

- [PDF Creation Made Easy with Syncfusion Document Processing Libraries](https://www.syncfusion.com/blogs/post/pdf-creation-document-processing-libraries.aspx "Blog: PDF Creation Made Easy with Syncfusion Document Processing Libraries")
- [Create Accessible PDF Documents Using C#](https://www.syncfusion.com/blogs/post/create-accessible-pdf-documents-using-c.aspx "Blog: Create Accessible PDF Documents Using C#")
- [Add, Remove, Extract, and Replace Images in PDF using C#](https://www.syncfusion.com/blogs/post/add-remove-extract-and-replace-images-in-pdf-using-csharp.aspx "Blog: Add, Remove, Extract, and Replace Images in PDF using C#")
- [6 Easy Ways to Split a PDF Document Using C#](https://www.syncfusion.com/blogs/post/6-easy-ways-to-split-a-pdf-document-using-c.aspx "Blog: 6 Easy Ways to Split a PDF Document Using C#")