Results 1 to 13 of 13
  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    135
    Rep Power
    0

    Default Header in javadocx

    Hi,

    I have written a class that writes text to a docx document using javadocx.
    In my document I want to add a footer and header.
    The header I would like to use a picture (logo) but for some reason the picture isn't showing.

    Heres some of my code:
    Java Code:
    CreateDocx docx = new CreateDocx("docx");
            
            HashMap paramsHeader = new HashMap();
            paramsHeader.put("name", "image.png");
            paramsHeader.put("jc", "right");
            paramsHeader.put("font", "Times New Roman");
            paramsHeader.put("textWrap", "5");
            String header = "Topptekst";
            docx.addHeader(header, paramsHeader);
            paramsHeader.clear();

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Header in javadocx

    Can you show the code that loads/opens the image file?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Header in javadocx

    Is the header supposed to handle that for Javadocx?

    Have you looked at the file that's been generated?
    Have you then compared it with one that you've manually created with an image in a header?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    135
    Rep Power
    0

    Default Re: Header in javadocx

    Heres a example from the free version of javadocx:

    Java Code:
    /*
     * Copyright (c) 2009-2010 Narcea Producciones Multimedia S.L.
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public License
     * version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
     */
    
    package examples.intermediate;
    
    import com.javadocx.CreateDocx;
    import java.util.HashMap;
    
    /**
     * Create a DOCX file. Header and footer example
     *
     * @version    2.1
     */
    public class HeaderAndFooter {
        /**
         * Create docx file.
         * @param args
         */
        public static void main(final String[] args) {
            CreateDocx docx = new CreateDocx("docx");
    
            String text = "Header Arial";
            HashMap paramsHeader = new HashMap();
            paramsHeader.put("name", "examples/files/img/image.png");
            paramsHeader.put("jc", "right");
            paramsHeader.put("textWrap", "5");
            paramsHeader.put("font", "Arial");
    
            docx.addHeader(text, paramsHeader);
    
            paramsHeader.clear();
    
            text = "Header Times New Roman";
            paramsHeader.put("font", "Arial");
    
            docx.addHeader(text, paramsHeader);
    
            text = "Footer. Times New Roman font";
            HashMap paramsFooter = new HashMap();
            paramsFooter.put("pager", "true");
            paramsFooter.put("pagerAlignment", "center");
            paramsFooter.put("font", "Times New Roman");
    
            paramsFooter.clear();
            
            text = "Footer. Arial";
            paramsFooter.put("font", "Arial");
            docx.addFooter(text, paramsFooter);
    
            docx.createDocx("example_headerandfooter");
        }
    }
    The png file exists, but does not show in the document.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Header in javadocx

    The file may exist, but does it exist at the path implied?
    I've no idea where it treats as the root.

    And why the clear() on the HashMap?
    What happens if you don't clear it?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Header in javadocx

    I would think that the parameter for the "name" key in the hashMap should be a String. I would try to add the header to the docx without the image and then add the image separately at the desired location.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Header in javadocx

    Does the code in post#4 work for you when you compile and execute it?

    Is this a question for the javadocx group?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    135
    Rep Power
    0

    Default Re: Header in javadocx

    Thanks for your replies so far. :)
    @Norm: Yes the code executes, everything is written to the docx exept the image.
    The docx file that is created, is found in the root of the java project. So if I changes the path like this:
    Java Code:
    paramsHeader.put("name", "image.png");
    The file should be found.
    I also wrote a small image open class, and the picture is found:
    Java Code:
    package Classes;
    
    import java.awt.Desktop;
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    public class Picturetest {
        public static void main(final String[] args) {
            
            File file       = new File ("image.png");
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.open(file);
            } catch (IOException ex) {
                Logger.getLogger(Picturetest.class.getName()).log(Level.SEVERE, null, ex);
            }
        } 
    }
    The image opens fine.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Header in javadocx

    No, Norm is asking if the example code works.
    Not your code.

    That's got to be your start point.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    135
    Rep Power
    0

    Default Re: Header in javadocx

    Quote Originally Posted by Tolls View Post
    No, Norm is asking if the example code works.
    Not your code.

    That's got to be your start point.
    That code doesnt show the picture either. The docx is created, the header and footer is written, but no picture.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Header in javadocx

    And the picture is where it says in that code, under some directory like "examples/files/img/image.png"?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    135
    Rep Power
    0

    Default Re: Header in javadocx

    Quote Originally Posted by Tolls View Post
    And the picture is where it says in that code, under some directory like "examples/files/img/image.png"?
    Yes it is.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Header in javadocx

    Then I have no idea.
    As if the example code doesn't work then you probably need to find javadocx experts to explain what's going wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Pascal header into java header ?
    By fredvs in forum New To Java
    Replies: 0
    Last Post: 02-28-2014, 11:18 PM
  2. java rsh header
    By Ericyue in forum New To Java
    Replies: 0
    Last Post: 04-05-2012, 04:47 AM
  3. Fixed Header
    By Quirl in forum New To Java
    Replies: 2
    Last Post: 07-28-2010, 10:19 PM
  4. Header/Footer
    By selva.bics in forum New To Java
    Replies: 0
    Last Post: 11-26-2009, 02:26 PM
  5. header of jtable
    By bbq in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 04:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •