C# itextsharp pdf页面边框?
我正在使用itext sharp创建PDF格式的报告。C# itextsharp pdf页面边框?,c#,asp.net,itext,C#,Asp.net,Itext,我正在使用itext sharp创建PDF格式的报告。 我想要页面边框。我试过一些方法。我没有成功。 如何使用.NET的iText获取顶部、底部、左侧和右侧的页面边框? 我添加了一个图像。我想要图像中描述的边框。您可以尝试使用此代码手动为标题添加图像 //步骤1:添加图像文件 strImgPath is refer the directory Info.. Image imgLogo = Image.GetInstance(strImgPath.ToString()+"\\abcdur com
我想要页面边框。我试过一些方法。我没有成功。
如何使用.NET的
iText
获取顶部、底部、左侧和右侧的页面边框?我添加了一个图像。我想要图像中描述的边框。您可以尝试使用此代码手动为标题添加图像 //步骤1:添加图像文件
strImgPath is refer the directory Info..
Image imgLogo = Image.GetInstance(strImgPath.ToString()+"\\abcdur compe.Jpg");
imgLogo.Alignment = Image.ALIGN_CENTER;
imgLogo.ScalePercent(50f);
//步骤2:
Add this ImgLogo to the PdfPTable by use of this
PdfPCell pdfcellImage = new PdfPCell(imgLogo, true);
pdfcellImage.FixedHeight = 40f;
pdfcellImage.HorizontalAlignment = Element.ALIGN_CENTER;
pdfcellImage.VerticalAlignment = Element.ALIGN_CENTER;
pdfcellImage.Border = Rectangle.NO_BORDER;
pdfcellImage.Border = Rectangle.NO_BORDER;
pdftblImage.AddCell(pdfcellImage);
//步骤3:
Create Chunck to add Text for address or others
fntBoldComHd is a Base Font Library Object
Chunk chnCompany = new Chunk("Your CompanyName\nAddress", fntBoldComHd);
//Step 4:
Create Phrase For add the Chunks and PdfPTables
Phrase phHeader = new Phrase();
phHeader.Add(pdftblImage);
phHeader.Add(chnCompany);
//步骤5:
Assign the Phrase to PDF Header
HeaderFooter header = new HeaderFooter(phHeader, false);
header.Border = Rectangle.NO_BORDER;
header.Alignment = Element.ALIGN_CENTER;
docPDF.Header = header;
你指的是文件页边距吗?如果是,请使用文档对象的ctor指定它们:
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom);
我正在使用一种破解方法,但它会创建边界。请使用此方法
private void CreateBorder(PdfContentByte cb, PdfWriter writer, Document doc)
{
iTextSharp.text.Rectangle r = doc.PageSize;
float left = r.Left + 30;
float right = r.Right - 30;
float top = r.Top - 30;
float bottom = r.Bottom + 30;
float width = right - left;
float height = top - bottom;
PdfPTable tab = new PdfPTable(1);
tab.TotalWidth = width;
tab.LockedWidth = true;
PdfPCell t = new PdfPCell(new Phrase(String.Empty));
t.BackgroundColor = new BaseColor(250, 235, 215);
t.FixedHeight = height;
t.BorderWidth = 3;
tab.AddCell(t);
Paragraph pa = new Paragraph();
pa.Add(tab);
float h = tab.TotalHeight;
PdfTemplate temp = cb.CreateTemplate(tab.TotalWidth, h);
tab.WriteSelectedRows(0, -1, 0.0F, h, temp);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(temp);
img.SetAbsolutePosition(30, 30);
cb.AddImage(img);
}
如果你想在页眉上再增加一个部分,请创建两行表格宽度。我希望这会有所帮助。谢谢。它起作用了。你能告诉我整个pdf的边界吗?希望这能帮助你。。。然后尝试手动添加矩形(如边框)。。很遗憾,我找不到您添加的图像。你能再加一次吗?