Create PDF/A and insert hyperlink to image in C#

PDF/A is widely used for long term archiving for PDF format. By using Spire.PDF, you can create PDF/A file directly. This article mainly shows how to set up PDF/A file; it will also demonstrate how to add image and insert hyperlink to image in C#.

Make sure Spire.PDF for .NET (version 2.9.43 or above) has been installed correctly and then add Spire.Pdf.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Pdf\Bin\NET4.0\ Spire.Pdf.dll".

Here comes to the steps:

Step 1: Create a PDF/A document.

// Create a PdfDocument instance
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
page.Canvas.DrawString("Hello World", new PdfFont(PdfFontFamily.Helvetica, 30f), new PdfSolidBrush(Color.Black), 10, 10);

Step 2: Load an image from file and insert to the PDF.

//insert an image
PdfImage image = PdfImage.FromFile(@"D:\PDF.png");

Step 3: Add a hyper link to the image.

//Add a link to image
PointF location = new PointF(100, 100);
RectangleF linkBounds = new RectangleF(location, new SizeF(image.Width, image.Height));
Spire.Pdf.Annotations.PdfUriAnnotation link = new Spire.Pdf.Annotations.PdfUriAnnotation(linkBounds, "http://www.e-iceblue.com/Introduce/pdf-for-net-introduce.html");
link.Border = new PdfAnnotationBorder(0);
page.Canvas.DrawImage(image, linkBounds);
page.Annotations.Add(link);

Step 4: Save the PDF document.

//Save the document to file in PDF format
String output1 = @"..\..\..\..\..\..\Data\ToPDF.pdf";
document.SaveToFile(output1);

// Create an instance of the PdfStandardsConverter class, passing the input PDF file path as a parameter.
PdfStandardsConverter converter = new PdfStandardsConverter(output1);

// Specify the desired file name for the resulting PDFA-1b compliant PDF.
String output2 = @"..\..\..\..\..\..\Data\ToPDFA.pdf";

// Convert the input PDF file to PDFA-1b format and save it using the specified output file name.
converter.ToPdfA1B(output2);

Effective screenshot:

Create PDF/A and insert hyperlink to image