我正在使用itext sharp來創建PDF格式的報告。
我想要頁面邊框。我嘗試了一些方法。我不成功。
如何使用iText for .NET
獲得頂部,底部,左側,右側的頁面邊框?
我添加了一個圖像1。我想要像圖片中描述的邊框。itextsharp pdf頁面邊框?
2
A
回答
4
您可以嘗試使用此代碼手動爲標題添加圖像。
//步驟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;
0
您是指文件邊距?如果是的話,使用文檔對象的構造函數指定它們:
public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom);
1
我使用的變通辦法的一個哈克的方式,但它會創建border.Use此方法。
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);
}
如果你想再多一節的頭創建表寬兩行。我希望這有助於。
相關問題
- 1. Itextsharp將邊框添加到所有pdf頁面
- 2. itextsharp html to pdf創建無邊框
- 3. C#iTextsharp替換多頁PDF的頁面
- 4. iTextSharp的多頁PDF
- 5. 使用iTextSharp獲取PDF頁面大小
- 6. iTextSharp PDF頁面導入內存問題
- 7. itextsharp修剪pdf文檔的頁面
- 8. iTextSharp的 - 如何定位PDF頁面數
- 9. ITextSharp - 在第一頁以外的頁面上書寫PDF頁面
- 10. 如何使用iTextSharp爲頁面添加邊框?
- 11. 如何使用iTextsharp更改PDF中第二頁的頁邊距?
- 12. 頁腳在PDF與iTextSharp
- 13. 如何突破PDF頁面中iTextSharp的PDF
- 14. PDF iTextSharp的,寫PDF行不同的頁面
- 15. 拆分10k頁面時發生內存泄漏PDF(iTextSharp PDF API)
- 16. iTextsharp自定義邊框
- 17. iTextSharp不生成PDF中的表格邊框
- 18. 如何在pdf中使用itextsharp設置邊框顏色
- 19. itextsharp html to pdf - 表格邊框不工作
- 20. iTextSharp忽略新創建的PDF中的頁邊距
- 21. 使用jspdf導出的pdf頁面邊框
- 22. 如何將邊框應用於PDF頁面?
- 23. 縮放pdf以添加邊框以打印全尺寸頁面
- 24. 圖片頁面邊框
- 25. 在asp.net頁面查看pdf頁面
- 26. iTextSharp .pdf工具
- 27. Itextsharp下載PDF
- 28. Itextsharp pdf colore code
- 29. iTextSharp的和pdf
- 30. itextsharp postscript to PDF
不幸的是我找不到您添加的圖像。你可以再添加一次嗎? – mkl