@Deprecated public HeaderFooterPolicy getHeaderFooterPolicy() { int last = getDocumentModel().getSections().size(); if (last>0) { // Should always be the case, since we add one, // even if the document contains no sectPr return getDocumentModel().getSections().get(last-1).getHeaderFooterPolicy(); } else { log.error("Unexpected - zero sections?!"); return null; } }
/** * @param filenameHint * @param altText * @param id1 * @param id2 * @param link * @param maxWidth * @return * @throws Exception * @since 3.3.0 */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, boolean link, int maxWidth) throws Exception { // This signature can scale the image to specified maxWidth WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) this.getPackage()); List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); PageDimensions page = sections.get(sections.size() - 1).getPageDimensions(); CxCy cxcy = CxCy.scale(imageInfo, page, maxWidth); return createImageInline(filenameHint, altText, id1, id2, cxcy.getCx(), cxcy.getCy(), link); }
/** * Create a <wp:inline> element suitable for this image, * which can be linked or embedded in w:p/w:r/w:drawing. * If the image is wider than the page, it will be scaled * automatically. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, boolean link) throws Exception { WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) this.getPackage()); List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); PageDimensions page = sections.get(sections.size() - 1).getPageDimensions(); CxCy cxcy = CxCy.scale(imageInfo, page); return createImageInline(filenameHint, altText, id1, id2, cxcy.getCx(), cxcy.getCy(), link); }
SectionWrapper sw = input.getDocumentModel().getSections().get(0); SectPr sectPr = sw.getSectPr();
Inline inline = null; String altText = attributes.contains("alt") ? attributes.getValue("alt") : ""; List<SectionWrapper> sections = docx.getPackage().getDocumentModel().getSections(); PageDimensions page = sections.get(sections.size() - 1).getPageDimensions(); double writableWidthTwips = page.getWritableWidthTwips();
@Deprecated public HeaderFooterPolicy getHeaderFooterPolicy() { int last = getDocumentModel().getSections().size(); if (last>0) { // Should always be the case, since we add one, // even if the document contains no sectPr return getDocumentModel().getSections().get(last-1).getHeaderFooterPolicy(); } else { log.error("Unexpected - zero sections?!"); return null; } }
InputStream is = new FileInputStream(new File(docx_path)); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(is); @SuppressWarnings("rawtypes") List sections = wordMLPackage.getDocumentModel().getSections(); for (int i = 0; i < sections.size(); i++) { wordMLPackage.getDocumentModel().getSections().get(i) .getPageDimensions(); } Mapper fontMapper = new IdentityPlusMapper(); PhysicalFont font = PhysicalFonts.getPhysicalFonts().get( "Times New Roman"); fontMapper.getFontMappings().put("Algerian", font); wordMLPackage.setFontMapper(fontMapper); PdfSettings pdfSettings = new PdfSettings(); org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion( wordMLPackage); OutputStream out = new FileOutputStream(new File(pdf_path)); conversion.output(out, pdfSettings);
InputStream is = new FileInputStream(new File("your Docx PAth")); WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(is); List sections = wordMLPackage.getDocumentModel().getSections(); for (int i = 0; i < sections.size(); i++) { wordMLPackage.getDocumentModel().getSections().get(i) .getPageDimensions(); } Mapper fontMapper = new IdentityPlusMapper(); PhysicalFont font = PhysicalFonts.getPhysicalFonts().get( "Comic Sans MS");//set your desired font fontMapper.getFontMappings().put("Algerian", font); wordMLPackage.setFontMapper(fontMapper); PdfSettings pdfSettings = new PdfSettings(); org.docx4j.convert.out.pdf.PdfConversion conversion = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion( wordMLPackage); //To turn off logger List<Logger> loggers = Collections.<Logger> list(LogManager .getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); for (Logger logger : loggers) { logger.setLevel(Level.OFF); } OutputStream out = new FileOutputStream(new File("Your OutPut PDF path")); conversion.output(out, pdfSettings); System.out.println("DONE!!");
/** * @param filenameHint * @param altText * @param id1 * @param id2 * @param link * @param maxWidth * @return * @throws Exception * @since 3.3.0 */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, boolean link, int maxWidth) throws Exception { // This signature can scale the image to specified maxWidth WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) this.getPackage()); List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); PageDimensions page = sections.get(sections.size() - 1).getPageDimensions(); CxCy cxcy = CxCy.scale(imageInfo, page, maxWidth); return createImageInline(filenameHint, altText, id1, id2, cxcy.getCx(), cxcy.getCy(), link); }
/** * Create a <wp:inline> element suitable for this image, * which can be linked or embedded in w:p/w:r/w:drawing. * If the image is wider than the page, it will be scaled * automatically. * @param filenameHint Any text, for example the original filename * @param altText Like HTML's alt text * @param id1 An id unique in the document * @param id2 Another id unique in the document * @param link true if this is to be linked not embedded * None of these things seem to be exposed in Word 2007's * user interface, but Word won't open the document if * any of the attributes these go in (except @ desc) aren't present! * @throws Exception */ public Inline createImageInline(String filenameHint, String altText, int id1, int id2, boolean link) throws Exception { WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) this.getPackage()); List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); PageDimensions page = sections.get(sections.size() - 1).getPageDimensions(); CxCy cxcy = CxCy.scale(imageInfo, page); return createImageInline(filenameHint, altText, id1, id2, cxcy.getCx(), cxcy.getCy(), link); }
List<SectionWrapper> wrappers = wordMLPackage.getDocumentModel().getSections(); for (SectionWrapper sw : wrappers) { FooterPart footer = sw.getHeaderFooterPolicy().getDefaultFooter();
int writableWidthTwips = wPMLpackage.getDocumentModel().getSections() .get(0).getPageDimensions() .getWritableWidthTwips();
if (reportRegion.isTabulatedRegion()) { mainDocumentPart.addParagraphOfText(""); int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips(); int cols = reportRegion.getRegionProperties().size(); int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
protected Part resolveTextPartForDOCX(Text text, WordprocessingMLPackage wordPackage) { java.util.List<SectionWrapper> sectionWrappers = wordPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); List<Part> parts = Arrays.<Part>asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter()); for (Part part : parts) { TextMatchCallback callback = new TextMatchCallback(text); new TraversalUtil(part, callback); if (callback.matched) { return part; } } } return wordPackage.getMainDocumentPart(); }
protected Part resolveTextPartForDOCX(Text text, WordprocessingMLPackage wordPackage) { java.util.List<SectionWrapper> sectionWrappers = wordPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); List<Part> parts = Arrays.asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter()); for (Part part : parts) { TextMatchCallback callback = new TextMatchCallback(text); new TraversalUtil(part, callback); if (callback.matched) { return part; } } } return wordPackage.getMainDocumentPart(); }
protected void collectHeadersAndFooters() {//collect data from headers List<SectionWrapper> sectionWrappers = wordprocessingMLPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); collectDataFromObjects(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter()); } }
protected void collectHeadersAndFooters() {//collect data from headers List<SectionWrapper> sectionWrappers = wordprocessingMLPackage.getDocumentModel().getSections(); for (SectionWrapper sw : sectionWrappers) { HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy(); collectDataFromObjects(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(), hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter()); } }
SectionWrapper sw = input.getDocumentModel().getSections().get(0); SectPr sectPr = sw.getSectPr();