Support for Replaceable Symbols, a new XML schema and Document level JavaScript with Aspose.Pdf for .NET 11.1.0

Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Pdf for .NET logoAspose.Pdf for .NET is among one of the top API’s being used by developers across the globe for PDF file creation as well as manipulation. The ease of use, light weight architecture, compatibility with almost all VisualStudio versions, .NET Frameworks and almost all versions of Windows, are some of the features which have made this API favorite among developers. With every new release, we provide a bunch of new features and enhancements to cope with requirements of our customers with an intent to make our API more robust to cater as much possible scenarios as we can. A new release of Aspose.Pdf for .NET 11.1.0 has already hit the download section and provides new features and enhancements already requested by our customers. Among these new features, there have been fixes towards various exceptions and bugs reported against earlier release versions.

Replaceable symbols using TextFragment

Replaceable symbols are special symbols in a text string that can be replaced with corresponding content at run time.

When adding TextFragment to paragraphs collection of PDF document, it does not support line feed inside the text. However in order to add text with line feed, please use TextFragment with TextParagraph:

  • use “\r\n” or Environment.NewLine in TextFragment instead of single “\n”;
  • create TextParagraph object. It will add text with line splitting;
  • add the TextFragment with TextParagraph.AppendLine;
  • add the TextParagraph with TextBuilder.AppendParagraph.
Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document();
Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add();

//initialize new TextFragment with text containing required newline markers
Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe");

//set text fragment properties if necessary
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman");
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

//create TextParagraph object
TextParagraph par = new TextParagraph();

//add new TextFragment to paragraph

//set paragraph position
par.Position = new Aspose.Pdf.Text.Position(100, 600);

//create TextBuilder object
TextBuilder textBuilder = new TextBuilder(applicationFirstPage);
//add the TextParagraph using TextBuilder

//save output file

Please visit the following link for further details on Rendering Replaceable Symbols during PDF creation.

Aspose.Pdf for .NET XML Schema for DOM approach

The Document Object Model (DOM) of the Aspose.Pdf namespace is created using XML Schema Document (XSD) which can be found here: Aspose.Pdf XML schema(DOM).xsd . This schema can be used to know the detailed information of all the elements and attributes that are supported by Aspose.Pdf for .NET.

Using Roman numbers in TOC entries

Headings are the important parts of any document. Writers always try to make headings more prominent and meaningful to its readers. If there are more than one headings in a document, a writer has several options to organize these headings. One of the most common approach to organize headings is to write headings in Numbering Style. Aspose.Pdf for .NET supports following heading styles.

Heading Types Description
NumeralsArabic Arab type,for example, 1,1.1,…
NumeralsRomanUppercase Roman upper type, for example, I,I.II, …
NumeralsRomanLowercase Roman lower type, for example, i,i.ii, …
LettersUppercase English upper type, for example, A,A.B, …
LettersLowercase English lower type, for example, a,a.b, …
Document pdfDoc = new Document();
pdfDoc.PageInfo.Width = 612.0;
pdfDoc.PageInfo.Height = 792.0;
pdfDoc.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfDoc.PageInfo.Margin.Left = 72;
pdfDoc.PageInfo.Margin.Right = 72;
pdfDoc.PageInfo.Margin.Top = 72;
pdfDoc.PageInfo.Margin.Bottom = 72;

Aspose.Pdf.Page pdfPage = pdfDoc.Pages.Add();
pdfPage.PageInfo.Width = 612.0;
pdfPage.PageInfo.Height = 792.0;
pdfPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfPage.PageInfo.Margin.Left = 72;
pdfPage.PageInfo.Margin.Right = 72;
pdfPage.PageInfo.Margin.Top = 72;
pdfPage.PageInfo.Margin.Bottom = 72;

Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox();
floatBox.Margin = pdfPage.PageInfo.Margin;


TextFragment textFragment = new TextFragment();
TextSegment segment = new TextSegment();

Aspose.Pdf.Heading heading = new Aspose.Pdf.Heading(1);
heading.IsInList = true;
heading.StartNumber = 1;
heading.Text = "List 1";
heading.Style = NumberingStyle.NumeralsRomanLowercase;
heading.IsAutoSequence = true;


Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
heading2.IsInList = true;
heading2.StartNumber = 13;
heading2.Text = "List 2";
heading2.Style = NumberingStyle.NumeralsRomanLowercase;
heading2.IsAutoSequence = true;


Aspose.Pdf.Heading heading3 = new Aspose.Pdf.Heading(2);
heading3.IsInList = true;
heading3.StartNumber = 1;
heading3.Text = "the value, as of the effective date of the plan, of property to be distributed under the plan onaccount of each allowed";
heading3.Style = NumberingStyle.LettersLowercase;
heading3.IsAutoSequence = true;



Further details can be found on How to Apply Numbering Style in Heading.

Add Document level JavaScript

A new property named JavaScript is added in Document class which has JavaScript collection type and provides access to JAvaScript scenarios by its key. The JavaScript collection has the following properties and methods:

  • string this[string key] { get; set; } – Gets or sets JavaScript by its name
  • IList Keys – provides list of exisitng keys in JavaScript collection
  • bool Remove(string key) – removes JavaScript by its key.
Document doc = new Document();
doc.JavaScript["func1"] = "function func1() { hello(); }";
doc.JavaScript["func2"] = "function func2() { hello(); }";
Document doc1 = new Document("c:/pdftest/39455_js.pdf");
IList keys = doc1.JavaScript.Keys;
Console.WriteLine("=============================== ");
foreach (string key in keys)
    Console.WriteLine(key + " ==> " + doc1.JavaScript[key]);

Console.WriteLine("Key 'func1' removed ");
Console.WriteLine("=============================== ");


Miscellaneous fixes

As well as the enhancements and features discussed above, there have been specific improvements regarding Footnote rendering, TOC rendering, PDF to HTML, HTML to PDF conversion features. Among these fixes, the PCL to PDF, SVG to PDF, PDF to Excel, PDF to DOC, PDF to TIFF, XML to PDF, TIFF to PDF conversion, conversion of PDF to PDF/A compliant documents, text replacement, rendering PDF files to XPS format are also improved. Please download and try the latest release of Aspose.Pdf for .NET 11.1.0.