Ignore:
Timestamp:
07/08/10 03:00:13 (23 months ago)
Author:
jharrop
Message:

PDF via XSL FO: support for multiple sections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/Conversion.java

    r1127 r1135  
    3333import org.docx4j.fonts.PhysicalFonts; 
    3434import org.docx4j.jaxb.Context; 
     35import org.docx4j.jaxb.NamespacePrefixMapperUtils; 
    3536import org.docx4j.model.PropertyResolver; 
    3637import org.docx4j.model.TransformState; 
     
    4142import org.docx4j.model.properties.paragraph.Indent; 
    4243import org.docx4j.model.properties.run.Font; 
     44import org.docx4j.model.structure.SectionWrapper; 
     45import org.docx4j.model.structure.jaxb.ObjectFactory; 
     46import org.docx4j.model.structure.jaxb.Sections; 
     47import org.docx4j.model.structure.jaxb.Sections.Section; 
    4348import org.docx4j.model.table.TableModel.TableModelTransformState; 
    4449import org.docx4j.openpackaging.exceptions.Docx4JException; 
    4550import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
     51import org.docx4j.openpackaging.parts.relationships.RelationshipsPart; 
    4652import org.docx4j.wml.Ftr; 
    4753import org.docx4j.wml.Hdr; 
     
    4955import org.docx4j.wml.RFonts; 
    5056import org.docx4j.wml.RPr; 
     57import org.docx4j.wml.SectPr; 
    5158import org.docx4j.wml.Tbl; 
    5259import org.docx4j.wml.Tc; 
     
    261268           */ 
    262269          //Document domDoc = XmlPackage.getFlatDomDocument(wordMLPackage); 
    263           Document domDoc = XmlUtils.marshaltoW3CDomDocument(wordMLPackage.getMainDocumentPart().getJaxbElement()); 
     270          //Document domDoc = XmlUtils.marshaltoW3CDomDocument(wordMLPackage.getMainDocumentPart().getJaxbElement()); 
     271           
     272          Sections sections = createSectionContainers(wordMLPackage); 
     273          Document domDoc = XmlUtils.marshaltoW3CDomDocument(sections, Context.jcSectionModel); 
    264274           
    265275          java.util.HashMap<String, Object> settings = new java.util.HashMap<String, Object>(); 
     
    330340                 
    331341        } 
     342     
     343        private Sections createSectionContainers(WordprocessingMLPackage wordMLPackage) { 
     344                                 
     345                ObjectFactory factory = new ObjectFactory(); 
     346                 
     347                Sections sections = factory.createSections(); 
     348                Section section = factory.createSectionsSection(); 
     349                section.setName("s1"); // name must match fo master 
     350                 
     351                sections.getSection().add(section); 
     352                                                 
     353                org.docx4j.wml.Document doc = (org.docx4j.wml.Document)wordMLPackage.getMainDocumentPart().getJaxbElement(); 
     354                 
     355                int i = 2; 
     356                for (Object o : doc.getBody().getEGBlockLevelElts() ) { 
     357                         
     358                        if (o instanceof org.docx4j.wml.P) { 
     359                                if (((org.docx4j.wml.P)o).getPPr() != null ) { 
     360                                        org.docx4j.wml.PPr ppr = ((org.docx4j.wml.P)o).getPPr(); 
     361                                        if (ppr.getSectPr()!=null) { 
     362                                                section = factory.createSectionsSection(); 
     363                                                section.setName("s" +i); // name must match fo master 
     364                                                sections.getSection().add(section);      
     365                                                i++; 
     366                                        } 
     367                                }                                
     368                        }  
     369                        section.getAny().add( marshall(o) ); 
     370                                // TODO: since the section model knows nothing about WML, 
     371                                // we have to marshall each object separately. 
     372                                // To fix this, next time wml is generated, include the section model there! 
     373                } 
     374                return sections;                                 
     375        } 
     376     
     377        private Element marshall(Object o) { 
     378                 
     379                try { 
     380                        org.w3c.dom.Document w3cDoc =  
     381                                XmlUtils.marshaltoW3CDomDocument(o); 
     382                         
     383                         
     384                                /* Force the RelationshipsPart to be marshalled using 
     385                                 * the normal non-rels part NamespacePrefixMapper, 
     386                                 * since otherwise (because we'd be using 2 namespace 
     387                                 * prefix mappers?) we end up with errant xmlns="", 
     388                                 * which is wrong and stops Word 2007 from loading the 
     389                                 * document. 
     390                                 *  
     391                                 * Note that xmlPackage.xsd defines: 
     392                                 *      <xsd:complexType name="CT_XmlData"> 
     393                                                <xsd:sequence> 
     394                                                        <xsd:any processContents="skip" /> 
     395                                                </xsd:sequence> 
     396                                 * 
     397                                 * Note also that marshaltoString uses  
     398                                 * just the normal non-rels part NamespacePrefixMapper, 
     399                                 * so if/when this is marshalled again, that could 
     400                                 * have been causing problems as well??  
     401                                 */ 
     402                return w3cDoc.getDocumentElement();                      
     403                } catch (Exception e) { 
     404                        // TODO Auto-generated catch block 
     405                        e.printStackTrace(); 
     406                }                        
     407                return null; 
     408                 
     409        } 
     410         
     411         
    332412 
    333413    /* ---------------Xalan XSLT Extension Functions ---------------- */ 
Note: See TracChangeset for help on using the changeset viewer.