First of all I must admire the great effort put in this product.You PPl rock
Actually I am using pdf sharp to generate invoices but the problem i am gettin is how to add new pages in my case Here is code I have done it generates pdf from database.
Code:
public void create(XGraphics gfx)
{
double total = 0;
XRect rect;
XPen pen = new XPen(XColors.DarkBlue, 2.5);
double x = 50, y = 20;
XFont fontH1 = new XFont("Times", 25, XFontStyle.Bold);
XFont font = new XFont("Times", 12, XFontStyle.Bold);
XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
double ls = font.GetHeight(gfx);
gfx.DrawImage(XImage.FromFile("../../Resources/Logo.gif"), 20, 10);
gfx.DrawString("Invoice",fontH1, XBrushes.Black, this.ClientSize.Width/2.8, 35);
gfx.DrawString("89/R-1, Johar Town Lahore ", font, XBrushes.Black, 420, 20);
y += ls;
gfx.DrawString("0321-4133607,0321-4133607", font, XBrushes.Black, 420, y);
y += 3*ls;
gfx.DrawString("Name: "+name, font, XBrushes.Black, 20, y);
gfx.DrawString("Make: " + make, font, XBrushes.Black, 250, y);
y += ls;
gfx.DrawString("Contact: " + contact, font, XBrushes.Black, 20, y);
gfx.DrawString("Reg #: " + reg, font, XBrushes.Black, 250, y);
y += ls;
gfx.DrawString("Address: " + add, font, XBrushes.Black, 20, y);
gfx.DrawString("Milage: " + milage+" Kilometers", font, XBrushes.Black, 250, y);
y += ls;
gfx.DrawLine(pen, 20, y, 590, y);
gfx.DrawLine(pen, 60, y, 60, 750);
gfx.DrawLine(pen, 340, y, 340, 750);
gfx.DrawLine(pen, 390, y, 390, 750);
gfx.DrawLine(pen, 470, y, 470, 750);
gfx.DrawLine(pen, 20, 750, 590, 750);
y += 1.2*ls;
gfx.DrawString("Sr #", font, XBrushes.Black, 26, y);
gfx.DrawString("Description", font, XBrushes.Black, 100, y);
gfx.DrawString("Qty", font, XBrushes.Black, 350, y);
gfx.DrawString("Price/Uint", font, XBrushes.Black, 400, y);
gfx.DrawString("Price (PKR)", font, XBrushes.Black, 490, y);
y += 0.8 * ls;
gfx.DrawLine(pen, 20, y, 590, y);
y += 1 * ls;
//cmd.Parameters.Add("@jCard", SqlDbType.VarChar).Value = jobCardid;
cmd.CommandText = "SELECT jobTitle,jLab FROM Jobs WHERE jCardId = @jcard";
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows == true)
{
int i = 0;
while (reader.Read())
{
i++;
gfx.DrawString(i.ToString(), font, XBrushes.Black, 28, y);
gfx.DrawString(reader["jobTitle"].ToString(), font, XBrushes.Black, 70, y);
gfx.DrawString(reader["jLab"].ToString(), font, XBrushes.Black, 490, y);
total += double.Parse(reader["jLab"].ToString());
y += 1 * ls;
}
}
gfx.DrawString("Powered by Xeo Technologies", font, XBrushes.Purple, 20, 766);
gfx.DrawImage(XImage.FromFile("../../Resources/Xeosoft.gif"), 180, 755);
gfx.DrawString("03454191007", font, XBrushes.Purple, 20, 780);
gfx.DrawString("G.Total", fontH1, XBrushes.Black, 350, 775);
gfx.DrawString(total.ToString(), fontH1, XBrushes.Red, 440, 775);
reader.Close();
rect = new XRect(x + 230, y, 100, 60);
}
and of course constructor
Code:
public PDFInvoiceJob(int jobcard)
{
InitializeComponent();
this.jobCardid = jobcard;
renderEvent = new PagePreview.RenderEvent(create);
pagePreview.SetRenderEvent(renderEvent);
this.pagePreview.PageSize= PageSizeConverter.ToSize(PageSize.A4);
this.pagePreview.Zoom = Zoom.BestFit;
}