gpt4 book ai didi

c# - ABCPDF 标题大小和位置的计算。

转载 作者:太空宇宙 更新时间:2023-11-03 11:14:17 24 4
gpt4 key购买 nike

问题是一个头文件,我必须在 abcpdf 生成的 pdf 文件的每一页上包含它。

头文件包含不止一个图像文件和几行文本,具体情况视情况而定。

问题是我不知道如何计算标题的大小。我需要有它的大小来分配矩形位置,以将每个页面上的其余 html 文件与标题一起放置。我正在使用 C#。

最佳答案

首先,您需要创建顶部有足够空间的文档,以便添加标题。以下设置适用于页眉约占页面 1/5 的普通 A4 文档。请记住 PDF 上的坐标是从右下角开始的,而不是从左上角开始的。

//Setting to create the document using ABCPdf 8
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";

theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.ImageQuality = 101;
theDoc.Rect.Width = 719;
theDoc.Rect.Height = 590;
theDoc.Rect.Position(2, 70);
theDoc.HtmlOptions.Engine = EngineType.Gecko;

下面的代码在文档的每一页上放置了一个标题,带有标题图像,然后是图像下方的彩色框,其中包含一些自定义文本。

本例中的标题图像为 1710 x 381,以保持图像的分辨率尽可能高,以免打印时看起来模糊。

private static Doc AddHeader(Doc theDoc)
{
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, 706);

theDoc.PageNumber = i;
string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png");

Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath);
theDoc.AddImage(myBmp);
}

//Blue header box
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 672);
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#468DCB");
theDoc.Color.Color = c;
theDoc.PageNumber = i;
theDoc.FillRect();
}

//Blue header text
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 586 50";
theDoc.Rect.Position(25, 660);
System.Drawing.Color cText = System.Drawing.ColorTranslator.FromHtml("#ffffff");
theDoc.Color.Color = cText;
string theFont = "Century Gothic";
theDoc.Font = theDoc.AddFont(theFont);
theDoc.FontSize = 14;
theDoc.PageNumber = i;
theDoc.AddText("Your Text Here");
}
return theDoc;
}

关于c# - ABCPDF 标题大小和位置的计算。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13149160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com