Page 1 of 1

Insert new page to document

PostPosted: Sat Jun 05, 2010 4:57 am
by padcoe
Hey :D

I'm new to docx4j and i have a doubt how i can insert a new page to document. Actually i have a looping that fill my document with values but i need to insert a new page to fill next values.

How can i do it?
Code: Select all
   public byte[] criarArquivo(File[] imagens, Collection<StepTO> objs) {      
      try {
         WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
         MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();   
         
         for(StepTO stepTO : objs){
            
            mainDocumentPart.addParagraphOfText("Step: " + stepTO.getStStepName());
            mainDocumentPart.addParagraphOfText("Data Execução: " + new SimpleDateFormat("dd/MM/yy").format(stepTO.getStExecutionDate()));
            
            for(File file : imagens){
               if(file.getName().contains(String.valueOf(stepTO.getStId()))){
                  mainDocumentPart.addObject(createImage(wordMLPackage, file.getAbsolutePath()));
               }
            }

            // HERE SHOULD BE A NEW PAGE DO NEXT OBJECT ON LOOP
         }
         
         System.out.println("Saved.");
         wordMLPackage.save(new java.io.File("D:\\ad22.docx") );
         
      } catch (InvalidFormatException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }      
      // TODO Auto-generated method stub
      return null;
   }

}


Thanks.

David

Re: Insert new page to document

PostPosted: Mon Jun 07, 2010 4:01 pm
by jason
You are aiming to create:
Code: Select all
<w:p>
      <w:r>
        <w:br w:type="page" />
      </w:r>
    </w:p>


There are a few ways to create the w:br WordML (see the Getting Started Guide). Here is the ObjectFactory way:

Code: Select all
ObjectFactory factory = Context.getWmlObjectFactory();
Br br = factory.createBr();
br.setType(....

Re: Insert new page to document

PostPosted: Tue Jun 08, 2010 1:50 am
by padcoe
Thanks..it works!!