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.

Sun Dec 19, 2021 1:58 pm

Hello
I have faced with problem during docx to pdf conversion - image can overlaps some of rows from previous table in small example bellow.
Code: Select all
LicenseProvider.setLicenseKey(licenseKey);
var document = new Document();
document.loadFromFile(sourcePath);
document.saveToFile(resultPath);

spire.doc Java version 4.8.0
I have tried to set setAllowOverlap to false, but without any success.
Thx

truthSerruf
 
Posts: 13
Joined: Mon Feb 01, 2021 7:08 am

Mon Dec 20, 2021 7:46 am

Hello,

Thank you for your inquiry.
I tested your Word file with Spire.Doc for java 4.8.0 and the latest version (Spire.Doc for Java Version:4.12.7), but none of them reproduced your issue. For your situation,I suggest you first try again with the latest version(Spire.Doc for Java Version:4.12.7). If the issue still exists after trying, please provide the following information for our reference. Thanks in advance.
1) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
2) Your JDK version, such as 1.8.
In addition, we provide the PS method for converting Word to PDF. The sample code is as follows, please try it.
Code: Select all
Document document = new Document();
document.loadFromFile(sourcePath);
ToPdfParameterList ps = new ToPdfParameterList();
ps.setUsePSCoversion(true);
document.saveToFile(resultPath,ps);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 20, 2021 8:23 am

Hello Annika !
Unfortunately issue reproduced for 4.12.7 to.
1 My test environment: x86_64 x86_64 x86_64 GNU/Linux; Ubuntu 20.04.3 LTS; LANG=ru_RU.UTF-8
2
Code: Select all
import com.spire.doc.Document;
import com.spire.doc.ToPdfParameterList;
import com.spire.doc.documents.BreakType;
import com.spire.doc.fields.DocPicture;
import com.spire.license.LicenseProvider;

public class ConvertEx {

    public static String licenseKey = "";
    public static String sourcePath = "";
    public static String resultPath = "";

    public static void main(String[] args) {
        LicenseProvider.setLicenseKey(licenseKey);
        var document = new Document();
        document.loadFromFile(sourcePath);
        var ps = new ToPdfParameterList();
        ps.setUsePSCoversion(true);
        //my current workaround
//        var section = document.getSections().get(0);
//        var paragraph = section.getTables().get(1).getRows().get(0).getCells().get(0).getParagraphs().get(0);
//        var img = (DocPicture) paragraph.getChildObjects().get(0);
//        paragraph.getChildObjects().remove(img);
//        paragraph.appendBreak(BreakType.Line_Break);
//        paragraph.getChildObjects().insert(1, img);
        document.saveToFile(resultPath, ps);
    }
}

So it is just Java class with main

truthSerruf
 
Posts: 13
Joined: Mon Feb 01, 2021 7:08 am

Mon Dec 20, 2021 10:55 am

Hello,

Thank you for your feedback.
After investigation, we found that the Arial font was used in your source Word file, but this font was not used in the PDF file. Please use the following code to embed the Arial font into the PDF result file and tell us your test results. Looking forward to your test feedback.
Code: Select all
        String inputFile="";
        String fontFile="arial.ttf";
        String outputFile="";

        Document document = new Document();
        document.loadFromFile(inputFile);

        //embed the non-installed fonts.
        ToPdfParameterList parms = new ToPdfParameterList();
        List<PrivateFontPath> fonts = new ArrayList<PrivateFontPath>();
        fonts.add(new PrivateFontPath("Arial", fontFile));
        parms.setPrivateFontPaths(fonts);
        //save the document to a PDF file.
        document.saveToFile(outputFile, parms);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 20, 2021 11:45 am

With Arial font result looks better, but the main problem - image overlapping last row - still there
Logo overlaps «___»___________________2018 row
Image
Can see row only if it it selected
Image

truthSerruf
 
Posts: 13
Joined: Mon Feb 01, 2021 7:08 am

Tue Dec 21, 2021 2:12 am

Hello,

Thank you for your feedback.
I checked the PDF file you provided and found that the font "Arial" is still not embedded. I attached my jar package(WordToPDF.jar) and result file(result.pdf). Please test the jar package on your side.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 21, 2021 6:32 am

Now conversion result is fine, thanks a lot.
You are the best !
PS: suddenly it is possible to load font by inexistent path, like
Code: Select all
fonts.add(new PrivateFontPath("Arial", "inexistent_path"));

without any noticeable warning or errors. But maybee i miss the opportunity for something like debug mode ?

truthSerruf
 
Posts: 13
Joined: Mon Feb 01, 2021 7:08 am

Tue Dec 21, 2021 8:14 am

Hello,

Thank you for your feedback.
Glad to hear that your issue has been solved. If you have other questions about using Spire.Doc in the future, please feel free to contact us.
In addition, regarding the "load font by inexistent path" issue you mentioned, if the font does not exist or the font file path is incorrect, our Spire.Doc will use the default font, so the program will not report an error.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc