您好,登錄后才能下訂單哦!
這篇文章主要介紹“C#/VB.NET怎么創建PDF/UA文件”,在日常操作中,相信很多人在C#/VB.NET怎么創建PDF/UA文件問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”C#/VB.NET怎么創建PDF/UA文件”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
PDF/UA,即Universally Accessible PDF,該格式的PDF文件是于2012年8月以ISO標準14289-1發布的、具有普遍可訪問的PDF文檔標準。為帶標簽的PDF文檔(Tagged PDF Document)和表單的開發人員和作者設定了明確的規則。(PDF/UA-1是作為PDF/UA標準的第一部分,PDF/UA-2作為PDF/UA標準的第二部分)
PDF/UA在其基礎上有著明確的要求,即該標準都是基于PDF標簽,所有PDF/UA文檔都必須以PDF標簽來正確標記,并且,要求標簽在語義上適當,并按邏輯順序排列。
PDF/UA文件作為PDF文件的一種標準格式,要創建該標準的的PDF文檔,可使用調用PDF API的方法來創建。下面,是以Spire.PDF for .NET來創建的方法。
注:可在Visual Studio 中通過NuGet搜索“Spire.PDF”安裝dll到程序中;
或者下載包(hotfix版本)到本地,手動添加本地路徑下的Spire.Pdf.dll文件到程序。
using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Interchange.TaggedPdf; using System.Drawing; namespace CreatePDFUAfile { class Program { static void Main(string[] args) { //創建PdfDocument類的對象 PdfDocument doc = new PdfDocument(); //添加一頁 doc.Pages.Add(); //設置tab order doc.Pages[0].SetTabOrder(TabOrder.Structure); //創建PdfTaggedContent類的對象 PdfTaggedContent taggedContent = new PdfTaggedContent(doc); taggedContent.SetLanguage("en-US"); taggedContent.SetTitle("test"); //設置PDF/UA1驗證 taggedContent.SetPdfUA1Identification(); //創建字體、畫刷 PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", 10), true); PdfSolidBrush brush = new PdfSolidBrush(Color.Black); //添加要素 PdfStructureElement article = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document); PdfStructureElement paragraph2 = article.AppendChildElement(PdfStandardStructTypes.Paragraph); PdfStructureElement span1 = paragraph2.AppendChildElement(PdfStandardStructTypes.Span); span1.BeginMarkedContent(doc.Pages[0]); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Justify); doc.Pages[0].Canvas.DrawString("PDF/UA was published as ISO Standard 14289-1 in August 2012" + " and is by far the first complete definition " + "of a set of requirements for universally accessible PDF documents.", font, brush, new Rectangle(40, 80, 450, 80), format); span1.EndMarkedContent(doc.Pages[0]); PdfStructureElement paragraph3 = article.AppendChildElement(PdfStandardStructTypes.Paragraph); paragraph3.BeginMarkedContent(doc.Pages[0]); doc.Pages[0].Canvas.DrawString("The PDF/UA has some definite requirements at its base that act as the essence of this standard.", font, brush, new Rectangle(40, 120, 450, 60), format); paragraph3.EndMarkedContent(doc.Pages[0]); PdfStructureElement figure1 = article.AppendChildElement(PdfStandardStructTypes.Figure); //Set Alternate text figure1.Alt = "replacement text1"; figure1.BeginMarkedContent(doc.Pages[0], null); PdfImage image = PdfImage.FromFile(@"logo.jpg"); doc.Pages[0].Canvas.DrawImage(image, new PointF(40, 200), new SizeF(100, 100)); figure1.EndMarkedContent(doc.Pages[0]); PdfStructureElement figure2 = article.AppendChildElement(PdfStandardStructTypes.Figure); //Set Alternate text figure2.Alt = "replacement text2"; figure2.BeginMarkedContent(doc.Pages[0], null); doc.Pages[0].Canvas.DrawRectangle(PdfPens.Black, new Rectangle(300, 200, 100, 100)); figure2.EndMarkedContent(doc.Pages[0]); //保存文檔 doc.SaveToFile("CreatePDFUAFile_result.pdf"); System.Diagnostics.Process.Start("CreatePDFUAFile_result.pdf"); } } }
Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports Spire.Pdf.Interchange.TaggedPdf Imports System.Drawing Namespace CreatePDFUAfile Class Program Private Shared Sub Main(args As String()) '創建PdfDocument類的對象 Dim doc As New PdfDocument() '添加一頁 doc.Pages.Add() '設置tab order doc.Pages(0).SetTabOrder(TabOrder.[Structure]) '創建PdfTaggedContent類的對象 Dim taggedContent As New PdfTaggedContent(doc) taggedContent.SetLanguage("en-US") taggedContent.SetTitle("test") '設置PDF/UA1驗證 taggedContent.SetPdfUA1Identification() '創建字體、畫刷 Dim font As New PdfTrueTypeFont(New Font("Times New Roman", 10), True) Dim brush As New PdfSolidBrush(Color.Black) '添加要素 Dim article As PdfStructureElement = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document) Dim paragraph2 As PdfStructureElement = article.AppendChildElement(PdfStandardStructTypes.Paragraph) Dim span1 As PdfStructureElement = paragraph2.AppendChildElement(PdfStandardStructTypes.Span) span1.BeginMarkedContent(doc.Pages(0)) Dim format As New PdfStringFormat(PdfTextAlignment.Justify) doc.Pages(0).Canvas.DrawString("PDF/UA was published as ISO Standard 14289-1 in August 2012" + " and is by far the first complete definition " + "of a set of requirements for universally accessible PDF documents.", font, brush, New Rectangle(40, 80, 450, 80), format) span1.EndMarkedContent(doc.Pages(0)) Dim paragraph3 As PdfStructureElement = article.AppendChildElement(PdfStandardStructTypes.Paragraph) paragraph3.BeginMarkedContent(doc.Pages(0)) doc.Pages(0).Canvas.DrawString("The PDF/UA has some definite requirements at its base that act as the essence of this standard.", font, brush, New Rectangle(40, 120, 450, 60), format) paragraph3.EndMarkedContent(doc.Pages(0)) Dim figure1 As PdfStructureElement = article.AppendChildElement(PdfStandardStructTypes.Figure) 'Set Alternate text figure1.Alt = "replacement text1" figure1.BeginMarkedContent(doc.Pages(0), Nothing) Dim image As PdfImage = PdfImage.FromFile("logo.jpg") doc.Pages(0).Canvas.DrawImage(image, New PointF(40, 200), New SizeF(100, 100)) figure1.EndMarkedContent(doc.Pages(0)) Dim figure2 As PdfStructureElement = article.AppendChildElement(PdfStandardStructTypes.Figure) 'Set Alternate text figure2.Alt = "replacement text2" figure2.BeginMarkedContent(doc.Pages(0), Nothing) doc.Pages(0).Canvas.DrawRectangle(PdfPens.Black, New Rectangle(300, 200, 100, 100)) figure2.EndMarkedContent(doc.Pages(0)) '保存文檔 doc.SaveToFile("CreatePDFUAFile_result.pdf") System.Diagnostics.Process.Start("CreatePDFUAFile_result.pdf") End Sub End Class End Namespace
到此,關于“C#/VB.NET怎么創建PDF/UA文件”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。