Display In Wps
apperently it all display in single page .
when convert to pdf , it turns to double page .
what is the best practoce to fix it ?
following is the origin file .
695200843888066560.docx (67.4 KB)
env is :
jdk:17
aspose : 23.9
thanks for aspose community .
@pengpengon
Could you please provide more details about the specific issues you are facing with the header and footer formatting after conversion? Additionally, what method are you using to convert the document to PDF?
here what method i used to convert docx into pdf ;
@pengpengon
Looks like the query is related to Aspose.Words. We are moving it to the respective category where you will be assisted accordingly.
@pengpengon The problem is not reproducible on my side using the latest 25.3 version of Aspose.Words for Java and the following simple code:
Document doc = new Document("C:\\Temp\\in.docx");
doc.save("C:\\Temp\\out.pdf");
out.pdf (103.6 KB)
Most likely the problem on your side occurs because the fonts used in your document are not available in the environment where the document is converted to PDF. If Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
The following articles can be useful for you:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
i tried same code in windows and ubuntu , but could not get the same effect like yours ,so it may be lack of some fonts ?
@Test
@SneakyThrows
public void tranPdf2() {
Document doc = new Document("C:\\Temp\\test.docx");
doc.save("C:\\Temp\\out2.pdf");
}
out2.pdf (126.2 KB)
@alexey.noskov
if it is lack of fonts , but both in windows and ubuntu are lacked. what should i do that find the lacked fonts ?
And i tried use
You can implement IWarningCallback to get a notification when font substitution is performed.
public void tranPdf() {
//AsposeAccessor.InitialAccessor();
var classResource = new ClassPathResource("test.docx");
Document doc = new Document(classResource.getInputStream());
HandleDocumentSubstitutionWarnings substitutionWarningHandler = new HandleDocumentSubstitutionWarnings();
// Set a default font name and enable font substitution.
FontSettings fontSettings = new FontSettings();
fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(true);
doc.setFontSettings(fontSettings);
FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
doc.setWarningCallback(callback);
doc.setWarningCallback(substitutionWarningHandler);
doc.save("C:\\Temp\\out.pdf");
Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();
while (warnings.hasNext())
System.out.println(warnings.next().getDescription());
}
public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
///
/// Called every time a warning occurs during loading/saving.
///
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
FontWarnings.warning(info);
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
private static class FontSubstitutionWarningCollector implements IWarningCallback {
///
/// Called every time a warning occurs during loading/saving.
///
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION){
FontSubstitutionWarnings.warning(info);
log.info("FontSubstitutionWarnings :{}", JSON.toJSONString(FontSubstitutionWarnings));
}
}
public WarningInfoCollection FontSubstitutionWarnings = new WarningInfoCollection();
}
but i got nothing. no fonts warning display.
I also tried the latest words version 25.3 but in same .
@alexey.noskov Thanks for you answer , i got the point , that when i unpack the document and find that the abnormal font Times New Roman Bold
, it should be Times New Roman
, withoud Bold . i don’t know how it produced but when i modify font type to correct format , all things are solved.
@pengpengon It is perfect that you managed to detect the problem. But as I have mentioned the problem is not reproducible on my side. As I can see the provided output PDF was produced by Aspose.Words in evaluation mode. In evaluation mode Aspose.Words injects evaluation notes into the document, they might push the content down as in your case.
yeah ,the root is that Times New Roman Bold , so is there any way to change this as Times New Roman ?
<w:font w:name="Times New Roman Bold">
<w:panose1 w:val="02020803070505020304"/>
<w:charset w:val="00"/>
<w:family w:val="roman"/>
<w:notTrueType/>
<w:pitch w:val="default"/>
<w:sig w:usb0="00000003" w:usb1="00000000" w:usb2="00000000" w:usb3="00000000" w:csb0="00000001" w:csb1="00000000"/>
</w:font>
@pengpengon You can get/set this value using Font.Name
property.
okay , i see in your environment is ok , may be there is no Times New Roman Bold.ttf
font on my computer , could your please provide one for test . I am confusing about Times New Roman
and Times New Roman Bold
, not sure which one should be installed (actually , ```Times New Roman is already installed but still prompt lacked of fonts in WPS on computer )so both is ok , i 'll install both in your way .
Plan not to modify the document , On your envirment it is fine , there must be some fonts not installed on my computer . I think that Install them is the least costly solution.
C:\Windows\Fonts\timesbd.ttf this is Times New Roman Bold
path on my computer ,.
out2.docx (60.3 KB)
I fiexd lacked of Times New Roman Bold by modify style , but still in wrong format, could you please try again this file ?
@pengpengon The problem is not reproducible on my side. Here are output document produced by
MS Word: ms.pdf (185.7 KB)
Aspose.Words: out.pdf (103.6 KB)
our payment version is 23.9(our environment can not use latest words version without watermarks) , so the latest version may solved this ? could you please use 23.9 try again ? if it is same as my ,we will consider upgrade payment version plan .
@pengpengon Yes, the problem is reproducible with 23.9 version of Aspose.Words: out_23.9.pdf (104.2 KB)
So to resolve the problem, it is required to update to the latest version.
Is there any trial key for latest version 25.9 ( if there is please post to pengpeng_on@163.com) , i 'll test it locally (our current payment version 23.9 can not use in 25.9 and i tried without license ,but the watermarks would impact final display ) if it worked ,we 'll start a payment for latest version (how to start a upgrade payment order?).
@pengpengon Sure, if you would like to test new version of Aspose.Words without evaluation version limitations, you can request a free 30-days temporary license .