为有中文需求的客户提供多渠道中文技术支持.

Fri Jun 19, 2020 2:50 am

hello:


需求:查看官网的 doc java 能够进行图片插入,但具体位置不知如何控制

参考code如下:
Code: Select all
  //Create a Document object
            Document doc = new Document();
            doc.loadFromStream(sourceFile.getInputStream(),FileFormat.Auto);
            //Add a section

            Section section = doc.addSection();

            //Add a paragraph to the section

            //Add another paragraph to the section
            Paragraph paragraph2 = section.addParagraph();
            //Append an image from local file to the paragraph
            DocPicture picture = paragraph2.appendPicture("C:\\Users\\Administrator\\Desktop\\sign.png");
            //Set image width
            picture.setWidth(50f);
            //Set image height
            picture.setHeight(50f);

            //Set horizontal alignment for paragraph 1 and paragraph 2
            paragraph2.getFormat().setHorizontalAlignment(HorizontalAlignment.Right);
            //Save the Document object
            doc.saveToFile("C:\\InsertImage.docx", FileFormat.Docx_2010);



目标:需要具体api实现或demo :D :D :D

bruce.shuai
 
Posts: 2
Joined: Thu Jun 18, 2020 11:46 am

Fri Jun 19, 2020 6:54 am

您好,

感谢您的咨询。
我们的Spire.Doc for Java 是基于Microsoft Word的。而Word文档本质上是流文档,它的内部数据没有“页”的相关信息,也就是说没有页的概念,所以无法在每页的底部插入图片。
对于您的需求,只能通过给页脚插入图片来实现。请参考附件的代码,如果还有问题,请提供您想要的结果给我们做进一步调查,谢谢!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Sat Jun 20, 2020 3:03 am

非常感谢~!
没有想到回复这么快速,我以为石沉大海!已经种草了

另外有几个问题还是需要咨询下:
1.采用您给到的代码后签名会在最左边,同时由于文字嵌套模式设置原因,会遮盖,并未追加在原有格式后; 目前采用Center居中处理,是否有更好的解决方式?

2.另外目前只看到中文站点上有在线编辑的功能开放,看了下目前市面上永中、i Doc View 、ali cloud api 都支持预览但没有入门版API,不知道iceblue是否提供在线预览,会受到欢迎的!

bruce.shuai
 
Posts: 2
Joined: Thu Jun 18, 2020 11:46 am

Mon Jun 22, 2020 5:41 am

您好,

感谢您的回应,以下是我对您问题的答复。
1、您可以在设置文字环绕方式后,再设置图片的水平方向上的位置,如下所示。如果还有问题,请提供您期望得到的结果文档给我们参考。
Code: Select all
        //添加图片
        DocPicture picture = footerParagraph.appendPicture("img.png");
        picture.setWidth(50f);
        picture.setHeight(50f);
        //设置文字环绕方式
        picture.setTextWrappingStyle(TextWrappingStyle.Through);
        //设置水平位置
        picture.setHorizontalPosition(120);

2、我们的云产品是支持在线预览文档的,详见:快速接入。如果您还有别的疑问,请随时联系我们。

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to 中文技术支持