/** * Draws the point, text and borders of this cell. */ internal void Paint( Page page, float x, float y, float w, float h) { if (background != -1) { DrawBackground(page, x, y, w, h); } if (image != null) { if (GetTextAlignment() == Align.LEFT) { image.SetLocation(x + leftPadding, y + topPadding); image.DrawOn(page); } else if (GetTextAlignment() == Align.CENTER) { image.SetLocation((x + w / 2f) - image.GetWidth() / 2f, y + topPadding); image.DrawOn(page); } else if (GetTextAlignment() == Align.RIGHT) { image.SetLocation((x + w) - (image.GetWidth() + leftPadding), y + topPadding); image.DrawOn(page); } } if (barCode != null) { try { if (GetTextAlignment() == Align.LEFT) { barCode.DrawOnPageAtLocation(page, x + leftPadding, y + topPadding); } else if (GetTextAlignment() == Align.CENTER) { float barcodeWidth = barCode.DrawOn(null)[0]; barCode.DrawOnPageAtLocation(page, (x + w / 2f) - barcodeWidth / 2f, y + topPadding); } else if (GetTextAlignment() == Align.RIGHT) { float barcodeWidth = barCode.DrawOn(null)[0]; barCode.DrawOnPageAtLocation(page, (x + w) - (barcodeWidth + leftPadding), y + topPadding); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } if (textBlock != null) { textBlock.SetLocation(x + leftPadding, y + topPadding); textBlock.DrawOn(page); } DrawBorders(page, x, y, w, h); if (text != null && !text.Equals("")) { DrawText(page, x, y, w, h); } if (point != null) { if (point.align == Align.LEFT) { point.x = x + 2 * point.r; } else if (point.align == Align.RIGHT) { point.x = (x + w) - this.rightPadding / 2; } point.y = y + h / 2; page.SetBrushColor(point.GetColor()); if (point.GetURIAction() != null) { page.AddAnnotation(new Annotation( point.GetURIAction(), null, point.x - point.r, point.y - point.r, point.x + point.r, point.y + point.r, null, null, null)); } page.DrawPoint(point); } if (drawable != null) { drawable.SetPosition(x + leftPadding, y + topPadding); drawable.DrawOn(page); } }
/// <summary> /// Populate a voter card with the information of a given voter. /// </summary> /// <param name="page">The page containing the card.</param> /// <param name="pdf">The pdf containing the page.</param> /// <param name="xO">The horizontal offset of the card in points.</param> /// <param name="yO">The vertical offset of the card in points.</param> /// <param name="voter">The voter whose information to be populated onto the card.</param> private static void PopulateCard(Page page, PDF pdf, double xO, double yO, VoterDO voter) { // ----- POPULATE: POLLING STATION ----- PollingStationDO ps = voter.PollingStation; var font = new Font(pdf, CoreFont.HELVETICA); font.SetSize(9); var t = new TextLine(font, ps.Name); t.SetPosition(xO + 9 * U, yO + 27.5 * U); t.DrawOn(page); t = new TextLine(font, ps.Address); t.SetPosition(xO + 9 * U, yO + 32 * U); t.DrawOn(page); t = new TextLine(font, "valgfrit"); t.SetPosition(xO + 29 * U, yO + 48.8 * U); t.DrawOn(page); t = new TextLine(font, "02-04861"); t.SetPosition(xO + 29 * U, yO + 58.7 * U); t.DrawOn(page); t = new TextLine(font, "09:00 - 20:00"); t.SetPosition(xO + 29 * U, yO + 68.2 * U); t.DrawOn(page); // ----- POPULATE: VOTER ----- MunicipalityDO mun = voter.PollingStation.Municipality; font = new Font(pdf, CoreFont.COURIER); font.SetSize(10); // Add top voter number 'Vælgernr.' t = new TextLine(font, "02-04861"); t.SetPosition(xO + 102 * U, yO + 12 * U); t.DrawOn(page); // Add sender 'Afsender' t = new TextLine(font, mun.Name); t.SetPosition(xO + 102 * U, yO + 32.5 * U); t.DrawOn(page); t = new TextLine(font, mun.Address); t.SetPosition(xO + 102 * U, yO + 36.5 * U); t.DrawOn(page); t = new TextLine(font, mun.City); t.SetPosition(xO + 102 * U, yO + 40.5 * U); t.DrawOn(page); // Add reciever 'Modtager' t = new TextLine(font, voter.Name); t.SetPosition(xO + 102 * U, yO + 62.5 * U); t.DrawOn(page); t = new TextLine(font, voter.Address); t.SetPosition(xO + 102 * U, yO + 66.5 * U); t.DrawOn(page); t = new TextLine(font, voter.City); t.SetPosition(xO + 102 * U, yO + 70.5 * U); t.DrawOn(page); // Add CPR barcode string barcode = BarCodeHashing.Hash(voter.PrimaryKey.Value).ToString(); var b = new BarCode(BarCode.CODE128, barcode); b.SetPosition(xO + 160 * U, yO + 60 * U); b.DrawOn(page); t = new TextLine(font, barcode); t.SetPosition(xO + 160 * U, yO + 72 * U); t.DrawOn(page); }