Click here to Skip to main content
15,897,891 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.Text;
using System.Drawing;

namespace SmartPdf
{
	public class PdfRectangle : PdfObject
	{
		
		internal PdfArea rectangleArea;
		public PdfArea RectangleArea
		{
			get
			{
				return this.rectangleArea;
			}
		}
		internal Color BorderColor=Color.Black,FillingColor;
		internal bool bordered,filled;
		internal double strokeWidth;
		public double StrokeWidth
		{
			set
			{
				this.strokeWidth=value;
			}
			get
			{
				return this.strokeWidth;
			}
		}		
		
		public PdfRectangle(PdfArea RectangleArea,Color BorderColor)
		{
			this.rectangleArea=RectangleArea;
			this.BorderColor=BorderColor;
			this.bordered=true;
			this.strokeWidth=1;
		}
		public PdfRectangle(PdfArea RectangleArea,Color BorderColor,double BorderWidth)
		{
			this.rectangleArea=RectangleArea;
			this.BorderColor=BorderColor;
			this.bordered=true;
			this.strokeWidth=BorderWidth;
		}
		
		public PdfRectangle(PdfArea RectangleArea,Color BorderColor,Color FillingColor)
		{
			this.rectangleArea=RectangleArea;
			this.BorderColor=BorderColor;
			this.FillingColor=FillingColor;
			this.filled=true;
			this.strokeWidth=1;
			this.bordered=true;
		}
		public PdfRectangle(PdfArea RectangleArea,Color BorderColor,double BorderWidth,Color FillingColor)
		{
			this.rectangleArea=RectangleArea;
			this.BorderColor=BorderColor;
			this.FillingColor=FillingColor;
			this.filled=true;
			this.strokeWidth=BorderWidth;
			this.bordered=true;
		}
		
		public void Fill(Color Color)
		{
			if (!bordered)
			{
				this.bordered=true;
				this.BorderColor=Color;
			}
			this.FillingColor=Color;
			this.filled=true;
		}
		public void Border(Color Color)
		{
			this.bordered=true;
			this.BorderColor=Color;
		}
		internal string ToLineStream()
		{
			string text="";
			if (this.bordered)
			{
				text+=Utility.ColorRGLine(this.BorderColor);
				if (filled) text+=Utility.ColorrgLine(this.FillingColor);
				
				text+=this.strokeWidth.ToString("0.##")+" ";
				text+="w\n";
				
				//text+="100 600 300 100 re\n";
				text+=this.RectangleArea.PosX.ToString("0.##");
				text+=" "+(842-this.rectangleArea.PosY-this.RectangleArea.Height).ToString("0.##")+" ";
				text+=this.RectangleArea.Width.ToString("0.##");
				text+=" "+this.RectangleArea.Height.ToString("0.##")+" re\n";
				if (filled) text+="B";else text+="s";
				text=text.Replace(",",".");
			} else text+="BT\nET";
			text+="\n";
			return text;
		}
		internal override Byte[] ByteStream
		{
			get
			{
				int num=this.id;
				string 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