Last chance to order the Ultimate PDF with the competitive price

We are thrilled to annouce that a new version of the Ultimate PDF component is out in July with many improvements and new features. We have worked hard to deliver the high-quality products to our ATP, Inc.'s division - ComponentSoft customers. The new version is coming with a new pricing model in which the base price of the Ultimate PDF component is increased. Hurry up, it's your last chance to order the component at an affordable price. Order now and enjoy your FREE Upgrade when we release the new version in July. The trial version of the component can be downloaded at our Download Page.

Drawing Text in PDF Document

There are many ways to draw texts with the UltimatePdf component. The following code example illustrates how to draw texts with each method.

1. Using DrawString

The format of the DrawString methods of the PdfGraphics are similar to the System.Drawing.Graphics.DrawString methods. It allows you to draw the specified text with the specified color, size, and font family.

The following code example illustrates this:

C#
PdfImportedDocument doc = new PdfImportedDocument(fileName);
PdfPage page = doc.Pages.Add()
as PdfPage;
PdfGraphics g = page.Graphics;
PdfFont font =
new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
g.DrawString(
"My Text", font, PdfBrushes.DarkBlue, new PointF(50, 0));
doc.Save(fileName);
doc.Close();
VB.NET
Dim fileName As String = "c:\test pdf.pdf"
Dim doc As New PdfImportedDocument(fileName)
Dim page As PdfPage = TryCast(doc.Pages.Add(), PdfPage)
Dim g As PdfGraphics = page.Graphics
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold)
g.DrawString("My Text", font, PdfBrushes.DarkBlue, New PointF(50, 0))
doc.Save(fileName)
doc.Close()

2. Paginating the text Area

To paginate a text, simply create a new instance of the PdfTextElement class and draw it in the PDF document. To configure the layout for your spanning text, use the PdfLayoutSettings class. For more details on spanning other elements, see this topic.

C#
// Create a new PDF document. This object represents the PDF document.
// This document has one page, by default. Additional pages have to be added.
PdfDocument pdfDoc = new PdfDocument();
// Add a page to the document
PdfPage page = pdfDoc.Pages.Add();
PdfFont font =
new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold);
// Create a text element with large amount of text.
PdfTextElement element = new PdfTextElement("Text Element", font);
// Set the properties for the text element.
element.Brush = new PdfSolidBrush(Color.Black);
PdfStringFormat format =
new PdfStringFormat(PdfTextAlignment.Right);
// Set the string format. This can be used for setting unicode text.
element.StringFormat = format;
// Set the layout format properties to make the text flow through multiple pages.
PdfLayoutSettings layoutFormat = new PdfLayoutSettings();
layoutFormat.Break = PdfLayoutBreakType.FitPage;
layoutFormat.Layout = PdfLayoutType.Paginate;
// Set the bounds.
RectangleF bounds = new RectangleF(PointF.Empty, page.Graphics.ClientSize);
// Draw the text element.
element.Draw(page, bounds, layoutFormat);
// Save the PDF document to disk.
pdfDoc.Save("Test.pdf");
// Use the following code to stream the document to the browser.
// pdfDoc.Save("Test.pdf", Response, HttpResponseType.OpenInsideBrowser); // Response is an HttpResponse object.
// Close the document.
pdfDoc.Close();
VB.NET
' Create a new PDF document. This object represents the PDF document.
' This document has one page, by default. Additional pages have to be added.
Dim pdfDoc As New PdfDocument()
' Add a page to the document
Dim page As PdfPage = pdfDoc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold)
' Create a text element with large amount of text.
Dim element As New PdfTextElement("Text Element", font)
' Set the properties for the text element.
element.Brush = New PdfSolidBrush(Color.Black)
Dim format As New PdfStringFormat(PdfTextAlignment.Right)
' Set the string format. This can be used for setting unicode text.
element.StringFormat = format
' Set the layout format properties to make the text flow through multiple pages.
Dim layoutFormat As New PdfLayoutSettings()
layoutFormat.Break = PdfLayoutBreakType.FitPage
layoutFormat.Layout = PdfLayoutType.Paginate
' Set the bounds.
Dim bounds As New RectangleF(PointF.Empty, page.Graphics.ClientSize)
' Draw the text element.
element.Draw(page, bounds, layoutFormat)
' Save the PDF document to disk.
pdfDoc.Save("Test.pdf")
' Use the following code to stream the document to the browser.
' pdfDoc.Save("Test.pdf", Response, HttpResponseType.OpenInsideBrowser); // Response is an HttpResponse object.
' Close the document.
pdfDoc.Close()

3. String Formatting

For dedicated presentation of text in a PDF document, use a PdfStringFormat object. PdfStringFormat class provides support for the following features:

Formatting a text in a PDF document is very easy with the UltimatePdf component. By using the PdfStringFormat class, you can quickly set character spacing, word spacing, and line spacing. In addition, it also lets you format your text area with Center, Left, Right and Justify text alignments. You can also set Right-To-Left text align for languages such as Arabic, Hebrew, Urdu, and so on.

4. RTF Support

The UltimatePdf component fully supports converting RTF document to PDF document. A RTF text can either be converted to metafile image or raster image. To convert a RTF text, simply use the FromRtf methods of the PdfImage class.

Adding and removing a new page

Creating a page 


Firstly, you need to load an existing document by using the PdfImportedDocument class and then add a new page to the loaded document by calling doc.Pages.Add method. The following example illustrates how to do that.

C#

PdfImportedDocument lDoc = new PdfImportedDocument("myfile.pdf");
PdfPage page = lDoc.Pages.Add() as PdfPage;
// Use the predefined fonts to draw the text.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10.0f, PdfFontStyle.Regular);
PdfGraphics g = page.Graphics;
g.DrawString("My Text", font, PdfBrushes.Black, PointF.Empty);
lDoc.Save("AddNewPages.pdf");
lDoc.Close();

VB.NET

Dim lDoc As New PdfImportedDocument("myfile.pdf")
Dim page As PdfPage = TryCast(lDoc.Pages.Add(), PdfPage)
' Use the predefined fonts to draw the text.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10.0F, PdfFontStyle.Regular)
Dim g As PdfGraphics = page.Graphics
g.DrawString("My Text", font, PdfBrushes.Black, PointF.Empty)
lDoc.Save("AddNewPages.pdf")
lDoc.Close()

Removing a page 


You can also remove pages from the existing PDF document by using the Remove or RemoveAt methods of the PdfImportedPageCollection class.


The following code example illustrates this.

C#:

PdfImportedDocument lDoc = new PdfImportedDocument("myfile.pdf");
// Remove the first page.
lDoc.Pages.RemoveAt(0);
lDoc.Pages.Remove(lDoc.Pages[0]);
lDoc.Save("AddNewPages.pdf");
lDoc.Close();

VB.NET

Dim lDoc As New PdfImportedDocument("myfile.pdf")
' Remove the first page.
lDoc.Pages.RemoveAt(0)
lDoc.Pages.Remove(lDoc.Pages(0))
lDoc.Save("AddNewPages.pdf")
lDoc.Close()

ComponentSoft Introduces Ultimate PDF for .NET

Ultimate PDF for .NET is a 100%-managed PDF document component that helps you to add PDF capabilities in your .NET applications. With a few lines of code, you can create a complex PDF document from scratch or load an existing PDF file. In addition to the ease-of-use and flexibility, Ultimate PDF component also offers many features including: drawing text, image, tables and other shapes, compression, hyperlinks, security and custom fonts. PDF files created using the Ultimate PDF component are compatible with all versions of Adobe Acrobat and the free version of Acrobat Viewer from Adobe.

Sample Usage - Drawing a string

C#

 const PdfFontStyle fontStyle = PdfFontStyle.Regular;
 const float fontSize = 12.0f;
 // Create a new PDF document. This object represents the PDF document.
 PdfDocument pdfDoc = new PdfDocument();
 // Add a page to the document
 PdfPage page = pdfDoc.Pages.Add();
 // Use the predefined fonts to draw the text.
 PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize,
 fontStyle);
 // Draw the string at the specified coordinates.
 page.Graphics.DrawString("Hello World", font, PdfBrushes.Black, 0, 0);
 // Save the PDF document to disk.
 pdfDoc.Save("HelloWorld.pdf");
 // Use the following code to stream the document to the browser.
 // pdfDoc.Save("HelloWorld.pdf", Response,
 //       HttpResponseType.OpenInsideBrowser); 
 // Response is an HttpResponse object.
 // Close the document.
 pdfDoc.Close(); 

VB.NET

 Const fontStyle As PdfFontStyle = PdfFontStyle.Regular
 Const fontSize As Single = 12.0F
 ' Create a new PDF document. This object represents the PDF document.
 Dim pdfDoc As New PdfDocument()
 ' Add a page to the document
 Dim page As PdfPage = pdfDoc.Pages.Add()
 ' Use the predefined fonts to draw the text.
 Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 
 fontSize, fontStyle)
 ' Draw the string at the specified coordinates.
 page.Graphics.DrawString("Hello World", font, PdfBrushes.Black, 0, 0)
 ' Save the PDF document to disk.
 pdfDoc.Save("HelloWorld.pdf")
 ' Use the following code to stream the document to the browser.
 ' pdfDoc.Save("HelloWorld.pdf", Response, 
 '    HttpResponseType.OpenInsideBrowser); 
 ' Response is an HttpResponse object.
 ' Close the document.
 pdfDoc.Close() 

Supports many .NET Platforms

Ultimate PDF Component for .NET supports the following platforms:

  • Windows Forms
  • Web Forms
  • Web Services

In addition, it is also possible to use the component in PowerShell - Microsoft’s new command console and scripting language.

Ultimate PDF is fully compatible with Visual Studio 2005 and Visual Studio 2008, as well as upcomming release of Visual Studio 2010. As a benefit, you are always up-to-date with Microsoft's Technologies when using our products.

Flexibility

The PDF component can be used with a wide variety of programming languages and different types of development environments. As it was written in 100% managed Visual C#, it is fully supported by languages such as Visual Basic, Visual C#, J#, Managed C++, Borland C# Builder, and Delphi.

Fully Documented

We know that no product can be complete without comprehensive documentation. This is why the Ultimate PDF for .NET product includes a Developer's Guide and a complete Technical Reference which documents every property, method and event supported by the component. A context-sensitive online help is included with the product which can be accessed directly from within the development environment.

Lots of complete PDF samples in VB.NET, C#, and ASP.NET

In addition to the fully documented Developer's Guide and a complete Technical Reference, Ultimate PDF component also includes a number of samples with full source code which help you to become familiar with the features of the component and provide code which you can re-use in your own applications.

Royalty-free and Unlimited Server Deployment

All ComponentSoft products include royalty-free distributation, for unlimited site deployment. It means applications built using the Ultimate PDF component can be redistributed to as many end-users as needed without additional royalties or runtime licensing fees.