public void Draw(PdfContentByte cb, Document doc) { int currentlyDrawingYPosition = DOCUMENTHEIGHT; for (int i = 0; i < productWindows.Count; i++) { ProductWindow prodWindow = productWindows[i]; currentlyDrawingYPosition -= prodWindow.GetHeight(); if (currentlyDrawingYPosition <= 0) { doc.NewPage(); currentlyDrawingYPosition = DOCUMENTHEIGHT - prodWindow.GetHeight(); } prodWindow.Draw(cb, currentlyDrawingYPosition); } }
static void Main(string[] args) { System.IO.FileStream fs = new FileStream("First PDF document.pdf", FileMode.Create); //Create pdf structure and content ProductWindow prodWindow = new ProductWindow("MOK_ALLES_GROEN"); prodWindow.AddSpecification("Resolution", "300"); prodWindow.AddSpecification("Width", "400"); prodWindow.AddSpecification("Height", "200"); prodWindow.AddSpecification("Glans", "Inderdaad"); prodWindow.AddSummary("Green mug for a nice cuppa tea"); ProductWindow prodWindow1 = new ProductWindow("WOOP"); prodWindow1.AddSpecification("Resolution", "300"); prodWindow1.AddSpecification("Width", "400"); prodWindow1.AddSpecification("Height", "200"); prodWindow1.AddSpecification("Glans", "Inderdaad"); prodWindow1.AddSpecification("Width", "400"); prodWindow1.AddSpecification("Height", "200"); prodWindow1.AddSpecification("Glans", "Inderdaad"); prodWindow1.AddSummary("Green mug for a nice cuppa tea"); ProductWindow prodWindow2 = new ProductWindow("GELE_BANAAN"); prodWindow2.AddSpecification("Resolution", "300"); prodWindow2.AddSpecification("Width", "400"); prodWindow2.AddSpecification("Height", "200"); prodWindow2.AddSpecification("Glans", "Inderdaad"); prodWindow2.AddSummary("Green mug for a nice cuppa tea"); ProductWindow prodWindow3 = new ProductWindow("MOK_ALLES_GROEN"); prodWindow3.AddSpecification("Resolution", "300"); prodWindow3.AddSpecification("Width", "400"); prodWindow3.AddSpecification("Height", "200"); prodWindow3.AddSpecification("Glans", "Inderdaad"); prodWindow3.AddSummary("Green mug for a nice cuppa tea"); //Window manager manages the layout of all the products WindowManager pageManager = new WindowManager(); pageManager.Add(prodWindow); pageManager.Add(prodWindow1); pageManager.Add(prodWindow2); pageManager.Add(prodWindow3); Document document = new Document(PageSize.A4, 0, 0, 0, 0); PdfWriter writer = PdfWriter.GetInstance(document, fs); document.Open(); PdfContentByte cb = writer.DirectContent; //Purple background for layout testing //cb.SetColorFill(new BaseColor(255, 0, 255)); //cb.Rectangle(0, 0, 595, 842); //cb.Fill(); pageManager.Draw(cb, document); //Draw debug info //BaseFont f_cb = BaseFont.CreateFont("c:\\windows\\fonts\\calibrib.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //cb.SetFontAndSize(f_cb, 12); //DrawPDFDebugInfo(cb); document.Close(); // Close the writer instance writer.Close(); // Always close open filehandles explicity fs.Close(); }
public void Add(ProductWindow window) { productWindows.Add(window); }