這是一個使用itextsharp庫的vb.net應用程序。我正在運行的是下面的代碼變得非常多餘,在我看來,這不是一個乾淨的方式去做事情。但我似乎無法弄清楚如何將它分離到一個單獨的函數中,在這個函數中,我只需傳入字符串x_Cord,y_Cord,並將其傾斜並將其傳遞給它)a)傳入時將其作爲數組傳入;或者b)爲需要它的每一行執行它......然後該函數將返回contentBytes的必要信息......下面的內容非常類似於結束時冗餘冗餘。從pdf生成器函數中分離冗餘代碼
Dim cb As PdfContentByte = writer.DirectContent
我在上面簡單地介紹了爲了清楚起見而聲明瞭cb。
cb.BeginText()
cb.SetFontAndSize(Californian, 36)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "CERTIFICATE OF COMPLETION", 396, 397.91, 0)
cb.SetFontAndSize(Bold_Times, 22)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, name, 396, 322.35, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _hours + " Hours", 297.05, 285.44, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _dates, 494.95, 285.44, 0)
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _class1, 396, 250.34, 0)
If Not String.IsNullOrWhiteSpace(_class2) Then
cb.SetFontAndSize(Bold_Times, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _class2, 396, 235.34, 0)
End If
cb.SetFontAndSize(Copper, 16)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _conf_num + _prefix + " Annual Conference " + _dates, 396, 193.89, 0)
cb.SetFontAndSize(Bold_Times, 13)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Some Name", 396, 175.69, 0)
cb.SetFontAndSize(Bold_Times, 10)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "Some Company Manager", 396, 162.64, 0)
cb.EndText()
任何想法使它成爲它自己的功能?