2012-12-18 4 views
2

PDF 형식의 보고서를 만들 때 sharply를 사용하고 있습니다.
페이지 테두리가 필요합니다. 나는 몇 가지 방법을 시도했다. 나는 성공하지 못했다.
iText for .NET을 사용하여 위쪽, 아래쪽, 왼쪽, 오른쪽으로 페이지 테두리를 가져올 수 있습니까?
하나의 이미지 1을 추가했습니다. 나는 이미지에서 묘사 된 것과 같은 경계를 원한다.itextsharp pdf 페이지 테두리?

+1

불행히도 내가 추가 한 이미지를 찾을 수 없습니다. 다시 추가 할 수 있습니까? – mkl

답변

4

머리글 이미지를 수동으로 추가 할 때이 코드를 사용해보십시오.

// 1 단계 :

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 단계 :

이미지 파일

strImgPath is refer the directory Info.. 

Image imgLogo = Image.GetInstance(strImgPath.ToString()+"\\abcdur compe.Jpg"); 
imgLogo.Alignment = Image.ALIGN_CENTER; 
imgLogo.ScalePercent(50f); 

// 2 단계 추가

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

감사합니다. 그 일. 전체 PDF 국경에 대해 말해 줄 수 있습니까? – Prasad

+1

희망이 도움이 될 수 있습니다 ... http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns – SUBRA

+0

아니요 작동하지 않습니다 – Prasad

0

문서 여백을 언급하고 있습니까? 내가 해결 방법 중 하나 해키 방법을 사용하고

public Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom); 
1

하지만 border.Use이 방법을 만들 것입니다 : 예, 문서 객체의의 ctor를 사용하는 경우를 지정합니다.

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); 
    } 

헤더를 만들려면 섹션을 두 개 더 만들어야합니다.이 정보가 도움이되기를 바랍니다.

관련 문제