C# Get Last Character of String (How It Works)
可攜式文件格式(PDF)一直是跨平台分享文件的首選格式。 然而,隨著數位檔案的重要性增加,對於以標準化格式檔案進行檔案保存的需求也在增加,這保證了長期的保存和可存取性。 PDF/A(PDFA)格式是專為此目的設計的,提供了一種穩定且自包含的格式,適合用於存檔。
了解PDF/A
PDF/A是一種ISO標準化的PDF變體,旨在隨著時間的推移保存文件,保持內容的可存取性和完整性。 與普通的PDF文件相比,PDF/A文件具有特定的限制,以確保其穩健性和自足性。
本文將引導您使用C++中的QPDF程式庫將PDF文件轉換為PDF/A格式的過程。 QPDF是功能強大的C++程式庫,使開發者能夠以程式方式管理和轉換PDF文件,包括PDF到PDF/A的轉換,只需幾行程式碼即可完成。
QPDF C++程式庫
QPDF是一個C++程式庫及命令行工具,旨在支援處理、轉換和解析PDF文件。 它允許開發者以程式方式存取和操作PDF文件的內容,提供廣泛的支援。 QPDF是一個開源專案,提供多種功能,包括加密、解密、線性化、最佳化和PDF/A合規性。
必要條件
在開始之前,請確保您已準備好以下環境:
- Code::Blocks IDE:從官方網站下載並安裝Code::Blocks(Code::Blocks官方網站)。
- QPDF程式庫:從QPDF網站下載適用於您的作業系統的最新版本的QPDF程式庫(QPDF官方網站)。
建立PDF到PDF/A專案
- 打開Code::Blocks:在您的電腦上啟動Code::Blocks IDE。
- 建立新專案:在頂部選單中點擊File,然後選擇New,接著選擇Project。
- 選擇專案型別:在New from template窗口中,選擇Console application,然後點擊Go。 選擇C/C++語言,然後點擊Next。
- 輸入專案詳細資訊:在Project title欄位中提供專案名稱(例如"PDFtoPDFA")。 選擇儲存專案檔案的位置,然後點擊Next。
- 選擇編譯器:選擇一個編譯器,必要時,從列表中手動選擇一個。點擊Finish。
將QPDF新增到專案
要在Code::Blocks中包含QPDF標頭檔案,請遵循以下步驟:
- 在選單中點擊Project。
- 從上下文選單中選擇Build options。
- 在Build options對話框中,轉到Search directories標籤。
- 在Compiler標籤中,點擊Add按鈕並瀏覽到包含QPDF標頭檔案的目錄(通常位於include資料夾中)。
- 然後,在Link標籤中,點擊Add按鈕並包含lib和bin目錄。
- 點擊OK關閉Build options對話框。
此外,您需要在連結階段與QPDF程式庫建立連接。 遵循以下步驟:
- 在Build options對話框中,轉到Linker settings標籤。
- 在Link Libraries下點擊Add,然後瀏覽到包含QPDF程式庫檔案的目錄(通常在Windows上有.a或.lib檔案擴展名)。
- 再次點擊Add,並輸入QPDF程式庫的名稱(例如libqpdf.a或qpdf.lib)。
- 點擊OK關閉Build options對話框。
將PDF轉換為PDF/A文件的步驟
包含必要的標頭檔案
#include <iostream>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFWriter.hh>
// The above code includes necessary header files for standard input/output operations and QPDF functionalities.
#include <iostream>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFWriter.hh>
// The above code includes necessary header files for standard input/output operations and QPDF functionalities.
設置輸入和輸出檔案的路徑
在main函式中(C++程式的起始點),設置輸入和輸出檔案的路徑:
std::string input_pdf_path = "input.pdf";
std::string output_pdf_a_path = "output.pdfa";
// These lines declare and initialize strings to store the paths of the input PDF and the output PDF/A file.
std::string input_pdf_path = "input.pdf";
std::string output_pdf_a_path = "output.pdfa";
// These lines declare and initialize strings to store the paths of the input PDF and the output PDF/A file.
為PDF檔案建立QPDF物件
QPDF input_pdf;
input_pdf.processFile(input_pdf_path.c_str());
// Create a QPDF object for the input PDF and process the file to prepare it for conversion.
QPDF input_pdf;
input_pdf.processFile(input_pdf_path.c_str());
// Create a QPDF object for the input PDF and process the file to prepare it for conversion.
為編寫PDF/A文件建立QPDFWriter物件
QPDFWriter writer(input_pdf, output_pdf_a_path.c_str());
// This creates a QPDFWriter object to handle writing the converted PDF/A file.
QPDFWriter writer(input_pdf, output_pdf_a_path.c_str());
// This creates a QPDFWriter object to handle writing the converted PDF/A file.
設置PDF/A合規性並轉換PDF文件
writer.setQDFMode(true);
writer.write();
// Set the QPDFWriter to operate in PDF/A compliant mode and write the output file.
writer.setQDFMode(true);
writer.write();
// Set the QPDFWriter to operate in PDF/A compliant mode and write the output file.
輸出
輸出文件不可編輯且符合PDF/A規範:

Convert PDF to PDF/A in C
IronPDF程式庫是一個.NET PDF程式庫,提供了處理PDF文件的全面功能。 它允許開發者使用C#或VB.NET建立、修改和轉換PDF文件。 使用者可以使用IronPDF從HTML、ASPX、Word文件(.doc)或圖片中動態生成PDF文件,並包含圖表、表格和圖片資料等豐富元素(如JPG、PNG格式)。 它還支持合併、分割和編輯現有PDF文件的頁面,以及從PDF資料中提取文字和操作內容。
IronPDF通過幾行程式碼實現PDF到PDF/A-3b格式標準的轉換。 以下程式碼幫助實現此任務:
using IronPdf;
// Create a PdfDocument object or open any PDF file
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3);
// The above C# code demonstrates the use of IronPDF to convert a PDF document to a PDF/A-3b compliant file.
using IronPdf;
// Create a PdfDocument object or open any PDF file
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3);
// The above C# code demonstrates the use of IronPDF to convert a PDF document to a PDF/A-3b compliant file.
Imports IronPdf
' Create a PdfDocument object or open any PDF file
Private pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3)
' The above C# code demonstrates the use of IronPDF to convert a PDF document to a PDF/A-3b compliant file.
結論
本文引導您通過QPDF程式庫在C++中將標準PDF文件轉換為PDF/A格式。 PDF/A合規性確保內容保存和可存取性,使其成為存檔的理想選擇。
IronPDF還支持多種格式的轉換,如HTML、圖片和Word文件到PDF文件。 欲獲取更多資訊,請存取此IronPDF文件頁。
IronPDF提供免費試用IronPDF,以測試其商業生產功能。 直接下載IronPDF。




