2011-03-29 40 views
1

我已經使用Abc PDF從HTML頁面創建PDF現在我的問題是我想要在下一頁上打印表格標題,但只有當表格數據顯示在另一個頁面中時if不在不同的頁面上顯示標題,任何人都知道我們如何使用Abc pdf來做到這一點。使用Abc PDF在設置頁面上打印標題

回答

2

你需要做的是創建頁面頂部有一些空格,然後一旦你的文檔建立在abc PDF循環中,通過頁面添加一個頁眉。

下面的代碼是什麼,我用它來添加頁眉,在這種情況下,頭的頂部有三個位的圖像和兩個箱與文本。

記得在ABC PDF的線是從底部右邊不是左上角。

private static Doc AddHeader(Doc theDoc, Core.Property propertyDetails) 
{ 
    int theCount = theDoc.PageCount; 
    int i = 0; 

    //Image header 
    for (i = 1; i <= theCount; i++) 
    { 
     theDoc.Rect.Width = 590; 
     theDoc.Rect.Height = 140; 

     theDoc.Rect.Position(0, 712); 

     theDoc.PageNumber = i; 

     //Check Which office to use. 
     string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png"); 


     Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath); 

     theDoc.AddImage(myBmp); 
    } 

    //page header boxes. 
    //Grey header box 
    theDoc.Rect.String = "20 15 590 50"; 
    theDoc.Rect.Position(13, 672); 
    System.Drawing.Color colour = System.Drawing.ColorTranslator.FromHtml("#CCCCCC"); 
    theDoc.Color.Color = colour; 
    theDoc.PageNumber = 1; 
    theDoc.FillRect(); 

    theDoc.Rect.String = "20 15 586 50"; 
    theDoc.Rect.Position(30, 660); 
    System.Drawing.Color pageoneText = System.Drawing.ColorTranslator.FromHtml("#50474A"); 
    theDoc.Color.Color = pageoneText; 
    string thePageFont = "Century Gothic"; 
    theDoc.Font = theDoc.AddFont(thePageFont); 
    theDoc.FontSize = 16; 
    theDoc.PageNumber = 1; 
    theDoc.AddText("My Text!!!!!"); 


    theDoc.Rect.String = "20 15 590 50"; 
    theDoc.Rect.Position(13, 630); 
    System.Drawing.Color greyBox = System.Drawing.ColorTranslator.FromHtml("#468DCB"); 
    theDoc.Color.Color = greyBox; 
    theDoc.PageNumber = 1; 
    theDoc.FillRect(); 

    theDoc.Rect.String = "20 15 586 50"; 
    theDoc.Rect.Position(30, 620); 
    System.Drawing.Color greyText = System.Drawing.ColorTranslator.FromHtml("#ffffff"); 
    theDoc.Color.Color = greyText; 
    string thePageFontTwo = "Century Gothic"; 
    theDoc.Font = theDoc.AddFont(thePageFontTwo); 
    theDoc.FontSize = 14; 
    theDoc.PageNumber = 1; 
    theDoc.AddText("This is more text"); 

    return theDoc; 
} 

然後一旦創建PDF文件只需要調用

var theDoc = new Doc(); 

/// Your document creation stuff!!! 
theDoc = AddHeader(theDoc, propertyDetails);