-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab character is not visible in the PDF generated as glyph substitution not working #454
Comments
@asturio @PallaviSaini This issue is caused by that when we use \t, PdfChunk will change font to font-fallback/LiberationSans-Regular.ttf. But this font can not support \t, when it meet \t in bytesArray it will ignore it and don't encode it. So my solution is that when we use \t, use default font which actually support \t. OpenPDF/openpdf/src/main/java/com/lowagie/text/pdf/PdfChunk.java Lines 212 to 224 in bff6520
\t not in the matrix:
I have fix it solution. In the futher, I will study how to let other fonts to encode \t and give a better solution. Test Code: public class TabTest {
public static void main(String[] args) throws FileNotFoundException, DocumentException {
Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
Document.compress = false;
try {
PdfWriter.getInstance(document,
new FileOutputStream("TabsTable.pdf"));
document.open();
Chunk a = new Chunk("data\\ttable");
a.setFont(new Font(BaseFont.createFont("font-fallback/LiberationSans-Regular.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED)));
document.add(a);
} catch (Exception de) {
de.printStackTrace();
}
document.close();
}
} |
Thanks for the contribution! |
Bug
Tab character is not visible in the PDF generated.
This is due to glyph substitutions are not done for tab character as per the TTF file.
Below is link to typography specs:
https://docs.microsoft.com/en-us/typography/opentype/spec/gsub
Below is code to Reproduce
package test;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import fr.opensagres.xdocreport.core.XDocReportException;
import fr.opensagres.xdocreport.document.IXDocReport;
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
/**
*
*/
public class OpenPdf {
}
Expected behavior
The text should be visible as "Raj Vihar" instead of "RajVihar". The rendered text in PDF should have a tab character in it.
Screenshot of current behaviour
System:
The text was updated successfully, but these errors were encountered: