Exemplo n.º 1
0
    public Example_29()
    {
        PDF pdf = new PDF(new BufferedStream(
                              new FileStream("Example_29.pdf", FileMode.Create)));

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

        Font font = new Font(pdf, CoreFont.HELVETICA);

        font.SetSize(16f);

        Paragraph paragraph = new Paragraph();

        paragraph.Add(new TextLine(font, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum interdum elit, quis vehicula urna interdum quis. Phasellus gravida ligula quam, nec blandit nulla. Sed posuere, lorem eget feugiat placerat, ipsum nulla euismod nisi, in semper mi nibh sed elit. Mauris libero est, sodales dignissim congue sed, pulvinar non ipsum. Sed risus nisi, ultrices nec eleifend at, viverra sed neque. Integer vehicula massa non arcu viverra ullamcorper. Ut id tellus id ante mattis commodo. Donec dignissim aliquam tortor, eu pharetra ipsum ullamcorper in. Vivamus ultrices imperdiet iaculis."));

        TextColumn column = new TextColumn();

        column.SetLocation(50f, 50f);
        column.SetSize(540f, 0f);
        // column.SetLineBetweenParagraphs(true);
        column.SetLineBetweenParagraphs(false);
        column.AddParagraph(paragraph);

        Dimension dim0 = column.GetSize();

        float[]   point1 = column.DrawOn(page);
        float[]   point2 = column.DrawOn(null);
        Dimension dim1   = column.GetSize();
        Dimension dim2   = column.GetSize();
        Dimension dim3   = column.GetSize();

/*
 *      Console.WriteLine("height0: " + dim0.GetHeight());
 *      Console.WriteLine("point1.x: " + point1.GetX() + "    point1.y " + point1.GetY());
 *      Console.WriteLine("point2.x: " + point2.GetX() + "    point2.y " + point2.GetY());
 *      Console.WriteLine("height1: " + dim1.GetHeight());
 *      Console.WriteLine("height2: " + dim2.GetHeight());
 *      Console.WriteLine("height3: " + dim3.GetHeight());
 *      Console.WriteLine();
 */
        column.RemoveLastParagraph();
        column.SetLocation(50f, point2[1]);
        paragraph = new Paragraph();
        paragraph.Add(new TextLine(font, "Peter Blood, bachelor of medicine and several other things besides, smoked a pipe and tended the geraniums boxed on the sill of his window above Water Lane in the town of Bridgewater."));
        column.AddParagraph(paragraph);

        Dimension dim4 = column.GetSize();

        float[] xy = column.DrawOn(page);  // Draw the updated text column

/*
 *      Console.WriteLine("point.x: " + xy[0] + "    point.y " + xy[1]);
 *      Console.WriteLine("height4: " + dim4.GetHeight());
 */
        Box box = new Box();

        box.SetLocation(xy[0], xy[1]);
        box.SetSize(540f, 25f);
        box.SetLineWidth(2f);
        box.SetColor(Color.darkblue);
        box.DrawOn(page);

        pdf.Complete();
    }
Exemplo n.º 2
0
    public Example_10()
    {
        int rotate = 0;
        // int rotate = 90;
        // int rotate = 270;

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

        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, FileAccess.Read), ImageType.PNG);

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

        f1.SetSize(10f);

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

        f2.SetSize(14f);

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

        f3.SetSize(12f);

        Font f4 = new Font(pdf, CoreFont.HELVETICA_OBLIQUE);

        f4.SetSize(10f);

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

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

        TextColumn column = new TextColumn(rotate);

        column.SetSpaceBetweenLines(5.0f);
        column.SetSpaceBetweenParagraphs(10.0f);

        Paragraph p1 = new Paragraph();

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

        Paragraph p2 = new Paragraph();

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

        StringBuilder buf = new StringBuilder();

        buf.Append("The Swiss Confederation was founded in 1291 as a defensive ");
        buf.Append("alliance among three cantons. In succeeding years, other ");
        buf.Append("localities joined the original three. ");
        buf.Append("The Swiss Confederation secured its independence from the ");
        buf.Append("Holy Roman Empire in 1499. Switzerland's sovereignty and ");
        buf.Append("neutrality have long been honored by the major European ");
        buf.Append("powers, and the country was not involved in either of the ");
        buf.Append("two World Wars. The political and economic integration of ");
        buf.Append("Europe over the past half century, as well as Switzerland's ");
        buf.Append("role in many UN and international organizations, has ");
        buf.Append("strengthened Switzerland's ties with its neighbors. ");
        buf.Append("However, the country did not officially become a UN member ");
        buf.Append("until 2002.");

        Paragraph p3 = new Paragraph();

        // p3.SetAlignment(Align.LEFT);
        // p3.SetAlignment(Align.RIGHT);
        p3.SetAlignment(Align.JUSTIFY);
        TextLine text = new TextLine(f1, buf.ToString());

        text.SetFont(f1);
        p3.Add(text);

        buf = new StringBuilder();
        buf.Append("Switzerland remains active in many UN and international ");
        buf.Append("organizations but retains a strong commitment to neutrality.");

        text = new TextLine(f1, buf.ToString());
        text.SetColor(Color.red);
        p3.Add(text);

        Paragraph p4 = new Paragraph();

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

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

        Paragraph p5 = new Paragraph();

        p5.SetAlignment(Align.JUSTIFY);
        text = new TextLine(f1, buf.ToString());
        p5.Add(text);

        text = new TextLine(f4,
                            "Even so, unemployment has remained at less than half the EU average.");
        text.SetColor(Color.blue);
        p5.Add(text);

        Paragraph p6 = new Paragraph();

        p6.SetAlignment(Align.RIGHT);
        text = new TextLine(f1, "Source: The world fact book.");
        text.SetColor(Color.blue);
        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);

        if (rotate == 0)
        {
            column.SetLocation(90f, 300f);
        }
        else if (rotate == 90)
        {
            column.SetLocation(90f, 780f);
        }
        else if (rotate == 270)
        {
            column.SetLocation(550f, 310f);
        }

        float columnWidth = 470f;

        column.SetSize(columnWidth, 100f);
        float[] xy = column.DrawOn(page);

        Line line = new Line(
            xy[0],
            xy[1],
            xy[0] + columnWidth,
            xy[1]);

        line.DrawOn(page);

        pdf.Complete();
    }