J'ai réalisé une implémentation rapide de la plupart de vos cas d'utilisation.
Voici le code:
Nous définissons d'abord une petite classe qui agit comme un seul enregistrement dans la facture. Puis, j'ai créé une méthode pour chacun des gros blocs de la facture.
En commençant par le titre:
public static void addTitle(Document layoutDocument)
{
layoutDocument.add(new Paragraph("RETAIL INVOICE").setBold().setUnderline().setTextAlignment(TextAlignment.CENTER));
}
Puis ajouter le petit paragraphe de texte qui est sous le titre:
public static void addCustomerReference(Document layoutDocument)
{
layoutDocument.add(new Paragraph("M/s Indian Convent School").setTextAlignment(TextAlignment.LEFT).setMultipliedLeading(0.2f));
layoutDocument.add(new Paragraph("y Pocket-3, Sector-24, Rohini Delhi-110085").setMultipliedLeading(.2f));
layoutDocument.add(new Paragraph("b 011-64660271").setMultipliedLeading(.2f));
}
Et puis en ajoutant une table:
public void addTable(Document layoutDocument, List<Article> articleList)
{
Table table = new Table(UnitValue.createPointArray(new float[]{60f, 180f, 50f, 80f, 110f}));
// headers
table.addCell(new Paragraph("S.N.O.").setBold());
table.addCell(new Paragraph("PARTICULARS").setBold());
table.addCell(new Paragraph("QTY").setBold());
table.addCell(new Paragraph("RATE").setBold());
table.addCell(new Paragraph("AMOUNT IN RS.").setBold());
// items
for(Article a : articleList)
{
table.addCell(new Paragraph(a.SNO+""));
table.addCell(new Paragraph(a.description));
table.addCell(new Paragraph(a.quantity+""));
table.addCell(new Paragraph(a.unitPrice+""));
table.addCell(new Paragraph((a.quantity * a.unitPrice)+""));
}
layoutDocument.add(table);
}
La principale méthode alors ressemble à ceci:
public static void main(String[] args) throws FileNotFoundException {
PdfDocument pdfDocument = new PdfDocument(new PdfWriter("MyFirstInvoice.pdf"));
Document layoutDocument = new Document(pdfDocument);
// title
addTitle(layoutDocument);
// customer reference information
addCustomerReference(layoutDocument);
addTable(layoutDocument, Arrays.asList(
new Article(1, "Envelopes",2000, 1.70),
new Article(2, "Voucher Book", 50, 41)));
// articles
layoutDocument.close();
}
Cette question est trop large pour débordement de la pile. Commencez par lire [la documentation] (https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml/chapter-4-creating-reports-using-pdfhtml) (si vous faites défiler vers le bas, vous verrez un exemple de facture). Commencez à coder et retournez à Stack Overflow lorsque vous avez un * problème technique spécifique *. Stack Overflow n'est pas une plate-forme «fais mon travail pour moi», ni une plateforme d'apprentissage. –
Et bien sûr, il y a un livre complet dédié à la production de factures avec iText: https://developers.itextpdf.com/content/zugferd-future-invoicing –
@BrunoLowagie merci pour les commentaires :) je cherche juste une référence de départ .. –