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:
Полный код
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);
}
}
}
}
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
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: