You are on page 1of 4

import java.awt.

Color;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.net.URL;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import io.cloudio.pdfutil.magicbox.MagicBox;
import io.cloudio.pdfutil.magicbox.widgets.PDFPage;
import io.cloudio.pdfutil.magicbox.widgets.images.Image;
import io.cloudio.pdfutil.magicbox.widgets.layouts.Div;
import io.cloudio.pdfutil.magicbox.widgets.layouts.FormPanel;
import io.cloudio.pdfutil.magicbox.widgets.page.PageBreak;
import io.cloudio.pdfutil.magicbox.widgets.tables.DataTable;
import io.cloudio.pdfutil.magicbox.widgets.tables.Panel;
import io.cloudio.pdfutil.magicbox.widgets.tables.Table.FontAlignment;
import io.cloudio.pdfutil.magicbox.widgets.tables.components.CellConfig;
import io.cloudio.pdfutil.magicbox.widgets.tables.components.RowData;
import io.cloudio.pdfutil.magicbox.widgets.text.TextBox;
import io.cloudio.pdfutil.magicbox.widgets.text.PageCounter;
import io.cloudio.pdfutil.magicbox.widgets.layouts.Footer;
import io.cloudio.pdfutil.magicbox.widgets.layouts.Header;
import com.rapapp.platform.server.AttachmentModel;
import com.rapapp.platform.server.Util;
import com.rapapp.platform.server.util.EmailUtil;

org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(EmailUtil.class);
import java.io.*;

static Color primaryColor = Color.decode("#057dcd");


static Color secondaryColor = Color.decode("#057dcd");
static Color textPrimaryColor = Color.decode("#464646");
static PDType1Font primaryFont = PDType1Font.HELVETICA;
static Color blackColor=Color.decode("#000000");
static Color whiteColor=Color.decode("#FFFFFF");
public static void main(String[] args) throws Exception {

MagicBox magicBox = MagicBox.getInstance();


PDFPage page = magicBox.createPage();
//page.setWidth(200);
//Header
logger.debug("Line no. " + 43);
//Div v=new Div();
//v.setBackgroundColor(blackColor);
//v.setBackgroundColor(blackColor);
//v.setBackgroundColor(blackColor);
Header header = new Header();
header.setRepeatOnEveryPage(true);
//header.setBackgroundColor(Color.decode("#FFFFFF"));
URL url = new URL("https://adfs.xoriant.com/adfs/portal/logo/logo.png");
logger.debug("URL is " + url);
Image imageOne = new Image(url);
imageOne.setMarginLeft(420);
imageOne.setMarginTop(50);
imageOne.setWidth(160);
imageOne.setHeight(40);
logger.debug("Line no. " + 57);
URL url = new
URL("http://ww1.prweb.com/prfiles/2016/04/22/14097790/gI_61020_cloudio-logo-
big.png");
Image imageTwo = new Image(url);
imageTwo.setMarginLeft(20);
imageTwo.setMarginTop(100);
imageTwo.setWidth(160);
imageTwo.setHeight(40);
logger.debug("Line no. " + 65);

//header.setRepeatOnEveryPage(true);
//header.setBorderBottom(0);
//header.setBorderWidth(2f);

// TextBox headerText = new TextBox("Sample PDF");


// headerText.setFontSize(15);
// headerText.setBorders(true);
header.appendChild(imageOne);
//header.appendChild(imageTwo);
// header.appendChild(headerText);
//header.setRepeatOnEveryPage(true);
// v.addWidget(header);
// v.appendChild(header);
page.addWidget(header);
//page.addWidget(v);
//Footer
/*Footer footer = new Footer();
footer.borders(true);

// Page Counter
PageCounter pc = new PageCounter();
pc.setMarginLeft(250);
pc.setMarginTop(-5);
pc.setExpression("Page " + PageCounter.CURRENT_PAGE_INDEX + " of " +
PageCounter.TOTAL_PAGES);
footer.appendChild(pc);
page.addWidget(footer);*/

//throw new RAException("data"+fileName);


for (int i=0; i< 500; i++){
logger.debug("Line no. " + 97);
Div div = new Div();
div.setWidth(page.getOffsetWidth());
div.setMarginTop(170);
Div div1 = new Div();
div1.setWidthPercentage(50);
div.appendChild(div1);
TextBox deliveryText = new TextBox("DELEVERY");
deliveryText.setFontColor(secondaryColor);
deliveryText.setFontSize(10);
deliveryText.setFontType(primaryFont);
//deliveryText.setRepeatOnEveryPage(true);
// div1.appendChild(deliveryText);
// Div separator = getSeparator(100, 200);
// div1.appendChild(separator);
logger.debug("Line no. " + 112);
Div div2 = new Div();
div2.setWidthPercentage(150);
div2.setMarginLeft(div.getWidth() / 2);
//div2.setBackgroundColor(blackColor);
//div2.setRepeatOnEveryPage(true);
div2.setMarginTop(200);
div.appendChild(div2);
TextBox encoreText = new TextBox("Hemangi Bhadke");
encoreText.setFontColor(secondaryColor);
encoreText.setFontSize(20);
encoreText.setMarginLeft(30);
encoreText.setFontType(primaryFont);

TextBox subText = new TextBox("has completed the interview training module");


subText.setFontColor(secondaryColor);
subText.setFontSize(10);
subText.setMarginLeft(30);
subText.setFontType(primaryFont);
subText.setMarginTop(50);
TextBox certName = new TextBox("Cyber Security:Self Defence in the Digital
Age");
certName.setFontColor(secondaryColor);
certName.setFontSize(20);
certName.setMarginLeft(30);
certName.setFontType(primaryFont);
certName.setMarginTop(60);
div2.appendChild(encoreText);
div2.appendChild(subText);
div2.appendChild(certName);
// div2.appendChild(separator);
page.addWidget(div);
logger.debug("Line no. " + 143);
}

logger.debug("Line no. " + 146);


Long fileId=34416L;
//AttachmentModel attchmentModel = db.getAttachment(fileId, true);
//InputStream imgStream = attchmentModel.getAttachement();
/*
Image image = new Image(imgStream);
image.setHeight(80);
image.setWidth(80);
image.setMarginLeft(350);
image.setMarginTop(300);
page.addWidget(image);
PageBreak pgBreak = new PageBreak();
page.addWidget(pgBreak);*/

logger.debug("Line no. " + 160);


response.setContentType("application/pdf");
magicBox.save(response.getOutputStream());
logger.debug("Line no. " + 163);
}

private static Div getSeparator(float length1, float length2) {


Div div = new Div();
div.setMarginTop(30);
Div div1 = new Div();
div1.setWidth(length1);
div1.setHeight(2);
div1.setBackgroundColor(secondaryColor);
div.appendChild(div1);
Div div2 = new Div();
div2.setWidth(length2);
div2.setHeight(1);
div2.setMarginTop(1);
div2.setBackgroundColor(secondaryColor);
div.appendChild(div2);
return div;
}
main(null);

You might also like