Page 1 of 1

docx to pdf -whitespaces not preserved

PostPosted: Tue Feb 20, 2018 11:36 pm
by Asttle
I am using the following code and jars used are docx4j-3.3.6 and docx4j-export-fo-3.3.4

Code: Select all
FOSettings foSettings = Docx4J.createFOSettings();
           foSettings.setImageDirPath("Documents\\images\\");
      InputStream is = new FileInputStream(new File("Documents\\sampleword.docx"));
      WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
       MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
      PhysicalFonts.discoverPhysicalFonts();
      Map<String, PhysicalFont> physicalFonts = PhysicalFonts.getPhysicalFonts();
      Iterator<Entry<String, PhysicalFont>> availableFonts = physicalFonts.entrySet().iterator();
      while(availableFonts.hasNext())
      {
         Entry<String, PhysicalFont> font = availableFonts.next();
         String key = font.getKey();
         PhysicalFont pFont = font.getValue();
         System.out.println("Key is " + key + ";; Name " + pFont.getName());
      }
      Mapper fontMapper = new IdentityPlusMapper();
      PhysicalFont font  = PhysicalFonts.get("Arial Unicode MS");
      fontMapper.put("Times New Roman", font);
      fontMapper.put("Arial", font);
      wordMLPackage.setFontMapper(fontMapper);
      foSettings.setWmlPackage(wordMLPackage);
      OutputStream pdfOutputStream = new FileOutputStream("Documents\\output.pdf");
      System.out.println(foSettings.getSettings());
      Docx4J.toFO(foSettings, pdfOutputStream, Docx4J.FLAG_EXPORT_PREFER_XSL);


the whitespaces are not preserved in the resulting pdf

Re: docx to pdf -whitespaces not preserved

PostPosted: Wed Feb 21, 2018 10:00 pm
by Asttle
This is my fo file
Code: Select all
<?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><layout-master-set xmlns="http://www.w3.org/1999/XSL/Format" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"><simple-page-master margin-bottom="0.5in" margin-left="1.25in" margin-right="1.25in" margin-top="0.5in" master-name="s1-simple" page-height="297mm" page-width="210mm"><region-body column-count="1" column-gap="0.5in" margin-bottom="36.0pt" margin-left="0mm" margin-right="0mm" margin-top="36.0pt"/><region-before extent="0.0pt" region-name="xsl-region-before-simple"/><region-after extent="0.0pt" region-name="xsl-region-after-simple"/></simple-page-master><page-sequence-master master-name="s1"><repeatable-page-master-alternatives><conditional-page-master-reference master-reference="s1-simple"/></repeatable-page-master-alternatives></page-sequence-master></layout-master-set><fo:page-sequence force-page-count="no-force" id="section_s1" format="" master-reference="s1"><fo:flow flow-name="xsl-region-body"><fo:block break-before="auto" font-size="10.0pt"><inline xmlns="http://www.w3.org/1999/XSL/Format" font-size="10.0pt"><inline font-family="Calibri">Hi                      Hello</inline></inline></fo:block>
 
 
 
  </fo:flow></fo:page-sequence></fo:root>




Why whitespace treatment is not applied?

Re: docx to pdf -whitespaces not preserved

PostPosted: Thu Feb 22, 2018 4:14 pm
by Asttle
Similarly textboxes are also not working.Am i missing any line of code?