Click here to Skip to main content
15,892,517 members
Articles / Programming Languages / C#

Gios PDF .NET library

Rate me:
Please Sign up or sign in to vote.
4.89/5 (157 votes)
18 Apr 2005LGPL32 min read 2.2M   13.1K   558  
A .NET library for generating impressive PDF reports.
using System;
using System.Drawing;
using System.Text;

namespace SmartPdf
{
	public class PdfGrid : PdfObject
	{
		internal bool hRows=true,vRows=true,bounds=true;
		internal Color color=Color.Black;
		internal double strokeWidth=0.5;
		public Color Color
		{
			set
			{
				this.color=value;
			}
			get
			{
				return this.color;
			}
		}
		public double StrokeWidth
		{
			set
			{
				this.strokeWidth=value;
			}
			get
			{
				return this.strokeWidth;
			}
		}		
		internal PdfArea gridArea;
		public PdfArea GridArea
		{
			get
			{
				return gridArea;
			}
			set
			{
				gridArea=value;
			}
		}
		internal int columns,rows;
		public int Columns
		{
			get
			{
				return columns;
			}
			set
			{
				columns=value;
			}
		}
		public int Rows
		{
			get
			{
				return rows;
			}
			set
			{
				rows=value;
			}
		}
		public PdfGrid(PdfArea GridArea,int Columns,int Rows,Color BorderColor)
		{
			this.rows=Rows;
			this.columns=Columns;
			this.gridArea=GridArea;
			this.color=BorderColor;
		}
		internal string ToLineStream()
		{
			string text="";
			if (this.hRows)
			{
				double vstep=(this.gridArea.height/this.rows);
				for (double y=this.gridArea.posy+vstep;y<this.gridArea.BottomRightCornerY;y+=vstep)
				{
					text+=new PdfLine(new PointF(gridArea.posx,(float)y),
						new PointF(gridArea.BottomRightCornerX,(float)y),color,strokeWidth).ToLineStream();
				}
			}
			if (this.vRows)
			{
				double hstep=(this.gridArea.width/this.columns);
				for (double x=this.gridArea.posx+hstep;x<this.gridArea.BottomRightCornerX;x+=hstep)
				{
					text+=new PdfLine(new PointF((float)x,gridArea.posy),
						new PointF((float)x,gridArea.BottomRightCornerY),color,strokeWidth).ToLineStream();
				}
			}
			if (this.bounds)
			{
				text+=new PdfRectangle(this.gridArea,this.color,this.strokeWidth).ToLineStream();
			}
			return text;
		}
		internal override Byte[] ByteStream
		{
			get
			{
				int num=this.id;
				string text="";
				text+=Utility.ColorRGLine(this.color);
				text+=this.strokeWidth.ToString("0.##")+" ";
				text+="w\n";
				text=text.Replace(",",".");

				text+=this.ToLineStream();

				string s="";
				s+=num.ToString()+" 0 obj\n";
				s+="<< /Lenght "+text.Length+" >>\n";
				s+="stream\n";
				s+=text;
				s+="endstream\n";
				s+="endobj\n";

				return ASCIIEncoding.ASCII.GetBytes(s);
			}

		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Italy Italy
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

my homepage is: http://www.paologios.com

Comments and Discussions