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