iTextSharp.text.Document.GetTop C# (CSharp) Метод

GetTop() публичный Метод

Returns the upper right y-coordinate, considering a given margin.
public GetTop ( float margin ) : float
margin float a margin
Результат float
        public float GetTop(float margin)
        {
            return pageSize.GetTop(marginTop + margin);
        }

Usage Example

Пример #1
0
        public void RenderCanvasSheet(Stream stream, IEnumerable<CanvasItemModel> items, UserModel currentUser,UserModel requestedBy, PurchaseRequest Pr, string[] Vendors)
        {
            Document document = new Document(PageSize.LETTER);

            try {
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                document.Open();

                // Create a page in the document and add it to the bottom layer
                document.NewPage();
                //Pass Document to this
                CurrentDoc = document;

                page = writer.DirectContentUnder;
                page.BeginText();
                int top = (int)document.GetTop(0);
                SetFontSizeTo(16);
                PrintText("CANVASS SHEET", 20, 10);
                SetFontSizeTo(10);

                //Header
                PrintText("Company Name: " + requestedBy.CompanyName, 20, 30); // Company Name
                PrintText("Department: " + requestedBy.DepartmentName, 20, 45); // Company Address
                PrintText("Purpose: " + Pr.Purpose, 20, 60); // Purpose
                PrintTextRight("Date: {0}".WithTokens(DateTime.Now.ToShortDateString()), 70, 30); // Date Created
                PrintTextRight("PR No: {0}".WithTokens(Pr.PRNo), 70, 45); // PR Number

                SetFontSizeTo(8);

                // START HERE ----------------------------
                Paragraph Grid = new Paragraph("\n");
                Grid.Alignment = 1;
                Grid.SpacingAfter = 10f;
                document.Add(Grid);

                Paragraph Grid2 = new Paragraph();
                Grid2.Alignment = 1;
                Grid2.SpacingBefore = 35f;
                //Start Table -----------------------------------
                PdfPTable rightTable = new PdfPTable(7);
                int[] widths = { 1, 7, 2, 2, 2, 2, 2 };
                rightTable.SetWidths(widths);
                rightTable.TotalWidth = 570f;
                rightTable.LockedWidth = true;
                Font tableFont = new Font(Font.FontFamily.HELVETICA, 8);

                PdfPCell rightAlignedCell = new PdfPCell();
                rightAlignedCell.HorizontalAlignment = Element.ALIGN_CENTER;

                //Headers
                rightAlignedCell.Phrase = new Phrase("Item No.", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("Item Description", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("Quantity", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase("UOM", tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[0], tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[1], tableFont); rightTable.AddCell(rightAlignedCell);
                rightAlignedCell.Phrase = new Phrase(Vendors[2], tableFont); rightTable.AddCell(rightAlignedCell);

                rightAlignedCell.HorizontalAlignment = Element.ALIGN_RIGHT;

                foreach (var item in items) {
                    string priceVendor1 = item.PriceVendor1 == 0 ? "NONE" : item.PriceVendor1.ToString();
                    string priceVendor2 = item.PriceVendor2 == 0 ? "NONE" : item.PriceVendor2.ToString();
                    string priceVendor3 = item.PriceVendor3 == 0 ? "NONE" : item.PriceVendor3.ToString();
                    rightTable.AddCell(new Phrase(item.ItemNumber.ToString(), tableFont));
                    rightTable.AddCell(new Phrase(item.ItemDescription, tableFont));
                    rightAlignedCell.Phrase = new Phrase(item.Quantity.ToString(), tableFont); rightTable.AddCell(rightAlignedCell);
                    rightTable.AddCell(new Phrase(item.UOM, tableFont));
                    rightAlignedCell.Phrase = new Phrase(priceVendor1, tableFont); rightTable.AddCell(rightAlignedCell);
                    rightAlignedCell.Phrase = new Phrase(priceVendor2, tableFont); rightTable.AddCell(rightAlignedCell);
                    rightAlignedCell.Phrase = new Phrase(priceVendor3, tableFont); rightTable.AddCell(rightAlignedCell);
                }
                Grid2.Add(rightTable);
                document.Add(Grid2);

                // Footer
                SetFontSizeTo(10);
                PrintTextBottom("Requested By:", 20, 105);
                PrintTextBottom("{0} {1}".WithTokens(requestedBy.FirstName, requestedBy.LastName), 20, 35);

                PrintTextBottom("Prepared By:", 265, 105);
                PrintTextBottom("{0} {1}".WithTokens(currentUser.FirstName, currentUser.LastName), 265, 35);

                PrintTextBottom("Approved By:", 450, 105);
                PrintTextBottom("{0}".WithTokens("______________________"), 450, 35);

                page.EndText();

                writer.Flush();
            }
            finally {
                document.Close();
            }
        }
All Usage Examples Of iTextSharp.text.Document::GetTop