Precise PDF Page Control Using C# and .NET

PDF-A Factor (also known as ZUGFeRD) is an electronic invoice format that combines both a human-readable PDF document and structured XML data that allows you to automate invoice processing. This format complies with the European standard EN 16931 (syntax CII D16B) and supports various versions of PDF/A (for example, PDF/A-3), which ensures long-term storage and accessibility of documents. In this article, we will look at how to use the SautinSoft.PDF.Net library for converting files to FacturX PDF format using C# and .Net.

Step-by-step guide:

  1. Add SautinSoft.PDF from NuGet.
  2. Load a PDF document.
  3. Create PDF save options like the FacturX Zugferd.
  4. Select the desired PDF/A version.
  5. Save a PDF document.

Output result:

Полный код

using System;
using System.IO;
using System.Reflection;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Convert PDF to PDF/A FacturX using C# and .NET.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/convert-to-pdfa-facturx.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free 100-day trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");
            string inpFile = @"..\..\..\Factur\Facture1.pdf";
            string outFile = @"..\..\..\Factur\FacturX.pdf";
            string xmlInfo = @"..\..\..\Factur\Facture1.xml";
            // Load a PDF document.
            using (var document = PdfDocument.Load(Path.GetFullPath(inpFile)))
            {
                // Create PDF save options.
                var pdfOptions = new PdfSaveOptions()
                {
                // Factur-X is at the same time a full readable invoice in a PDF A/3 format,
                // containing all information useful for its treatment, especially in case of discrepancy or absence of automatic matching with orders and / or receptions,
                // and a set of invoice data presented in an XML structured file conformant to EN16931 (syntax CII D16B), complete or not, allowing invoice process automation.

                    // Select the desired PDF/A version.
                    Version = PdfVersion.FacturX,
                    FacturXXml = File.ReadAllText(xmlInfo)
                };

                // Save a PDF document like the FacturX Zugferd.
				// Read more information about Factur-X: https://fnfe-mpe.org/factur-x/

                document.Save(outFile, pdfOptions);
            }
        }
    }
}

Download

Option Infer On

Imports System
Imports System.IO
Imports System.Reflection.Metadata
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content

Namespace Sample
	Friend Class Sample
		''' <summary>
		''' Convert PDF to PDF/A FacturX using C# and .NET.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/convert-to-pdfa-facturx.php
		''' </remarks>
		Shared Sub Main(ByVal args() As String)
			' Before starting this example, please get a free 100-day trial key:
			' https://sautinsoft.com/start-for-free/

			' Apply the key here:
			' PdfDocument.SetLicense("...");
			Dim inpFile As String = "..\..\..\Factur\Facture1.pdf"
			Dim outFile As String = "..\..\..\Factur\FacturX.pdf"
			Dim xmlInfo As String = "..\..\..\Factur\Facture1.xml"
			' Load a PDF document.
			Using document = PdfDocument.Load(Path.GetFullPath(inpFile))
				' Create PDF save options.
				Dim pdfOptions = New PdfSaveOptions() With {
					.Version = PdfVersion.FacturX,
					.FacturXXml = File.ReadAllText(xmlInfo)
				}

				' Save a PDF document like the FacturX Zugferd.
				' Read more information about Factur-X: https://fnfe-mpe.org/factur-x/

				document.Save(outFile, pdfOptions)
			End Using
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.