public virtual void CreatePdf(String dest) { //Initialize PDFA document with output intent PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read ))); Document document = new Document(pdf); //Setting some required parameters pdf.SetTagged(); //Fonts need to be embedded PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); Paragraph p = new Paragraph(); p.SetFont(font); p.Add(new Text("The quick brown ")); iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX)); //Set alt text foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox"); p.Add(foxImage); p.Add(" jumps over the lazy "); iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG)); //Set alt text dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog"); p.Add(dogImage); document.Add(p); document.Close(); }
private void ManipulatePdf(PdfDocument pdfDocument, bool setTagged) { Document document = new Document(pdfDocument); if (setTagged) { pdfDocument.SetTagged(); } pdfDocument.GetCatalog().SetLang(new PdfString("en-US")); pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdfDocument.GetDocumentInfo(); info.SetTitle("iText7 PDF/UA test"); PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); Paragraph p = new Paragraph(); p.SetFont(font); p.Add(new Text("The quick brown ")); iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX)); foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox"); p.Add(foxImage); p.Add(" jumps over the lazy "); iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG)); dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog"); p.Add(dogImage); document.Add(p); document.Close(); }
public virtual void CreatePdf(String dest) { PdfDocument pdf = new PdfDocument(new PdfWriter(dest, new WriterProperties().AddXmpMetadata())); Document document = new Document(pdf); //Setting some required parameters pdf.SetTagged(); pdf.GetCatalog().SetLang(new PdfString("en-US")); pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); PdfDocumentInfo info = pdf.GetDocumentInfo(); info.SetTitle("iText7 PDF/UA example"); //Fonts need to be embedded PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); Paragraph p = new Paragraph(); p.SetFont(font); p.Add(new Text("The quick brown ")); iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX)); //PDF/UA: Set alt text foxImage.GetAccessibilityProperties().SetAlternateDescription("Fox"); p.Add(foxImage); p.Add(" jumps over the lazy "); iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG)); //PDF/UA: Set alt text dogImage.GetAccessibilityProperties().SetAlternateDescription("Dog"); p.Add(dogImage); document.Add(p); document.Close(); }
/// <exception cref="System.UriFormatException"/> private void AddContentToDocInCustomNs(PdfDocument pdfDocument, PdfNamespace defaultNamespace, PdfNamespace xhtmlNs, PdfNamespace html4Ns, String hnRole, Document document) { Paragraph h1P = new Paragraph("Header level 1"); h1P.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.h1); Paragraph helloWorldPara = new Paragraph("Hello World from iText7"); helloWorldPara.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.p); iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(sourceFolder + imageName )).SetWidth(100); img.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.img); document.Add(h1P); document.Add(helloWorldPara); document.Add(img); pdfDocument.GetTagStructureContext().GetAutoTaggingPointer().SetNamespaceForNewTags(defaultNamespace); List list = new List().SetListSymbol("-> "); list.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.ul); list.GetAccessibilityProperties().SetNamespace(xhtmlNs); list.Add("list item").Add("list item").Add("list item").Add("list item").Add(new ListItem("list item")); document.Add(list); Paragraph center = new Paragraph("centered text").SetTextAlignment(TextAlignment.CENTER); center.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.center); center.GetAccessibilityProperties().SetNamespace(html4Ns); document.Add(center); Paragraph h11Para = new Paragraph("Heading level 11"); h11Para.GetAccessibilityProperties().SetRole(hnRole); document.Add(h11Para); if (defaultNamespace == null) { Text i = new Text("italic text"); i.GetAccessibilityProperties().SetRole("I"); Paragraph pi = new Paragraph(i.SetItalic()); document.Add(pi); } }