Search in sources :

Example 66 with Document

use of com.itextpdf.layout.Document in project MtgDesktopCompanion by nicho92.

the class DCIDeckSheetExport method exportDeck.

@Override
public void exportDeck(MagicDeck deck, File dest) throws IOException {
    try (var pdfSrc = new PdfDocument(new PdfReader(this.getClass().getResource("/data/mtg_constructed_deck_registration_sheet.pdf").openStream()));
        var docSrc = new Document(pdfSrc);
        var pdfDest = new PdfDocument(new PdfWriter(dest));
        var docDest = new Document(pdfDest)) {
        pdfDest.setDefaultPageSize(PageSize.A4);
        pdfSrc.copyPagesTo(1, 1, pdfDest);
        float h = pdfDest.getDefaultPageSize().getHeight();
        float w = pdfDest.getDefaultPageSize().getWidth();
        // HEADER
        docDest.add(createParagraphe(getString(LAST_NAME).substring(0, 1).toUpperCase(), w - 35, h - 103));
        if (!getString(FORCED_DATE).equalsIgnoreCase(""))
            docDest.add(createParagraphe(getString(FORCED_DATE), w / 3.2f, h - 127));
        else
            docDest.add(createParagraphe(new SimpleDateFormat(getString(DATE_FORMAT)).format(new Date()), w / 3.2f, h - 127));
        docDest.add(createParagraphe(getString(LOCATION), w / 3.2f, h - 150));
        docDest.add(createParagraphe(getString(EVENT_NAME), w / 1.40f, h - 127));
        docDest.add(createParagraphe(deck.getName(), w / 1.40f, h - 150));
        if (getString(DECK_DESIGNER).equals(""))
            docDest.add(createParagraphe(getString(LAST_NAME) + " " + getString(FIRST_NAME), w / 1.40f, h - 175));
        else
            docDest.add(createParagraphe(getString(DECK_DESIGNER), w / 1.40f, h - 175));
        // MAIN DECK
        var count = 0;
        for (Entry<MagicCard, Integer> e : deck.getMain().entrySet().stream().filter(e -> !e.getKey().isBasicLand()).toList()) {
            docDest.add(createParagraphe(e.getValue() + space + e.getKey().getName(), w / 6.4f, h - 240 - count));
            count += 18;
            notify(e.getKey());
        }
        count = 0;
        for (Entry<MagicCard, Integer> e : deck.getMain().entrySet().stream().filter(e -> e.getKey().isBasicLand()).toList()) {
            docDest.add(createParagraphe(e.getValue() + space + e.getKey().getName(), w / 1.65f, h - 240 - count));
            count += 18;
            notify(e.getKey());
        }
        // SIDEBOARD
        count = 0;
        for (MagicCard mc : deck.getSideBoard().keySet()) {
            docDest.add(createParagraphe(deck.getSideBoard().get(mc) + space + mc.getName(), w / 1.65f, h - 474 - count));
            notify(mc);
            count += 18;
        }
        // BOTTOM card count
        docDest.add(createParagraphe(String.valueOf(deck.getMainAsList().size()), (w / 2) - 25, 40));
        docDest.add(createParagraphe(String.valueOf(deck.getSideAsList().size()), w - 55, 95));
        // LEFT TEXT
        var p = createParagraphe(getString(LAST_NAME), 60, 90);
        p.setRotationAngle(1.5708f);
        docDest.add(p);
        p = createParagraphe(getString(FIRST_NAME), 60, 300);
        p.setRotationAngle(1.5708f);
        docDest.add(p);
        var dci = getString(DCI_NUMBER);
        count = 0;
        for (var i = 0; i < dci.length(); i++) {
            var c = dci.charAt(i);
            p = createParagraphe(String.valueOf(c), 60, (430 + count));
            p.setRotationAngle(1.5708f);
            docDest.add(p);
            count += 22;
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Icon(javax.swing.Icon) MagicCardStock(org.magic.api.beans.MagicCardStock) StandardFonts(com.itextpdf.io.font.constants.StandardFonts) File(java.io.File) Paragraph(com.itextpdf.layout.element.Paragraph) List(java.util.List) AbstractCardExport(org.magic.api.interfaces.abstracts.AbstractCardExport) PdfReader(com.itextpdf.kernel.pdf.PdfReader) Map(java.util.Map) Entry(java.util.Map.Entry) ImageIcon(javax.swing.ImageIcon) MagicCard(org.magic.api.beans.MagicCard) PageSize(com.itextpdf.kernel.geom.PageSize) TextAlignment(com.itextpdf.layout.properties.TextAlignment) Document(com.itextpdf.layout.Document) POMReader(org.magic.tools.POMReader) PdfFontFactory(com.itextpdf.kernel.font.PdfFontFactory) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfReader(com.itextpdf.kernel.pdf.PdfReader) IOException(java.io.IOException) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Date(java.util.Date) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) MagicCard(org.magic.api.beans.MagicCard) SimpleDateFormat(java.text.SimpleDateFormat)

Example 67 with Document

use of com.itextpdf.layout.Document 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)

Example 68 with Document

use of com.itextpdf.layout.Document in project java-example by saxingz.

the class A0025PdfApplication method main.

public static void main(String[] args) throws IOException {
    byte[] user = "".getBytes();
    byte[] owner = "xyz".getBytes();
    // PdfDocument pdfDoc =
    // new PdfDocument(new PdfReader("D:\\D_desktop\\book\\big2.pdf"),
    // new PdfWriter("D:\\D_desktop\\book\\big4.pdf",
    // new WriterProperties()
    // .setStandardEncryption(user, owner,
    // EncryptionConstants.ALLOW_PRINTING | EncryptionConstants.ALLOW_COPY,
    // EncryptionConstants.ENCRYPTION_AES_256)));
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(INPATH), new PdfWriter(OUTPATH));
    Document document = new Document(pdfDoc);
    Rectangle pageSize;
    PdfCanvas canvas;
    int totalPage = pdfDoc.getNumberOfPages();
    for (int i = 1; i <= totalPage; i++) {
        System.out.print("进度: " + i + " / " + totalPage + "\t");
        PdfPage page = pdfDoc.getPage(i);
        pageSize = page.getPageSize();
        canvas = new PdfCanvas(page);
        addText2(canvas, pageSize, totalPage, i, document, pdfDoc, page);
    }
    pdfDoc.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Rectangle(com.itextpdf.kernel.geom.Rectangle) PdfCanvas(com.itextpdf.kernel.pdf.canvas.PdfCanvas) PdfReader(com.itextpdf.kernel.pdf.PdfReader) PdfPage(com.itextpdf.kernel.pdf.PdfPage) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 69 with Document

use of com.itextpdf.layout.Document in project spring-learning by moon-zhou.

the class Demo002 method createPdf.

public void createPdf(String dest) throws IOException {
    // Initialize PDF writer
    PdfWriter writer = new PdfWriter(dest);
    // Initialize PDF document
    PdfDocument pdf = new PdfDocument(writer);
    // Initialize document
    Document document = new Document(pdf);
    // Create a PdfFont
    PdfFont font = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
    // Add a Paragraph
    document.add(new Paragraph("iText is:").setFont(font));
    // Create a List
    List list = new List().setSymbolIndent(12).setListSymbol("\u2022").setFont(font);
    // Add ListItem objects
    list.add(new ListItem("Never gonna give you up")).add(new ListItem("Never gonna let you down")).add(new ListItem("Never gonna run around and desert you")).add(new ListItem("Never gonna make you cry")).add(new ListItem("Never gonna say goodbye")).add(new ListItem("Never gonna tell a lie and hurt you"));
    // Add the list
    document.add(list);
    // Close document
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) PdfFont(com.itextpdf.kernel.font.PdfFont) List(com.itextpdf.layout.element.List) ListItem(com.itextpdf.layout.element.ListItem) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Example 70 with Document

use of com.itextpdf.layout.Document in project ISPP by josdomqui.

the class PaymentService method generateRecipt.

public String generateRecipt(Double price) {
    String fileName = "recipt.pdf";
    try {
        File file = new File(fileName);
        PdfWriter pdfWriter = new PdfWriter(file);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument);
        Paragraph paragraph = new Paragraph("Su pedido ha costado " + price + " euros.");
        document.add(paragraph);
        document.close();
        pdfWriter.close();
        System.out.println("PDF creado");
    } catch (FileNotFoundException ex) {
        System.out.println(ex.getMessage());
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }
    return fileName;
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) File(java.io.File) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Paragraph(com.itextpdf.layout.element.Paragraph)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)132 Document (com.itextpdf.layout.Document)132 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)130 Paragraph (com.itextpdf.layout.element.Paragraph)104 PdfFont (com.itextpdf.kernel.font.PdfFont)39 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)31 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 AreaBreak (com.itextpdf.layout.element.AreaBreak)25 Image (com.itextpdf.layout.element.Image)25 Table (com.itextpdf.layout.element.Table)25 Cell (com.itextpdf.layout.element.Cell)21 List (java.util.List)20 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)19 File (java.io.File)16 SolidBorder (com.itextpdf.layout.borders.SolidBorder)14 ArrayList (java.util.ArrayList)14 Tab (com.itextpdf.layout.element.Tab)13 Text (com.itextpdf.layout.element.Text)13 Rectangle (com.itextpdf.kernel.geom.Rectangle)12