List of usage examples for com.lowagie.text PageSize A4
Rectangle A4
To view the source code for com.lowagie.text PageSize A4.
Click Source Link
From source file:ch.brinika.sportsplanner5000.controller.EventController.java
/** * Diese Methode setzt die zu exportierde PDF-Seite auf Querformat * @param document zu exportierendes Dokument *//*from w ww .j ava 2s .c o m*/ public void preProcessDoc(Object document) { Document doc = (Document) document; doc.setPageSize(PageSize.A4.rotate()); }
From source file:ch.elexis.omnivore.data.DocHandle.java
License:Open Source License
public static List<DocHandle> assimilate(List<ImageData> images) { List<DocHandle> ret = new ArrayList<DocHandle>(); FileImportDialog fid = new FileImportDialog(Messages.DocHandle_scannedImageDialogCaption); if (fid.open() == Dialog.OK) { try {//from w w w.j av a 2s. co m Document pdf = new Document(PageSize.A4); pdf.setMargins(0, 0, 0, 0); ByteArrayOutputStream baos = new ByteArrayOutputStream(100000); PdfWriter.getInstance(pdf, baos); pdf.open(); ImageLoader il = new ImageLoader(); for (int i = 0; i < images.size(); i++) { ImageData[] id = new ImageData[] { images.get(i) }; il.data = id; ByteArrayOutputStream bimg = new ByteArrayOutputStream(); il.save(bimg, SWT.IMAGE_PNG); Image image = Image.getInstance(bimg.toByteArray()); int width = id[0].width; int height = id[0].height; // 210mm = 8.27 In = 595 px bei 72dpi // 297mm = 11.69 In = 841 px if ((width > 595) || (height > 841)) { image.scaleToFit(595, 841); } pdf.add(image); } pdf.close(); DocHandle docHandle = new DocHandle(fid.category, baos.toByteArray(), ElexisEventDispatcher.getSelectedPatient(), fid.originDate, fid.title, "image.pdf", //$NON-NLS-1$ fid.keywords); ret.add(docHandle); } catch (Exception ex) { ExHandler.handle(ex); SWTHelper.showError(Messages.DocHandle_readError, Messages.DocHandle_readErrorText2); } } return ret; }
From source file:ch.emad.business.schuetu.print.PrintAgent.java
License:Apache License
public void saveFileToPrint(String name, String htmlContent) { OutputStream os = null;/*from w ww . j a va 2 s . co m*/ try { if (!this.init) { map.put(name, htmlContent); return; } CleanerProperties props = new CleanerProperties(); // set some properties to non-default values props.setTranslateSpecialEntities(true); props.setTransResCharsToNCR(true); props.setOmitComments(true); // do parsing LOG.info("HtmlCleaner! Body wegnehmen"); TagNode tagNode = new HtmlCleaner(props).clean(htmlContent); Object[] o = tagNode.evaluateXPath("//body"); // serialize to xml file new PrettyXmlSerializer(props).writeToFile( // --> mit utf-8 wurden sonderzeichen falsch gedruckt pathprinter+"out.xml", "utf-8" (TagNode) o[0], pathprinter + "out.xml"); String outputFile = pathprinter + name + ".pdf"; os = new FileOutputStream(outputFile); Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, os); doc.open(); HTMLWorker hw = new HTMLWorker(doc); hw.parse(new FileReader(pathprinter + "out.xml")); doc.close(); if (this.applicationEventPublisher != null) { ch.emad.model.schuetu.model.integration.File file = new ch.emad.model.schuetu.model.integration.File(); file.setContent(IOUtils.toByteArray(new FileInputStream(new File(outputFile)))); file.setName(name + ".pdf"); OutgoingMessage fileOut = new OutgoingMessage(this); fileOut.setPayload(file); this.applicationEventPublisher.publishEvent(fileOut); } } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } FileUtils.deleteQuietly(new File(pathprinter + "out.xml")); }
From source file:ch.gpb.elexis.cst.view.CstResultPart.java
License:Open Source License
private void makeActions(final Control viewer) { actionScreenshot = new Action() { public void run() { if (profile == null) { SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden"); return; }/*from www . j a va2 s .c om*/ GC gc = null; Image image = null; try { String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null); if (latestPath == null) { latestPath = System.getProperty("user.home"); } FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE); fd.setText("Save"); fd.setFilterPath(latestPath); String[] filterExt = { "*.png", "*.*" }; fd.setFilterExtensions(filterExt); fd.setFileName(CstService.generateFilename(patient)); String selected = fd.open(); if (selected == null) { return; } File selFile = new File(selected); CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH, selFile.getParentFile().getAbsolutePath()); //if (profile.getAnzeigeTyp().toLowerCase().equals("effektiv")) { if (profile.getAnzeigeTyp().toLowerCase().equals(CstProfile.ANZEIGETYP_EFFEKTIV)) { if (profile.getAusgabeRichtung()) { image = new Image(viewer.getDisplay(), 1123, viewer.getBounds().height); } else { image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height); } } else { image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height); } ImageLoader loader = new ImageLoader(); gc = new GC(image); viewer.print(gc); gc.dispose(); loader.data = new ImageData[] { image.getImageData() }; loader.save(selected, SWT.IMAGE_PNG); } catch (Exception e) { log.error("Error saving png: " + e.toString()); showMessage("Error while saving PNG", e.getMessage()); } finally { if (image != null) { image.dispose(); } if (gc != null) { gc.dispose(); } } } }; actionScreenshot.setText(Messages.Cst_Text_Save_as_png); actionScreenshot.setToolTipText(Messages.Cst_Text_Save_as_png); actionScreenshot.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT)); actionScreenshot.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PNG_PATH)); // TODO: die pdf ausgabe ist eine ziemliche Baustelle - berarbeiten actionPdf = new Action() { public void run() { ////////////////////////// if (profile == null) { SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden"); return; } GC gc = null; Image image = null; try { String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null); if (latestPath == null) { latestPath = System.getProperty("user.home"); } FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE); fd.setText("Save"); fd.setFilterPath(latestPath); String[] filterExt = { "*.pdf", "*.*" }; fd.setFilterExtensions(filterExt); fd.setFileName(CstService.generateFilename(patient)); String selected = fd.open(); if (selected == null) { return; } File selFile = new File(selected); CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH, selFile.getParentFile().getAbsolutePath()); int printHeigth = 1123; int printWidth = 794; if (profile.getAusgabeRichtung()) { printHeigth = 794; printWidth = 1123; } // get the image from the viewport image = new Image(viewer.getDisplay(), printWidth, viewer.getBounds().height); ImageLoader loader = new ImageLoader(); gc = new GC(image); viewer.print(gc); gc.dispose(); // prepare title data //Date date = new Date(); //SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); Patient patient = Patient.load(profile.getKontaktId()); //String sTitle = "Gemeinschaftspraxis Brunnmatt Dr. Beat Knzi "; String sTitle; sTitle = profile.getOutputHeader() == null ? "No header configured!" : profile.getOutputHeader(); if (sTitle == null || sTitle.length() == 0) { sTitle = "No header configured!"; } sTitle = sTitle + " Datum: " + CstService.getReadableDateAndTime(); // get option (paging to A4/ in one piece) int pdfOutputOption = 0; boolean onePage = true; PdfOptionsDialog dialog = new PdfOptionsDialog(baseComposite.getShell()); dialog.create(); if (dialog.open() == Window.OK) { pdfOutputOption = dialog.getPdfOutputOption(); if (pdfOutputOption == PdfOptionsDialog.OPTION_ONE_PAGE) { onePage = true; } else { onePage = false; } } float docHeight = viewer.getBounds().height; docHeight = docHeight / 7.5f; float fontSize = 12f; if (docHeight < 360f) { docHeight = 360f; } BufferedImage bimage = ImageUtils.convertToAWT(image.getImageData()); // create an Itextt Image from AWT BufferedImage com.lowagie.text.Image itextImage = null; java.awt.Image awtImage = null; try { awtImage = Toolkit.getDefaultToolkit().createImage(bimage.getSource()); itextImage = com.lowagie.text.Image.getInstance(awtImage, null); } catch (Exception e) { log.error("Error on image loading: " + e.toString()); e.printStackTrace(); } // only for debugging //loader.data = new ImageData[] { image.getImageData() }; //loader.save("C:\\Users\\daniel\\tmp\\debug.png", SWT.IMAGE_PNG); Rectangle pagesize = new Rectangle(595f, itextImage.getHeight() * 0.75f); // is it a4 quer? if (profile.getAusgabeRichtung()) { pagesize = new Rectangle(842f, itextImage.getHeight() * 0.75f); } //System.out.println("pagesize: " + pagesize.toString()); Document document; if (onePage) { document = new Document(pagesize); } else { document = new Document(PageSize.A4); if (profile.getAusgabeRichtung()) { document = new Document(PageSize.A4.rotate()); } } document.addCreationDate(); try { // creation of the different writers PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selected)); // various fonts BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", true); BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true); BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", true); com.lowagie.text.Font fontHelv12 = new com.lowagie.text.Font(bf_helv, fontSize); com.lowagie.text.Font fontTimes = new com.lowagie.text.Font(bf_times, fontSize); fontTimes.setSize(fontSize); fontTimes.setStyle(com.lowagie.text.Font.ITALIC); Chunk chunkHeader = new Chunk(sTitle, FontFactory.getFont(FontFactory.HELVETICA, fontSize, com.lowagie.text.Font.NORMAL, new java.awt.Color(255, 0, 0))); com.lowagie.text.Phrase phraseHeader = new com.lowagie.text.Phrase(chunkHeader); // headers and footers must be added before the document // is opened Chunk chunkFooter = new Chunk("Seite: ", FontFactory.getFont(FontFactory.HELVETICA, fontSize, com.lowagie.text.Font.BOLD, new java.awt.Color(0, 0, 0))); Phrase phraseFooter = new Phrase(chunkFooter); phraseFooter.setFont(fontHelv12); HeaderFooter footer = new HeaderFooter(phraseFooter, true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); Phrase headerPhrase = new Phrase(sTitle); headerPhrase.setFont(fontTimes); HeaderFooter header = new HeaderFooter(phraseHeader, false); header.setBorder(Rectangle.BOTTOM); header.setBorderWidth(0.5f); header.setAlignment(Element.ALIGN_LEFT); document.setHeader(header); document.open(); //System.out.println("itext image w: " + itextImage.getWidth() + " h:" + itextImage.getHeight()); if (onePage) { int scale = 66; itextImage.scalePercent(scale); document.add(itextImage); } else { BufferedImage[] imageChunks = ImageUtils.splitImageByHeigth(bimage, printHeigth); for (int i = 0; i < imageChunks.length; i++) { com.lowagie.text.Image itextImage2 = com.lowagie.text.Image.getInstance( Toolkit.getDefaultToolkit().createImage(imageChunks[i].getSource()), null); // width becomes typically 523 (595 - 72) for a4Hoch or 770 (842 - 72) for A4Quer float imgWidth = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(); float imgHeigth = itextImage.getHeight() * 0.75f; itextImage2.setAbsolutePosition(30, 20); int scale = 66; itextImage2.scalePercent(scale); document.add(itextImage2); document.newPage(); } } // we're done! document.close(); /////////////////////////////// } catch (Exception ex) { log.error(ex.getMessage()); showMessage("Error while generating PDF", ex.getMessage()); } } finally { if (image != null) { image.dispose(); } if (gc != null) { gc.dispose(); } /* image.dispose(); gc.dispose(); */ } } }; actionPdf.setText(Messages.Cst_Text_Save_as_pdf); actionPdf.setToolTipText(Messages.Cst_Text_Save_as_pdf); /* * actionPdf.setImageDescriptor(PlatformUI.getWorkbench() .getSharedImages() * .getImageDescriptor(ISharedImages.IMG_OBJ_FILE)); */ actionPdf.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PDF_PATH)); }
From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java
License:Open Source License
public static void createLaborwertTable(Patient patient, String filename, LinkedList<String[]> laborBlatt, String footerText) throws IOException, DocumentException { // step 1/*from w w w . j a va 2s .c om*/ Document document = new Document(PageSize.A4); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); event.setHeaderText( patient.getVorname() + " " + patient.getName() + " (" + patient.getGeburtsdatum() + ")"); event.setFooterText(footerText); writer.setPageEvent(event); document.setMargins(56, 72, 60, 60); // step 3 document.open(); if (laborBlatt.size() == 0) { Paragraph p = new Paragraph(new Chunk("Keine Laborwerte vorhanden", fontTimesTitle)); p.setSpacingBefore(20f); document.add(p); } else { document.add(createTable2(laborBlatt)); } // step 5 document.close(); }
From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java
License:Open Source License
public static void createPdf(Patient patient, String filename, LinkedList<String[]> laborBlatt) throws IOException, DocumentException { BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", true); fontTimes = new com.lowagie.text.Font(bf_helv, 6); // step 1//from ww w.j a va 2 s . c om Document document = new Document(PageSize.A4.rotate()); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.setHeader(getHeader( patient.getVorname() + " " + patient.getName() + " Geburtsdatum: " + patient.getGeburtsdatum())); document.open(); document.add(new Chunk("")); // << this will do the trick. // step 4 document.add(createTable2(laborBlatt)); // step 5 document.close(); }
From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java
License:Open Source License
public static void createDiagnosenSheet(Patient patient, String filename, String footerText) throws DocumentException, IOException { StringBuffer sb = new StringBuffer("Diagnosen:\n"); sb.append(patient.getDiagnosen());/*from ww w .j a v a2s. c om*/ sb.append("\n"); sb.append("Persnliche Anamnese:\n"); sb.append(patient.getPersAnamnese()); sb.append("\n"); // step 1 Document document = new Document(PageSize.A4); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 //Rectangle rect = new Rectangle(30, 30, 559, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); event.setHeaderText( patient.getVorname() + " " + patient.getName() + " (" + patient.getGeburtsdatum() + ")"); event.setFooterText(footerText); writer.setPageEvent(event); document.setMargins(36, 72, 60, 60); // step 3 document.open(); document.add(new Chunk("")); // << this will do the trick. if (patient.getDiagnosen().length() > 0) { Paragraph p = new Paragraph("Diagnosen:", fontTimesTitle); p.setSpacingAfter(10f); document.add(p); String[] chunksDiag = patient.getDiagnosen().toString().split("(?m)^\\s*$"); for (String chunk : chunksDiag) { document.add(new Paragraph(chunk, fontTimes)); } } else { document.add(new Paragraph("Keine Diagnosen vorhanden", fontTimes)); } if (patient.getPersAnamnese().length() > 0) { Paragraph p = new Paragraph("Persnliche Anamnese:", fontTimesTitle); p.setSpacingBefore(10f); p.setSpacingAfter(10f); document.add(p); String[] chunksAnam = patient.getPersAnamnese().toString().split("(?m)^\\s*$"); for (String chunk : chunksAnam) { document.add(new Paragraph(chunk, fontTimes)); } } else { document.add(new Paragraph("Keine Persnliche Anamnese vorhanden", fontTimes)); } // step 5 document.close(); }
From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java
License:Open Source License
public static void createFixMediSheet(Patient patient, String filename, String footerText) throws DocumentException, IOException { Prescription[] prescriptions = patient.getFixmedikation(); StringBuffer sb = new StringBuffer(); for (Prescription prescription : prescriptions) { //System.out.println("Prescription: " + prescription.getLabel() + "/" + prescription.getDosis()); sb.append(prescription.getLabel()); sb.append("\r\n"); }//from w ww . j a va 2 s .c o m // step 1 Document document = new Document(PageSize.A4); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 //Rectangle rect = new Rectangle(30, 30, 559, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); event.setHeaderText( patient.getVorname() + " " + patient.getName() + " (" + patient.getGeburtsdatum() + ")"); event.setFooterText(footerText); writer.setPageEvent(event); document.setMargins(36, 72, 60, 60); // step 3 document.open(); document.add(new Chunk("")); // << this will do the trick. if (sb.length() > 0) { Paragraph p = new Paragraph("Fixmedikation:", fontTimesTitle); p.setSpacingAfter(10f); document.add(p); String[] chunksDiag = sb.toString().split("(?m)^\\s*$"); for (String chunk : chunksDiag) { document.add(new Paragraph(chunk, fontTimes)); } } else { //document.add(new Paragraph("Keine Medikationen vorhanden", fontTimes)); Paragraph p = new Paragraph(new Chunk("Keine Medikationen vorhanden", fontTimesTitle)); p.setSpacingBefore(20f); document.add(p); } // step 5 document.close(); }
From source file:classroom.filmfestival_c.Movies19.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*w w w.ja va 2 s .c o m*/ Rectangle rect = PageSize.A4.rotate(); Document document = new Document(rect); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); writer.setBoxSize("art", art); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery( "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day"); java.util.List<Date> days = q.list(); for (Date day : days) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(day); if (gc.get(GregorianCalendar.YEAR) != YEAR) continue; createSheet(session, day, writer); document.newPage(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_c.Movies20.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from ww w . ja va2 s . com Rectangle rect = PageSize.A4.rotate(); Document document = new Document(rect); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); Rectangle art = new Rectangle(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); writer.setBoxSize("art", art); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); // step 3 document.open(); // step 4 PdfOutline root = writer.getDirectContent().getRootOutline(); Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery( "select distinct festival.id.day from FestivalScreening as festival order by festival.id.day"); java.util.List<Date> days = q.list(); for (Date day : days) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(day); if (gc.get(GregorianCalendar.YEAR) != YEAR) continue; createSheet(session, day, writer); new PdfOutline(root, new PdfDestination(PdfDestination.FIT), day.toString()); document.newPage(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }