Articles in this section
Category / Section

How to convert PDF to PDF A1B in .NET Core

2 mins read

The Syncfusion Essential PDF is a .NET Core PDF library used to create, read, and edit PDF documents. Using this library, you can convert PDF to PDF/A-1b, PDF/A-2b, and PDF/A3-b in ASP.NET Core.

Steps to convert PDF to PDF/A-1b document in ASP.NET Core using C#

  1. Create a new ASP.NET Core console application.

Create a Console application

  1. Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package as a reference to your .NET Core project from NuGet.org.

Install Imaging packages

  1. Install the SkiaSharp NuGet package as a reference to your .NET Core project from NuGet.org.

Install skiasharp packages

 

  1. Include the following namespaces in the Program.cs file.
    using SkiaSharp;
    using Syncfusion.Pdf;
    using Syncfusion.Pdf.Graphics;
    using Syncfusion.Pdf.Parsing;
    using System.IO;
    

 

  1. Include the following code sample to convert PDF to PDF/A-1b using C#.
    //Load an existing PDF document.
    FileStream docStream = new FileStream(@"../../../Input.pdf", FileMode.Open, FileAccess.Read);
    PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
    //Sample level font event handling.
    loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont;
    //Convert the loaded document into PDF/A document.
    loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B);
    MemoryStream stream = new MemoryStream();
    //Save the document.
    loadedDocument.Save(stream);
    stream.Position = 0;
    FileStream filestream = new FileStream("../../../Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
    stream.WriteTo(filestream);
    //Close the document.
    loadedDocument.Close(true);
    

 

//Substitute the non-embedded fonts.
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 a fontData from the type face stream.
byte[] fontData = new byte[typeFaceStream.Length - 1];
typeFaceStream.Read(fontData, typeFaceStream.Length);
typeFaceStream.Dispose();
//Create a new memory stream from the font data.
memoryStream = new MemoryStream(fontData);
}
//Set the font stream to the event args.
args.FontStream = memoryStream;
}
  1. By executing the program, you will get the PDF document as follows.

 

Output document

A complete work sample can be downloaded from PDFToPDFA1b_Sample.zip.

Take a moment to peruse the documentation. You will also find other options like create PDF/A-1b and PDF/X-1a document and features like converting Word to PDF, Excel to PDF, and HTML to PDF with code examples.

Refer to this link to explore the rich set of Syncfusion Essential PDF features.

An online sample link to convert PDF to PDF/A-1b standard document.

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to this link to learn about generating and registering the Syncfusion license key in your application to use the components without a trail message.

Also see:

https://help.syncfusion.com/file-formats/pdf/working-with-pdf-conformance

https://www.syncfusion.com/kb/9515/how-to-convert-pdf-to-pdf-a-1b-using-c-and-vb-net

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied