Using TextColumn, Paragraph and TextLine classes

Example_10.pdf
using System;
using System.IO;
using System.Text;

using PDFjet.NET;


/**
 *  Example_10.cs
 *
 */
public class Example_10 {

    public Example_10() {

        FileStream fos = new FileStream("Example_10.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);
        // Before you enable this flag please read PDFJET.ZLIB.TXT
        // in the "optional" directory.
        // pdf.setCompressor(Compressor.ORIGINAL_ZLIB);

        pdf.SetTitle("Using TextColumn and Paragraph classes");
        pdf.SetSubject("Examples");
        pdf.SetAuthor("Innovatics Inc.");

        String fileName = "images/sz-map.png";
        Image image1 = new Image(
                pdf, new FileStream(fileName, FileMode.Open), ImageType.PNG);

        Font f1 = new Font(pdf, CoreFont.HELVETICA);
        Font f2 = new Font(pdf, CoreFont.HELVETICA_BOLD);
        Font f3 = new Font(pdf, CoreFont.HELVETICA_BOLD);

        Page page = new Page(pdf, Letter.PORTRAIT);

        f1.SetSize(10);
        f2.SetSize(14);
        f3.SetSize(12);

        image1.SetPosition(90, 35);
        image1.ScaleBy(0.75);
        image1.DrawOn(page);

        TextColumn column = new TextColumn(f1);
        column.SetLineSpacing(1.0);

        // Rotate the TextColumn on 90 degrees
        // TextColumn column = new TextColumn(f1, 90);

        // Rotate the TextColumn on 270 degrees
        // TextColumn column = new TextColumn(f1, 270);

        Paragraph p1 = new Paragraph();
        p1.SetAlignment(Align.CENTER);
        p1.Add(new TextLine(f2, "Switzerland"));

        Paragraph p2 = new Paragraph();
        p2.Add(new TextLine(f2, "Introduction"));

        Paragraph p3 = new Paragraph();
        p3.SetAlignment(Align.JUSTIFY);
        // p3.SetAlignment(Align.LEFT);
        TextLine text = new TextLine(f2);
        text.SetText("The Swiss Confederation was founded in 1291 as a defensive alliance among three cantons. In succeeding years, other localities joined the original three. The Swiss Confederation secured its independence from the Holy Roman Empire in 1499. Switzerland's sovereignty and neutrality have long been honored by the major European powers, and the country was not involved in either of the two World Wars. The political and economic integration of Europe over the past half century, as well as Switzerland's role in many UN and international organizations, has strengthened Switzerland's ties with its neighbors. However, the country did not officially become a UN member until 2002. Switzerland remains active in many UN and international organizations but retains a strong commitment to neutrality.");
        text.SetFont(f1);
        p3.Add(text);

        Paragraph p4 = new Paragraph();
        p4.Add(new TextLine(f3, "Economy"));

        Paragraph p5 = new Paragraph();
        p5.SetAlignment(Align.JUSTIFY);
        text = new TextLine(f1);
        text.SetText("Switzerland is a peaceful, prosperous, and stable modern market economy with low unemployment, a highly skilled labor force, and a per capita GDP larger than that of the big Western European economies. The Swiss in recent years have brought their economic practices largely into conformity with the EU's to enhance their international competitiveness. Switzerland remains a safehaven for investors, because it has maintained a degree of bank secrecy and has kept up the franc's long-term external value. Reflecting the anemic economic conditions of Europe, GDP growth stagnated during the 2001-03 period, improved during 2004-05 to 1.8% annually and to 2.9% in 2006. Even so, unemployment has remained at less than half the EU average.");
        p5.Add(text);

        Paragraph p6 = new Paragraph();
        p6.SetAlignment(Align.RIGHT);
        text = new TextLine(f1);
        text.SetColor(RGB.BLUE);
        text.SetText("Source: The world fact book.");
        text.SetURIAction("https://www.cia.gov/library/publications/the-world-factbook/geos/sz.html");
        p6.Add(text);

        column.AddParagraph(p1);
        column.AddParagraph(p2);
        column.AddParagraph(p3);
        column.AddParagraph(p4);
        column.AddParagraph(p5);
        column.AddParagraph(p6);

        column.SetPosition(90, 300); //  0 degree rotation
        // column.SetPosition(90, 780); // 90 degree rotation
        // column.SetPosition(550, 310); // 270 degree rotation

        column.SetSize(470.0, 100.0);
        Point point = column.DrawOn(page);

        Line line = new Line(
                point.GetX(), point.GetY(),
                point.GetX() + 470.0, point.GetY());
        line.DrawOn(page);

        pdf.Flush();
        bos.Close();
    }


    public static void Main(String[] args) {
        try {
            new Example_10();
        } catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }

}   // End of Example_10.cs

© 2011 Innovatics Inc.