0

每当我运行此代码时,我都会收到此错误 - 我已经盯着它看了好几个小时,试图破译正在发生的事情,但它是动态 PDF 内部的东西,所以我无法进入代码来调试它。任何帮助,将不胜感激。

    public void GeneratePDF(Guid id)
    {
        ceTe.DynamicPDF.Document doc = new ceTe.DynamicPDF.Document();
        doc.Author = new IssueTracker.ActiveDirectory.Searcher().FindBySAMAccountName(User.Identity.Name.Remove(0, 5)).DisplayName;
        doc.Creator = "GPO Pricing Application";
        doc.Title = "GPO Pricing Recommendation";

        Page page = new Page(ceTe.DynamicPDF.PageSize.Letter, ceTe.DynamicPDF.PageOrientation.Landscape);

        doc.Pages.Add(page);

        Worksheet worksheet = repo.GetByID(id);

        AddElement(page, "Report Name: ", worksheet.Name, 0, 0 );
        AddElement(page, "Customer Name: ", worksheet.CustomerName, 0, 20);
        AddElement(page, "Allied Group: ", worksheet.AlliedGroup, 0, 40);
        AddElement(page, "City, State: ", worksheet.City + ", " + worksheet.State, 0, 60);
        AddElement(page, "Gross Annual Sales: ", string.Format("{0:C}", worksheet.AnnualSales), 0, 80);

        var Y = 100;
        Table2 table = new Table2(0, Y, 850, 600);
        table.Border.Width = 0.5f;
        table.CellDefault.Border.Width = 0.5f;
        table.Columns.Add(45); // Contract Id
        table.Columns.Add(125); // Product Line
        table.Columns.Add(75); // SKU
        table.Columns.Add(150); // Description
        table.Columns.Add(30);  // Qty
        table.Columns.Add(50); // Current Price (ea)
        table.Columns.Add(50); // Current Spend
        table.Columns.Add(50); // New Price (ea)
        table.Columns.Add(50); // New Spend
        table.Columns.Add(50); // Variance

        Row2 row = table.Rows.Add(10, Font.TimesBold, 8);
        row.CellDefault.VAlign = VAlign.Top;
        row.CellDefault.Align = TextAlign.Center;
        row.Cells.Add("Contract Id");
        row.Cells.Add("Product Line");
        row.Cells.Add("SKU");
        row.Cells.Add("Description");
        row.Cells.Add("Qty");
        row.Cells.Add("Current Price (ea)");
        row.Cells.Add("Current Spend");
        row.Cells.Add("New Price (ea)");
        row.Cells.Add("New Spend");
        row.Cells.Add("Variance");

        var products = productRepository.Get(id);
        foreach(var product in products)
        {
            Y += 20;
            if (Y > 580)
            {
                page.Elements.Add(table);
                page = new Page(ceTe.DynamicPDF.PageSize.Letter, ceTe.DynamicPDF.PageOrientation.Landscape);
                doc.Pages.Add(page);
                table = new Table2(0, Y, 850, 800);
                Y = 0;
                row = table.Rows.Add(10, Font.TimesBold, 8);
                row.CellDefault.VAlign = VAlign.Top;
                row.CellDefault.Align = TextAlign.Center;
                row.Cells.Add("Contract Id"); //*********** This is where I get the error
                row.Cells.Add("Product Line");
                row.Cells.Add("SKU");
                row.Cells.Add("Description");
                row.Cells.Add("Qty");
                row.Cells.Add("Current Price (ea)");
                row.Cells.Add("Current Spend");
                row.Cells.Add("New Price (ea)");
                row.Cells.Add("New Spend");
                row.Cells.Add("Variance");
            }
            row = table.Rows.Add(10, Font.TimesRoman, 8);
            row.CellDefault.Align = TextAlign.Center;
            Cell2 contractId = row.Cells.Add(product.record.ContractId);
            Cell2 productLine = row.Cells.Add(product.record.ProductLine);
            Cell2 sku = row.Cells.Add(product.record.LongItemNbr);
            Cell2 description = row.Cells.Add(product.record.Description);
            Cell2 qty = row.Cells.Add(product.Qty.ToString());
            Cell2 currentPrice = row.Cells.Add(string.Format("{0:C}", product.record.DirectPriceEaches));
            Cell2 currentSpend = row.Cells.Add(string.Format("{0:C}", product.Spend));
        }

        doc.DrawToWeb("GPO Pricing Recommendation.pdf");
    }

    private void AddElement(Page page, string label, string data, int x, int y)
    {
        Label Label = new Label(label, x, y, 140, 14, Font.TimesRoman, 14, TextAlign.Right);
        Label Data = new Label(data, x + 145, y, 250, 14, Font.TimesRoman, 14, TextAlign.Left);
        page.Elements.Add(Label);
        page.Elements.Add(Data);
    }
4

1 回答 1

0

我在代码的 if (Y > 580) 部分中缺少 table.columns.add 。

于 2014-07-07T20:57:42.097 回答