DEV Community

jelizaveta
jelizaveta

Posted on

Mastering PDF and OFD Conversion in C#: A Simple Guide

When it comes to managing electronic documents, PDF and OFD formats are among the most widely used. PDFs are recognized globally as a standard format, while OFD is increasingly adopted in China as a national standard for electronic documents, including e-invoices and government paperwork. This article will guide you through the process of easily converting between these two formats using C# and the Spire.PDF component.

Introduction to Spire.PDF Component

Spire.PDF for .NET is a professional PDF processing component that allows operations on PDF documents within .NET applications without needing to install Adobe software. It supports conversion between PDF and various formats, including Word, Excel, images, and OFD, with powerful features that are easy to use.

Installation Methods

Install via NuGet package manager:

Method 1: Install via Visual Studio Search

Search for “Spire.PDF” in the NuGet package manager and install it.

Method 2: Install via Command Line

Install-PackageSpire.PDF
Enter fullscreen mode Exit fullscreen mode

Convert PDF to OFD: Simple in Three Steps

First, let’s see how to convert a PDF document to OFD format. With the help of the Spire.Pdf library, the entire process can be accomplished in just a few lines of code:

using Spire.Pdf;

namespace PDFtoOFD
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load the PDF document
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("Input.pdf");

            // Save as OFD format
            pdf.SaveToFile("ToOFD.ofd", FileFormat.OFD);

            Console.WriteLine("PDF to OFD conversion completed!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Convert OFD to PDF: Equally Simple

When it’s necessary to convert an OFD file back to PDF, the OfdConverter class in the Spire.Pdf.Conversion namespace provides the corresponding conversion capability:

using Spire.Pdf.Conversion;

namespace OFDtoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load the OFD document
            OfdConverter converter = new OfdConverter("Input.ofd");

            // Save as PDF format
            converter.ToPdf("ToPDF.pdf");

            Console.WriteLine("OFD to PDF conversion completed!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Practical Application Scenarios

This format conversion capability is particularly useful in the following scenarios:

  1. Integration in E-Government Systems : Document circulation between government departments may require OFD format, while internal systems in businesses might be more accustomed to handling PDF.
  2. E-Invoice Processing : Tax systems commonly use OFD format for invoices, while financial systems need to convert them to PDF for printing and archiving.
  3. Document Archiving Systems : Unified document format standard conversion ensures long-term readability.
  4. Cross-Platform Document Exchange : When exchanging documents between different operating systems and applications, format conversion is often a necessary step.

Conclusion

Through these two concise code snippets, we've achieved bidirectional conversion between PDF and OFD formats. This straightforward implementation reflects the design philosophy of an excellent component library—encapsulating complex technical details internally while providing developers with intuitive API interfaces. Whether converting PDF to OFD or OFD to PDF, integration into existing systems can be completed within minutes, greatly improving development efficiency.

As the OFD format gains popularity in the country, mastering the conversion technology between these two formats has become an indispensable skill for developers working on electronic document processing systems. I hope the example code provided in this article can assist you in your project development.

Top comments (0)