List of usage examples for org.apache.poi.xwpf.usermodel Document PICTURE_TYPE_JPEG
int PICTURE_TYPE_JPEG
To view the source code for org.apache.poi.xwpf.usermodel Document PICTURE_TYPE_JPEG.
Click Source Link
From source file:com.Base.JavaApplication1.java
public static void save(String path) { try {/*from ww w .j a va 2 s . c o m*/ // JOptionPane.showMessageDialog(null, "Start ImageDoc","Error",JOptionPane.INFORMATION_MESSAGE); //String comment=comment; XWPFDocument docx = new XWPFDocument(); // JOptionPane.showMessageDialog(null, "create ImageDoc","Error",JOptionPane.INFORMATION_MESSAGE); XWPFParagraph par = docx.createParagraph(); XWPFRun run = par.createRun(); run.setText(comment); run.setFontSize(13); FileOutputStream out = new FileOutputStream(path); //JOptionPane.showMessageDialog(null, "Dir"+dir+"\\"+name,"Error",JOptionPane.INFORMATION_MESSAGE); // byte [] picbytes = IOUtils.toByteArray(pic); // run.setText("Software Genrated File"); File f = new File("C:\\images\\*.*"); String str = f.getParent(); File k = new File(str); String list[] = k.list(); JOptionPane.showMessageDialog(null, "Reading Files", "Error", JOptionPane.INFORMATION_MESSAGE); for (int y = 0; y < list.length; y++) { InputStream pic = new FileInputStream("C:\\images\\" + list[y]); XWPFRun run2 = par.createRun(); // run2.setText("Screen Shot No."+(y+1)); run2.addPicture(pic, Document.PICTURE_TYPE_JPEG, "C:\\images\\" + list[y], Units.toEMU(500), Units.toEMU(350)); // XWPFRun run2 = title.createRun(); run2.setText("ScreenShot :" + (y + 1)); pic.close(); System.gc(); } //run.setText("Hello, World. This is my first java generated docx-file. Have fun2shhhh."); // FileInputStream pic2 = new FileInputStream("D:\\i.png"); //byte [] picbytes2 = IOUtils.toByteArray(pic); //docx.addPictureData(IOUtils.toByteArray(pic2), Document.PICTURE_TYPE_PNG); // docx.createParagraph().createRun().addPicture(pic, Document.PICTURE_TYPE_JPEG, "D:\\images\\image0.jpg", Units.toEMU(500), Units.toEMU(500)); XWPFParagraph title = docx.createParagraph(); XWPFRun run2 = title.createRun(); run2.setText(" "); run2.setBold(true); title.setAlignment(ParagraphAlignment.CENTER); JOptionPane.showMessageDialog(null, "Writing File", "Error", JOptionPane.INFORMATION_MESSAGE); System.out.println(dir + name); docx.write(out); out.close(); // pic.close(); JOptionPane.showMessageDialog(null, "Operation Complete", "Error", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(null, "No Image to save!" + e, "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout.java
License:Apache License
private void createWordDocument() { try {//from w ww .j a va 2 s . c om XWPFDocument doc = new XWPFDocument(); fillWordDocument(doc); InputStream pic = new FileInputStream("C://Users/user//Desktop//adobe.png"); // doc.addPictureData(pic, Document.PICTURE_TYPE_JPEG); FileOutputStream out = new FileOutputStream("C://temp//POIWord_1.docx"); doc.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.obeonetwork.m2doc.generator.TemplateProcessor.java
License:Open Source License
/** * Returns the picture type based on the filename's extension. * /* w w w. j av a 2 s .c om*/ * @param fileName * the picture file * @return the picture's file extension */ private int getPictureType(String fileName) { String[] segments = fileName.split("\\."); int result; if (segments.length > 1) { String extension = segments[segments.length - 1].trim(); if ("jpg".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_JPEG; } else if ("gif".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_GIF; } else if ("png".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_PNG; } else if ("emf".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_EMF; } else if ("wmf".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_WMF; } else if ("pict".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_PICT; } else if ("dib".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_DIB; } else if ("tiff".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_TIFF; } else if ("eps".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_EPS; } else if ("bmp".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_BMP; } else if ("wpg".equalsIgnoreCase(extension)) { result = Document.PICTURE_TYPE_WPG; } else { result = 0; } } else { result = 0; } return result; }