How to convert PDF to PDF/A-1b in .NET Core
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#
- Create a new ASP.NET Core console application.
- Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package as a reference to your .NET Core project from NuGet.org.
- 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;
- 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; }
- By executing the program, you will get the PDF document as follows.
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.
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