Aspose.words Java-based template generation of Word looping pictures

Source: Internet
Author: User

1. Create a new Word document

2. Bookmark the place where the picture is inserted

3, setting bookmarks

Second, the project

1, 2-Step introduction dependencies and loading authorization files in the previous article

3. Get the picture path inserted into Word and generate a new Word document

In a new document, two pictures are displayed per line

 Public Static voidMain (string[] args)throwsException {//Verify License        if(!Getlicense ()) {            return; }        //Template WordString template = "E:\\test\\temp.docx"; //Target WordString DestDoc = "E:\\test\\edit.docx"; //defining the Document interfaceDocument doc =NewDocument (template); //Picture PathList<string> pathList =NewArraylist<>(); Pathlist.add ("E:\\test\\image1.jpg"); Pathlist.add ("E:\\test\\image2.jpg"); Pathlist.add ("E:\\test\\image3.jpg"); Pathlist.add ("E:\\test\\image4.jpg"); Pathlist.add ("E:\\test\\image5.jpg"); Documentbuilder Builder=NewDocumentbuilder (DOC);
Navigates to the specified position Builder.movetobookmark ("Pics"); DoubleLength =pathlist.size (); for(inti = 0; I < Math.ceil (length/2.0); i++){ for(intj = 0; J < 2; J + +){ intindex = i*2 +J; if(Index <pathlist.size ()) { if(i = = 0){ if(j = = 0) {builder.insertimage (Pathlist.get (index), Relativeverticalposition.margin,1, relativehorizontalposition.margin,130,200,220, Wraptype.inline); }Else{builder.insertimage (pathlist.get (index), Relativeverticalposition.margin,230,relativehorizontalposition.margin,130,200,220, Wraptype.inline); } }Else { if(j = = 0) {builder.insertimage (Pathlist.get (index), Relativeverticalposition.margin,1,relativehorizontalposition.margin, (130+220*i+10*i), 200,220, Wraptype.inline); }Else{builder.insertimage (pathlist.get (index), Relativeverticalposition.margin,230,relativehorizontalposition.margin, (130+220*i+10*i), 200,220, Wraptype.inline); }}} builder.write (" "); } Builder.writeln (); } //Calling InterfaceDoc.save (DestDoc); System.out.println (Complete); }

Aspose.words Java-based template generation of Word looping pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.