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