Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jun 23, 2022 6:36 am

hello, I'm sorry I'm not good at English, so I'm writing with a translator

I have purchased a license and am currently using it.

The version used is maven 5.4.2

When 3 word files are merged, the font size 10 text in the first file is converted to font size 11 and saved. There is no code related to font modification, but I want to know why.

The order of file merging is file 1 -> 2 -> 3

code is java

Code: Select all

                /**
       * 5.N개 문서들 하나로 병합
       */
       
       Document doc = listDocument.get(0);
       
       for(int i = 1 ; i < listDocument.size() ; i ++) {
          
          doc.getLastSection().setBreakCode(SectionBreakType.New_Page);
          
          ByteArrayOutputStream baos = new ByteArrayOutputStream();

          listDocument.get(i).saveToStream(baos, FileFormat.Docx);

         InputStream is = new ByteArrayInputStream(baos.toByteArray());

         doc.insertTextFromStream(is, FileFormat.Docx);

          
          
//         doc.importContent(listDocument.get(i), false);
       }
       
       doc.getLastSection().setBreakCode(SectionBreakType.New_Page);
       

      /**
       * 6.변환된 문서파일(docx , pdf) 임시폴더에 저장
       */
      String fileName = StringUtils.stripFilenameExtension(reqMultiBuild.getSaveFileName())+"_"+new Date().getTime();
      String filePath = path+File.separator+user.getPathTmpFile()+File.separator+fileName;
      log.info("save temp dir path :: {} ", filePath);
      
      //템프폴더 없으면 만들도록 추가
      Path fileDir = Paths.get(path+File.separator+user.getPathTmpFile());   
      
      if(!Files.exists(fileDir)) {
         
         File dir = new File(fileDir.toString());
         
         dir.mkdirs();
      }
      doc.isUpdateFields(true);

      doc.saveToFile(filePath+".docx", FileFormat.Docx); //docx 파일 저장


crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Thu Jun 23, 2022 8:20 am

Hello,

Thank you for your inquiry.

Please modify the loop and test again. Here is the code. If there is any other issue, just feel free to contact us.

Code: Select all
        for (int i = 1; i < listDocument.size(); i++) {

            /**doc.getLastSection().setBreakCode(SectionBreakType.New_Page);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            listDocument.get(i).saveToStream(baos, FileFormat.Docx);
            InputStream is = new ByteArrayInputStream(baos.toByteArray());
            doc.insertTextFromStream(is, FileFormat.Docx);*/
            Document tempDoc=listDocument.get(i);
            for(Object obj:tempDoc.getSections()){
                Section section= (Section) obj;
                doc.getSections().add(section.deepClone());
            }

//         doc.importContent(listDocument.get(i), false);
        }
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Jun 24, 2022 12:52 am

hello. If you run the code you posted, the font size problem disappears, but the line spacing of the 3rd document is displayed with an expanded size, so the existing 1 page document is stretched to 2 pages. I would appreciate it if you could tell me why the line spacing is changing

I will upload a screenshot of the document before conversion and a screenshot after conversion.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Fri Jun 24, 2022 3:02 am

Hi,

I did notice the issue of paragraph spacing and tried some other solutions but didn't work. I have logged these two problems(font size issue and paragraph spacing issue) in our bug tracking system with the ticket SPIREDOC-8031. We will inform you in time when there is any update about these issues. Sorry for the inconvenience caused.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Jun 24, 2022 4:06 am

hello. Thank you for taking care of the processing. We are waiting for the update.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Tue Jun 28, 2022 7:13 am

Hello,

Thanks for your patience.

I got the cause and a solution for this issue from our dev team. The reason for the problem is that when multiple documents are merged, if the same styles exists in multiple documents, only one is retained. So we lost some styles. And below is the solution. Please give it a try.

Code: Select all
        for (int i = 1; i < listDocument.size(); i++) {

            Document tempDoc=listDocument.get(i);
            //Keep the original styles/formats
            tempDoc.setKeepSameFormat(true);
            for(Object obj:tempDoc.getSections()){
                Section section= (Section) obj;
                doc.getSections().add(section.deepClone());
            }
        }
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Jun 29, 2022 8:06 am

Hello, As a result of testing with the answer code, there was no problem on the transmitted file, but a problem occurred when merging with other files.

The problem is that if you put a file with a larger font as the first file, the font is checked normally (result2 file), but if you merge the file after the f3 file, the font grows again (result1 file). A solution is needed.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Thu Jun 30, 2022 3:43 am

Hi,

Thanks for your feedback.

After swapping the order of the merged documents, as you said, this problem reappeared. After communicating with the developers, we need to improve the internal code of the setKeepSameFormat method. So we will continue to fix this issue.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Jun 30, 2022 4:34 am

Hi, please provide feedback when the issue is resolved. Thank you for your attention to function improvement

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Thu Jun 30, 2022 5:52 am

Yes sure. We will notify you in time when we finish the improvement.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Jul 15, 2022 2:09 am

Until when can it be resolved?
We have a fixed development period, so we need to revise it quickly.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Mon Jul 18, 2022 1:45 am

Hi,

Sorry for the late reply due to a power outage in our area last Friday.

We have initially completed a fix for this issue. It is currently in the testing phase. We will provide you with a fixed version as soon as the test passes.
Also, could you please tell us the latest time you can accept? If we are unable to release a new version by this time, we will provide you with a temporary fix pack to resolve this issue.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Aug 02, 2022 12:10 am

hello.
We ask if the bug we requested has been resolved in this java version update.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Tue Aug 02, 2022 6:49 am

Hi,

Sorry for the delay.

The issue is not resolved in this version. We've made a number of changes to the merging of character and paragraph styles, so it has many implications for other documents. This made the issue quite time consuming.
We have prepared a temporary version for you to resolve this issue. Please get it from the link below and refer to the following code for testing. If you have any other questions, please feel free to feedback.
Code: Select all
https://drive.google.com/file/d/1zHiXhmb3blz9so9DKL_d4rP2FHEw1bte/view?usp=sharing


Full test code:
Code: Select all
        String path="files/";
        List<Document> listDocument=new ArrayList<>();
        String []files={"f2.docx","f3.docx","f4.docx","f1.docx"};
        String []files2={"f3.docx","f2.docx","f4.docx","f1.docx"};

        for(String file:files2){
            Document document=new Document();
            document.loadFromFile(path+file);
            listDocument.add(document);
        }
        Document doc=listDocument.get(0);
        for (int i = 1; i < listDocument.size(); i++) {

            Document tempDoc=listDocument.get(i);
            //Keep the original styles/formats
            tempDoc.setKeepSameFormat(true);
            for(Object obj:tempDoc.getSections()){
                Section section= (Section) obj;
                doc.getSections().add(section.deepClone());
            }
            doc.getLastSection().setBreakCode(SectionBreakType.New_Page);
        }

        doc.isUpdateFields(true);
        //Files Order  f2-f3-f4-f1
        //doc.saveToFile(path+  "2-3-4-1.docx", FileFormat.Docx);
        //Files Order  f3-f2-f4-f1
        doc.saveToFile(path+  "3-2-4-1.docx", FileFormat.Docx);
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Fri Aug 05, 2022 1:22 am

hello.
When applied as a changed jar, the output is normal. thank you If there is a change in the maven version after fixing the bug in the future, please let me know.

crizen.solution
 
Posts: 14
Joined: Mon May 30, 2022 12:47 am

Return to Spire.Doc