2017-09-16 60 views
1

創建文本中心的圓,我嘗試創建一個OMR片。對於這個需要像下面這樣的設計。我在HTML & css。如何iTextSharp的

enter image description here

但iTextSharp的不作爲瀏覽器的HTML工作。

<td style="border-width:0 2px 0 4px; border-style:solid; border-color:white; padding:0 20px;"> 
    <div style="height:17px; width:25px; padding:2px; float:left;">1</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">A</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">B</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">C</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">D</div> 
</td> 

邊境&邊界半徑不工作

我該如何解決,任何想法。 感謝

+0

你不顯示任何代碼的,因此這是不可能看到你正在使用的iText的版本。如果你想要這個工具,你應該使用iText 7 + pdfHTML插件。如果您聲稱邊界和邊界半徑不起作用,那麼您可能使用的是舊版本。 –

+0

@BrunoLowagie是的,我正在使用iText 5。 –

回答

2

我試過這段代碼:

public static final String SRC = "circle.html"; 
public static final String DEST = "circle.pdf"; 

public static void main(String[] args) throws IOException { 
    LicenseKey.loadLicenseFile(System.getenv("ITEXT7_LICENSEKEY") + "/itextkey-html2pdf_typography.xml");   
    Alignment app = new Alignment(); 
    app.createPdf(SRC, DEST); 
} 

public void createPdf(String src, String dest) throws IOException { 
    HtmlConverter.convertToPdf(new File(src), new File(dest)); 
} 

文件circle.pdf看起來像這樣(請注意,我刪除white作爲邊框顏色,或邊界本來不可見的):

<table> 
<tr> 
<td style="border-width:0 2px 0 4px; border-style:solid; padding:0 20px;" colspan="3"> 
    <div style="height:17px; width:25px; padding:2px; float:left;">1</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">A</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">B</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">C</div> 
    <div style="height:17px; width:18px; padding:2px; margin:5px 2px; float:left; text-align:center; border-radius:50px; border:1px solid black;">D</div> 
</td> 
</tr> 
</table> 

結果如下所示:

enter image description here

我會說這看起來或多或少OK,但:

  • 如果你沒有得到這樣的結果,您使用的是舊版本的iText的,升級!(因爲我們不支持在舊版本的iText的這種功能,而且我們沒有更新這些舊版本的意圖),
  • 如果,一旦你已經升級到利用iText 7 + pdfHTML,你是不是高興「圈子」的繪製方式,請承認您創建圈子的解決方法相當差。還有其他方法可以做到這一點。要麼你可以創建自己的實施ITagWorker來繪製的,而不是帶圓角的工作圍繞着內容真實圈,或者,如果你有一組有限的,需要各界的字符,使用字體它的字形已經配備了圈。