use of com.lowagie.text.Rectangle in project adempiere by adempiere.
the class Document method writePDF.
private static void writePDF(Pageable pageable, OutputStream output) {
try {
final PageFormat pf = pageable.getPageFormat(0);
final com.lowagie.text.Document document = new com.lowagie.text.Document(new Rectangle((int) pf.getWidth(), (int) pf.getHeight()));
final PdfWriter writer = PdfWriter.getInstance(document, output);
writer.setPdfVersion(PdfWriter.VERSION_1_2);
document.open();
final DefaultFontMapper mapper = new DefaultFontMapper();
//Elaine 2009/02/17 - load additional font from directory set in PDF_FONT_DIR of System Configurator
String pdfFontDir = MSysConfig.getValue(PDF_FONT_DIR, "");
if (pdfFontDir != null && pdfFontDir.trim().length() > 0) {
pdfFontDir = pdfFontDir.trim();
File dir = new File(pdfFontDir);
if (dir.exists() && dir.isDirectory())
mapper.insertDirectory(pdfFontDir);
}
//
final float w = (float) pf.getWidth();
final float h = (float) pf.getHeight();
final PdfContentByte cb = writer.getDirectContent();
for (int page = 0; page < pageable.getNumberOfPages(); page++) {
if (page != 0) {
document.newPage();
}
final PdfTemplate tp = cb.createTemplate(w, h);
final Graphics2D g2 = tp.createGraphics(w, h, mapper);
tp.setWidth(w);
tp.setHeight(h);
pageable.getPrintable(page).print(g2, pf, page);
g2.dispose();
cb.addTemplate(tp, 0, 0);
writer.releaseTemplate(tp);
}
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.lowagie.text.Rectangle in project adempiere by adempiere.
the class SmjPdfReport method onOpenDocument.
//simpleLine
/**
* predefine los valores del pie de pagina ** predefined values footer
*
* @param writer
* @param document
*/
public void onOpenDocument(PdfWriter writer, Document document) {
total = writer.getDirectContent().createTemplate(100, 100);
total.setBoundingBox(new Rectangle(-20, -20, 100, 100));
try {
helv = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
} catch (Exception e) {
throw new ExceptionConverter(e);
}
}
use of com.lowagie.text.Rectangle in project cytoscape-impl by cytoscape.
the class PDFWriterTest method itextLibTest.
@Test
public void itextLibTest() throws Exception {
final OutputStream os = new BufferedOutputStream(new FileOutputStream("target/itextTest.pdf"));
final Rectangle pageSize = PageSize.LETTER;
final Document document = new Document(pageSize);
logger.debug("Document created: " + document);
final PdfWriter writer = PdfWriter.getInstance(document, os);
document.open();
final PdfContentByte canvas = writer.getDirectContent();
logger.debug("CB0 created: " + canvas.getClass());
final float pageWidth = pageSize.getWidth();
final float pageHeight = pageSize.getHeight();
logger.debug("Page W: " + pageWidth + " Page H: " + pageHeight);
final DefaultFontMapper fontMapper = new DefaultFontMapper();
logger.debug("FontMapper created = " + fontMapper);
final Graphics2D g = canvas.createGraphics(pageWidth, pageHeight);
logger.debug("! G2D created = " + g);
assertNotNull(g);
g.dispose();
document.close();
os.close();
}
use of com.lowagie.text.Rectangle in project dhis2-core by dhis2.
the class DefaultPdfDataEntryFormService method insertTable_OrgAndPeriod.
private void insertTable_OrgAndPeriod(PdfPTable mainTable, PdfWriter writer, List<Period> periods) throws IOException, DocumentException {
boolean hasBorder = false;
float width = 220.0f;
// Input TextBox size
Rectangle rectangle = new Rectangle(width, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
// Add Organization ID/Period textfield
// Create A table to add for each group AT HERE
// Code 1
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[] { 1, 3 });
table.setHorizontalAlignment(Element.ALIGN_LEFT);
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), "Organization unit identifier", Element.ALIGN_RIGHT);
addCell_WithTextField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), PdfDataEntryFormUtil.LABELCODE_ORGID, PdfFieldCell.TYPE_TEXT_ORGUNIT);
String[] periodsTitle = getPeriodTitles(periods, format);
String[] periodsValue = getPeriodValues(periods);
addCell_Text(table, PdfDataEntryFormUtil.getPdfPCell(hasBorder), "Period", Element.ALIGN_RIGHT);
addCell_WithDropDownListField(table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell(hasBorder), PdfDataEntryFormUtil.LABELCODE_PERIODID, periodsTitle, periodsValue);
// Add to the main table
PdfPCell cell_withInnerTable = new PdfPCell(table);
// cell_withInnerTable.setPadding(0);
cell_withInnerTable.setBorder(Rectangle.NO_BORDER);
cell_withInnerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
mainTable.addCell(cell_withInnerTable);
}
use of com.lowagie.text.Rectangle in project dhis2-core by dhis2.
the class DefaultPdfDataEntryFormService method setProgramStage_DocumentContent.
private void setProgramStage_DocumentContent(Document document, PdfWriter writer, String programStageUid) throws Exception {
ProgramStage programStage = programStageService.getProgramStage(programStageUid);
if (programStage == null) {
throw new RuntimeException("Error - ProgramStage not found for UID " + programStageUid);
} else {
// Get Rectangle with TextBox Width to be used
Rectangle rectangle = new Rectangle(0, 0, TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
// Create Main Layout table and set the properties
PdfPTable mainTable = getProgramStageMainTable();
// Generate Period List for ProgramStage
List<Period> periods = getProgramStagePeriodList();
// Add Org Unit, Period, Hidden ProgramStageID Field
insertTable_OrgAndPeriod(mainTable, writer, periods);
insertTable_TextRow(writer, mainTable, TEXT_BLANK);
// Add ProgramStage Field - programStage.getId();
insertTable_HiddenValue(mainTable, rectangle, writer, PdfDataEntryFormUtil.LABELCODE_PROGRAMSTAGEIDTEXTBOX, String.valueOf(programStage.getId()));
// Add ProgramStage Content to PDF - [The Main Section]
insertTable_ProgramStage(mainTable, writer, programStage);
// Add the mainTable to document
document.add(mainTable);
}
}
Aggregations