在PDF文档中添加pdf表

时间:2016-04-26 10:22:00

标签: c# asp.net

我正在生成一个带有表格的简单pdf文件。当我在文档中添加一些短语时它工作正常但我也在这个文档中添加一个表但是表格没有添加到文档中。任何人都可以告诉我我在这做什么错?提前致谢。 这是我生成pdf的代码。除了pdf表

之外,其他一切都很好
public Document GetPDFparams(Document disclaimer)
    {
        StringBuilder Content = new StringBuilder();
        Content.Append("Testing");
        Paragraph NullContent = new Paragraph(Content.ToString(), FontFactory.GetFont(FontFactory.TIMES_ROMAN, font_size, Font.NORMAL));
        disclaimer.Add(NullContent);
        PdfPTable tableh = new PdfPTable(6);
        tableh.WidthPercentage = 100;
        tableh.SetTotalWidth(new float[] { 300f, 300f, 300f, 300f,300f,300f });
        tableh.HorizontalAlignment = Element.ALIGN_CENTER;

        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Images/ORIXLOGO.png"));
        //img.ScaleToFit(100, 40);
        PdfPCell LogoCell = new PdfPCell(img);
        LogoCell.HorizontalAlignment = Element.ALIGN_RIGHT;
        LogoCell.VerticalAlignment = Element.ALIGN_BOTTOM;
        LogoCell.Colspan = 2;
        LogoCell.Padding = 20;
        LogoCell.Border = 0;
        LogoCell.Indent = 0;        

        tableh.AddCell(LogoCell);


        Phrase LogoText = new Phrase("abc", FontFactory.GetFont(FontFactory.TIMES_BOLD, font_size));
        PdfPCell LogoTextCell = new PdfPCell(LogoText);
        LogoTextCell.HorizontalAlignment = Element.ALIGN_LEFT;
        LogoTextCell.VerticalAlignment = Element.ALIGN_LEFT;
        LogoTextCell.Border = Rectangle.NO_BORDER;
        LogoTextCell.PaddingTop = 15;
        LogoTextCell.PaddingBottom = 5;
        LogoTextCell.PaddingLeft = 5;
        LogoTextCell.PaddingRight = 5;
        tableh.AddCell(LogoTextCell);

        disclaimer.Add(tableh);
        return disclaimer;
    }

1 个答案:

答案 0 :(得分:0)

最后我得到了解决方案。问题是桌子每行有6列,我只在添加3列后进行测试,所以在为行表添加所有6列后添加:)。 这是我的代码:

@Component({
    selector: 'child-comp',
    template: `
    <h1>{{title}}</h1>
    <button (click)="notifyParent()">notify</button>
    `,
})
export class ChildComponent {
  @Output() notify = new EventEmitter();
  @Input() title;

  notifyParent() {
    this.notify.emit('Some notification');
  }
}


@Component({
    selector: 'my-app',
    directives: [ChildComponent]
    template: `
    <h1>Hello</h1>
    <child-comp [title]="childTitle" (notify)="onNotification($event)"></child-comp>
    <div>note from child: {{notification}}</div>
    `,
})
export class AppComponent {
  childTitle = "I'm the child";

  onNotification(event) {
    this.notification = event;
  }
}