PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Create PDF in C#
- Text formatting
- How to add page numbers to your PDF
- Append multiple PDF documents
- Add text field to PDF
- Convert XHTML to PDF
- Add footer with left and right aligned text on same line
- XhtmlParagraph and TrueType fonts
- What is the resulting fontsize in PDF for rich text used in a SimpleXhtmlShape
- Read and write meta data from PDF
- Merge PDF
- Stitch PDF documents
- Convert TXT to PDF
- Bulleted list from XML and XSL
- Use multiple licenses
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
Calculate the height of a paragraph in PDF
This code sample demonstrates how to use the event mechanism to calculate the height of a paragraph in a PDF. The program writes the height of the paragraph to the console.
using System;
using System.IO;
using TallComponents.PDF;
using TallComponents.PDF.Layout;
using TallComponents.PDF.Layout.Paragraphs;
namespace CalculateParagraphHeight
{
class Program
{
static double startY;
static double endY;
static void Main(string[] args)
{
Document document = new Document();
Section section = document.Sections.Add();
section.Paragraphs.PrintParagraph +=
new PrintParagraphEventHandler(section_PrintParagraph);
using (FileStream file =
new FileStream(@"..\..\out.pdf", FileMode.Create, FileAccess.Write))
{
document.Write(file);
}
Console.WriteLine("Height: {0:f1} points", startY - endY);
}
static void section_PrintParagraph(
ParagraphCollection sender, PrintParagraphEventArgs e)
{
RtfParagraph rtf = new RtfParagraph();
rtf.Text = File.ReadAllText(@"..\..\sample.rtf");
rtf.EndParagraph += new EndParagraphEventHandler(rtf_EndParagraph);
e.Paragraph = rtf;
startY = e.Top;
}
static void rtf_EndParagraph(Paragraph sender, EndParagraphEventArgs e)
{
endY = e.Bottom;
}
}
}
Download TallPDF.NET 5.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download
We have sent an email with a download link.