Print a header on set page using Abc PDF
I have created pdf from HTML page using Abc PDF now my problem is I want to print a table header on next page, but only if table data is display开发者_JAVA技巧 within a another page, if not display header on a different page, any one have idea about how we can do this using Abc pdf.
What you need to do is create the page with some space at the top, then once your document is built in abc PDF loop though the pages and add a header.
The code below is what I use to add a header, the header in this case has three bits a image at the top and two boxes with text in.
Remember the cord in abc pdf are from the bottom right not the top left.
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;
}
Then once the pdf file is created just call
var theDoc = new Doc();
/// Your document creation stuff!!!
theDoc = AddHeader(theDoc, propertyDetails);
精彩评论