Results 1 to 4 of 4
Thread: add a logo in header
- 09-22-2015, 09:19 AM #1
add a logo in header
hi,
can any body please help me to add a logo in header of docx.
Java Code:public static void main(String[] args) { try { //XWPFDocument docx = new XWPFDocument(); CustomXWPFDocument docx = new CustomXWPFDocument(); CTSectPr sectPr = docx.getDocument().getBody().addNewSectPr(); XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(docx, sectPr); File imgFile = new File("D:\\test.jpg"); //write header content CTP ctpHeader = CTP.Factory.newInstance(); CTR ctrHeader = ctpHeader.addNewR(); CTText ctHeader = ctrHeader.addNewT(); String headerText = "This is header"; ctHeader.setStringValue(headerText); XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, docx); headerParagraph.setAlignment(ParagraphAlignment.CENTER); XWPFParagraph[] parsHeader = new XWPFParagraph[1]; String blipId = headerParagraph.getDocument().addPictureData( new FileInputStream(imgFile), Document.PICTURE_TYPE_JPEG); docx.createPicture(blipId, docx.getNextPicNameNumber(Document.PICTURE_TYPE_JPEG), 252, 200); parsHeader[0] = headerParagraph; policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader); //write footer content CTP ctpFooter = CTP.Factory.newInstance(); CTR ctrFooter = ctpFooter.addNewR(); CTText ctFooter = ctrFooter.addNewT(); String footerText = "This is footer"; ctFooter.setStringValue(footerText); XWPFParagraph footerParagraph = new XWPFParagraph(ctpFooter, docx); XWPFParagraph[] parsFooter = new XWPFParagraph[1]; parsFooter[0] = footerParagraph; policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter); //write body content XWPFParagraph bodyParagraph = docx.createParagraph(); bodyParagraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun r = bodyParagraph.createRun(); r.setBold(true); r.setText("This is body content."); FileOutputStream out = new FileOutputStream("D:/a/test.docx"); docx.write(out); out.close(); System.out.println("Done"); } catch (Exception ex) { ex.printStackTrace(); } }
please help me
thanks in advance
- 09-22-2015, 09:20 AM #2
Re: add a logo in header
Java Code:public class CustomXWPFDocument extends XWPFDocument { public CustomXWPFDocument() { super(); } public CustomXWPFDocument(InputStream in) throws IOException { super(in); } public void createPicture(String blipId,int id, int width, int height) { final int EMU = 9525; width *= EMU; height *= EMU; //String blipId = getAllPictures().get(id).getPackageRelationship().getId(); CTInline inline = createParagraph().createRun().getCTR().addNewDrawing().addNewInline(); String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:nvPicPr>" + " <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + " <a:stretch>" + " <a:fillRect/>" + " </a:stretch>" + " </pic:blipFill>" + " <pic:spPr>" + " <a:xfrm>" + " <a:off x=\"0\" y=\"0\"/>" + " <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + " </a:xfrm>" + " <a:prstGeom prst=\"rect\">" + " <a:avLst/>" + " </a:prstGeom>" + " </pic:spPr>" + " </pic:pic>" + " </a:graphicData>" + "</a:graphic>"; //CTGraphicalObjectData graphicData = inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; try { xmlToken = XmlToken.Factory.parse(picXml); } catch(XmlException xe) { xe.printStackTrace(); } inline.set(xmlToken); //graphicData.set(xmlToken); inline.setDistT(0); inline.setDistB(0); inline.setDistL(0); inline.setDistR(0); CTPositiveSize2D extent = inline.addNewExtent(); extent.setCx(width); extent.setCy(height); CTNonVisualDrawingProps docPr = inline.addNewDocPr(); docPr.setId(id); docPr.setName("Picture " + id); docPr.setDescr("Generated"); } }
- 01-05-2016, 06:29 AM #3
Member
- Join Date
- Jan 2016
- Posts
- 4
- Rep Power
- 0
Re: add a logo in header
hey,I am sharing a code try this out:
<div id="header-image">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
<img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Logo" width="HERE" height="HERE" />
</a>
</div>
- 01-06-2016, 02:33 PM #4
Re: add a logo in header
"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
Similar Threads
-
Pascal header into java header ?
By fredvs in forum New To JavaReplies: 0Last Post: 03-01-2014, 12:18 AM -
Legal to use the Java Logo?
By developjava in forum Forum LobbyReplies: 2Last Post: 06-02-2012, 09:16 PM -
I need help with putting a logo on my code
By MikeJ39 in forum New To JavaReplies: 13Last Post: 10-22-2011, 02:10 AM -
setting application logo to tab
By sameerk in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 10-29-2010, 12:36 PM -
Adding Logo to my project
By ibrahimyoussof in forum New To JavaReplies: 0Last Post: 04-14-2010, 11:56 AM
Bookmarks