Search in sources :

Example 1 with CardsDeckSorter

use of org.magic.api.sorters.CardsDeckSorter in project MtgDesktopCompanion by nicho92.

the class PDFExport method exportDeck.

@Override
public void exportDeck(MagicDeck deck, File f) throws IOException {
    var table = new Table(3).useAllAvailableWidth();
    try (var pdfDocDest = new PdfDocument(new PdfWriter(f));
        Document doc = new Document(pdfDocDest)) {
        pdfDocDest.setDefaultPageSize(PageSize.A4);
        PdfDocumentInfo info = pdfDocDest.getDocumentInfo();
        info.setTitle(deck.getName());
        info.setAuthor(getString("AUTHOR"));
        info.setCreator(MTGConstants.MTG_APP_NAME);
        info.setKeywords(deck.getTags().stream().collect(Collectors.joining(",")));
        info.addCreationDate();
        var mainList = deck.getMainAsList();
        Collections.sort(mainList, new CardsDeckSorter(deck));
        for (MagicCard card : mainList) {
            table.addCell(createCell(card));
            notify(card);
        }
        doc.add(table);
    } catch (Exception e) {
        logger.error("Error in pdf creation " + f, e);
    }
}
Also used : Table(com.itextpdf.layout.element.Table) CardsDeckSorter(org.magic.api.sorters.CardsDeckSorter) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfDocumentInfo(com.itextpdf.kernel.pdf.PdfDocumentInfo) MagicCard(org.magic.api.beans.MagicCard) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfDocumentInfo (com.itextpdf.kernel.pdf.PdfDocumentInfo)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 Document (com.itextpdf.layout.Document)1 Table (com.itextpdf.layout.element.Table)1 IOException (java.io.IOException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 MagicCard (org.magic.api.beans.MagicCard)1 CardsDeckSorter (org.magic.api.sorters.CardsDeckSorter)1