Description:
I've encountered a problem that a chinese character (胸) displays normally in html with 'SourceHanSansSC-Medium.otf' font but printed in a quite strange position while the html is printed by pdf reactor service.
If i replace it with SourceHanSansSC-Norml.otf, then both the html preview and the generated pdf by pdf-reacor are going well, only the SourceHanSansSC-Medium.otf useage will lead to this issue.
My environment :
- System: Mac os 10.12.6, Java 8 Pdf reactor version: 10.0.
Preparation:
I pulled the pdf reactor image from docker hub and run it as a local docker container, that my app could visit it by http://localhost:9423/service/rest.
I write an very simple html contains the the error character in both SourceHanSansSC-Medium.otf and SourceHanSansSC-Medium.otf, just to compare the result of two fonts. They both display correctly in html preview, and only the medium font character would be printed in an incorrect position.
I mapped my html local parent path to pdf-reactor /ro/config to ensure the pdf-reactor is able to get the html to print.
HTML code:
This is My html code 'print_sc_font.html' (I attached the html the fonts in a zip):
<html>
<head>
<style type="text/css">
@font-face {
font-family: shssc-normal;
src: url("./SourceHanSansSC-Normal.otf");
}
@font-face {
font-family: shssc-medium;
src: url("./SourceHanSansSC-Medium.otf");
}
</style>
</head>
<body>
<div style="font-family: shssc-normal;">Print by SC Normal Font: 肺癌</div>
<div style="font-family: shssc-medium;">Print by SC Medium Font: 肺癌</div>
</body>
</html>
Html Preview is ok
Java Print Code (PdfReactorTest.java):
package com.gc.dev;
import com.realobjects.pdfreactor.webservice.client.Configuration;
import com.realobjects.pdfreactor.webservice.client.PDFreactor;
import com.realobjects.pdfreactor.webservice.client.PDFreactorWebserviceException;
import com.realobjects.pdfreactor.webservice.client.Result;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PDFReactorTest {
public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String timeStamp = dateFormat.format(date);
// Create new PDFreactor instance
PDFreactor pdfReactor = new PDFreactor("http://localhost:9423/service/rest");
// Create a new configuration object
Configuration config = new Configuration()
// Specify the input document for Mac systems (adapt path if necessary) .setDocument("file:///ro/config/html/test/print_sc_font.html")
// Enable javaScriptSettings
.setJavaScriptMode(Configuration.JavaScriptMode.ENABLED)
// Set an appropriate log level
.setLogLevel(Configuration.LogLevel.DEBUG)
// Sets the title of the created PDF
.setTitle("Demonstration of PDFreactor Java API")
// Sets the author of the created PDF
.setAuthor("Myself")
// Enables links in the PDF document.
.setAddLinks(true)
// Enable bookmarks in the PDF document
.setAddBookmarks(true)
// Set some viewer preferences
.setViewerPreferences(
Configuration.ViewerPreferences.FIT_WINDOW,
Configuration.ViewerPreferences.PAGE_MODE_USE_THUMBS)
// Add user style sheets
.setUserStyleSheets(
new Configuration.Resource().setContent("@page {" +
"@top-center {" +
"content: 'PDFreactor Java API demonstration';" +
"}" +
" @bottom-center {" +
"content: \"Created on " + timeStamp + "\";" +
"}" +
"}"),
new Configuration.Resource().setUri("common.css"));
FileOutputStream fos = null;
try {
// Render document and save result to result
Result result = pdfReactor.convert(config);
if (result != null) {
byte[] pdf = result.getDocument();
//Save the pdf at the desired location
fos = new FileOutputStream("result.pdf");
fos.write(pdf);
fos.close();
}
} catch (PDFreactorWebserviceException exception) {
Result result = exception.getResult();
System.err.println(result.getError());
} catch (Exception e) {
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
}
Result pdf:
I haved attach my code and screen snapshot.
the SourceHanSansSC-Normal.otf is too large to attach, so two font files SourceHanSansSC-Normal and SourceHanSansSC-Medium.otf could be downloaded from https://github.com/adobe-fonts/source-han-sans/tree/release/OTF/SimplifiedChinese,
We can replicate this behavior using your fonts. This is a known issue, which is reported as #7530 in our internal tracker. The issue appears to be that the font subset containing certain characters is not embedded properly. As a workaround, you could make sure the entire font is embedded by adding the property "-ro-font-embedding-type: all;" to the "@font-face" rule declaration for this font, e.g.: