使用 Abc PDF 在设置页面上打印标题

发布于 2024-10-28 13:54:29 字数 120 浏览 4 评论 0原文

我已经使用 Abc PDF 从 HTML 页面创建了 pdf,现在我的问题是我想在下一页上打印表格标题,但前提是表格数据显示在另一页中,如果不在不同页面上显示标题,任何人都有想法关于我们如何使用 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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海螺姑娘 2024-11-04 13:54:29

您需要做的是创建顶部有一些空间的页面,然后在 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文