use of org.apache.poi.xwpf.usermodel.XWPFRun in project tutorials by eugenp.
the class PDF2WordExample method generateDocFromPDF.
private static void generateDocFromPDF(String filename) throws IOException {
XWPFDocument doc = new XWPFDocument();
String pdf = filename;
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
TextExtractionStrategy strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
String text = strategy.getResultantText();
XWPFParagraph p = doc.createParagraph();
XWPFRun run = p.createRun();
run.setText(text);
run.addBreak(BreakType.PAGE);
}
FileOutputStream out = new FileOutputStream("src/output/pdf.docx");
doc.write(out);
out.close();
reader.close();
doc.close();
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project tutorials-java by Artister.
the class WordIntegrationTest method whenParsingOutputDocument_thenCorrect.
@Test
public void whenParsingOutputDocument_thenCorrect() throws Exception {
Path msWordPath = Paths.get(WordDocument.output);
XWPFDocument document = new XWPFDocument(Files.newInputStream(msWordPath));
List<XWPFParagraph> paragraphs = document.getParagraphs();
document.close();
XWPFParagraph title = paragraphs.get(0);
XWPFRun titleRun = title.getRuns().get(0);
assertEquals("Build Your REST API with Spring", title.getText());
assertEquals("009933", titleRun.getColor());
assertTrue(titleRun.isBold());
assertEquals("Courier", titleRun.getFontFamily());
assertEquals(20, titleRun.getFontSize());
assertEquals("from HTTP fundamentals to API Mastery", paragraphs.get(1).getText());
assertEquals("What makes a good API?", paragraphs.get(3).getText());
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph1), paragraphs.get(4).getText());
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph2), paragraphs.get(5).getText());
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph3), paragraphs.get(6).getText());
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.
the class DocxGenerator method addLicenses.
private void addLicenses(XWPFDocument document, LicenseInfoParsingResult parsingResult, boolean includeObligations) throws TException {
XWPFRun licensesTitleRun = document.createParagraph().createRun();
addNewLines(licensesTitleRun, 1);
addFormattedText(licensesTitleRun, "Licenses", FONT_SIZE, true);
for (String licenseName : getReleasesLicenses(parsingResult)) {
XWPFParagraph licensePara = document.createParagraph();
licensePara.setSpacingAfter(0);
addBookmarkHyperLink(licensePara, licenseName, licenseName);
if (includeObligations) {
addLicenseObligations(document, licenseName);
}
}
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project sw360portal by sw360.
the class DocxGenerator method addCopyrights.
private void addCopyrights(XWPFDocument document, LicenseInfoParsingResult parsingResult) {
XWPFRun copyrightTitleRun = document.createParagraph().createRun();
addFormattedText(copyrightTitleRun, "Copyrights", FONT_SIZE, true);
for (String copyright : getReleaseCopyrights(parsingResult)) {
XWPFParagraph copyPara = document.createParagraph();
copyPara.setSpacingAfter(0);
setText(copyPara.createRun(), copyright);
}
}
use of org.apache.poi.xwpf.usermodel.XWPFRun in project poi by apache.
the class SimpleImages method main.
public static void main(String[] args) throws IOException, InvalidFormatException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
XWPFRun r = p.createRun();
for (String imgFile : args) {
int format;
if (imgFile.endsWith(".emf"))
format = XWPFDocument.PICTURE_TYPE_EMF;
else if (imgFile.endsWith(".wmf"))
format = XWPFDocument.PICTURE_TYPE_WMF;
else if (imgFile.endsWith(".pict"))
format = XWPFDocument.PICTURE_TYPE_PICT;
else if (imgFile.endsWith(".jpeg") || imgFile.endsWith(".jpg"))
format = XWPFDocument.PICTURE_TYPE_JPEG;
else if (imgFile.endsWith(".png"))
format = XWPFDocument.PICTURE_TYPE_PNG;
else if (imgFile.endsWith(".dib"))
format = XWPFDocument.PICTURE_TYPE_DIB;
else if (imgFile.endsWith(".gif"))
format = XWPFDocument.PICTURE_TYPE_GIF;
else if (imgFile.endsWith(".tiff"))
format = XWPFDocument.PICTURE_TYPE_TIFF;
else if (imgFile.endsWith(".eps"))
format = XWPFDocument.PICTURE_TYPE_EPS;
else if (imgFile.endsWith(".bmp"))
format = XWPFDocument.PICTURE_TYPE_BMP;
else if (imgFile.endsWith(".wpg"))
format = XWPFDocument.PICTURE_TYPE_WPG;
else {
System.err.println("Unsupported picture: " + imgFile + ". Expected emf|wmf|pict|jpeg|png|dib|gif|tiff|eps|bmp|wpg");
continue;
}
r.setText(imgFile);
r.addBreak();
// 200x200 pixels
r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200));
r.addBreak(BreakType.PAGE);
}
FileOutputStream out = new FileOutputStream("images.docx");
doc.write(out);
out.close();
doc.close();
}
Aggregations