2017-09-16 3 views
1

J'essaie de créer une feuille OMR. Pour cela besoin d'un design comme ci-dessous. J'ai fait en html & css.Comment créer un cercle avec le texte central dans ItextSharp

enter image description here

mais iTextSharp il ne fonctionne pas comme HTML dans le navigateur.

<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> 

frontière & border-radius ne fonctionnent pas

Comment puis-je résoudre que toute idée. Merci

+0

Vous ne montrez pas votre code, il est donc impossible de voir quelle version d'iText vous utilisez. Vous devriez utiliser iText 7 + l'add-on pdfHTML si vous voulez que cela fonctionne. Si vous prétendez que border et border-radius ne fonctionnent pas, vous utilisez probablement une ancienne version. –

+0

@BrunoLowagie oui J'utilise iText 5. –

Répondre

2

j'ai essayé ce code:

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

Le fichier circle.pdf ressemble à ceci (notez que je l'ai enlevé white comme couleur de la bordure, ou la frontière aurait été invisible):

<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> 

Le résultat ressemble à ceci:

enter image description here

Je dirais que cela ressemble plus ou moins OK, mais:

  • Si vous ne recevez pas ce résultat, vous utilisez une ancienne version de iText, mise à jour! (parce que nous n'avons pas supporté cette fonctionnalité dans les anciennes versions d'iText, et nous n'avons pas l'intention de mettre à jour ces anciennes versions),
  • Si, une fois que vous avez mis à jour iText 7 + pdfHTML, vous n'êtes pas satisfait De la façon dont les «cercles» sont dessinés, veuillez admettre que votre solution de contournement pour créer des cercles est plutôt médiocre. Il y a d'autres façons de le faire. Soit vous pouvez créer votre propre implémentation du ITagWorker pour dessiner de vrais cercles autour du contenu au lieu de travailler avec des coins arrondis, soit, si vous avez un nombre limité de caractères nécessitant des cercles, utilisez une police dont les glyphes sont déjà fournis avec des cercles.