2013-02-22 51 views
0

我需要創建PDF文件,在頁面上使用左右邊緣的頂點繪製線條。但是,在這裏,由於這樣的混淆,這些邊際的計算是在像素值。那麼,怎麼可能畫出像素值邊距設置?使用C#中的itextsharp創建PDF文件

樣品如下代碼:

 PdfContentByte contentByte = writer.DirectContent; 
     contentByte.SetLineWidth(1); 
     float x1, y1, x2, y2; 
     x1 = myDocument.PageSize.Width - 84; 
     x2 = myDocument.PageSize.Width - 36; 
     y1 = myDocument.PageSize.Height - 56; 
     y2 = myDocument.PageSize.Height - 56; 
     contentByte.MoveTo(x1, y1); 
     contentByte.LineTo(x2, y2); 
     contentByte.Stroke(); 

事實上,我要繪製寬度的線48是具有右邊緣是36px,和上邊距是36px。

有什麼想法來計算它嗎?

回答

0

試試這個方法:

string pdfpath = Server.MapPath("PDFs"); 
    Document doc = new Document(); 
    try 
    { 
    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfpath + "/Graphics.pdf", FileMode.Create)); 
    doc.Open(); 
    PdfContentByte cb = writer.DirectContent; 
    ... 

現在我們有一個工作PdfContentByte對象,我們可以用它來啓動繪圖:

cb.MoveTo(doc.PageSize.Width/2, doc.PageSize.Height/2); 
cb.LineTo(doc.PageSize.Width/2, doc.PageSize.Height); 
cb.Stroke(); 
cb.MoveTo(0, doc.PageSize.Height/2); 
cb.LineTo(doc.PageSize.Width, doc.PageSize.Height/2); 
cb.Stroke(); 

here

接過
相關問題