Here's a code to convert docx to pdf
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toPDF(wordMLPackage, baos);
The problem here is that the generated PDF font is always Times New Roman, which is not the case, the docx template font is actually different, Garamond.
What could be missing or wrong here?
If a font is not installed on the system or embedded in the document, MS Word performs a silent font substitution. To check whether this is happening for your document, open it in Word, go to Word Options > Advanced > Show Document Content and press the Font Substitution button. (Word 2007)
If the font is embedded in the document, or you already have the font installed on your system, then I do not know what to tell you because ideally docx4j should use that font.
If that isn't the case, i.e. Word is using font substitution (which you can determine using the steps above), you can embed the Garmond font in the document using Word Options > Save > Embed Fonts in File. Run through your conversion program and check again.
Related
Using Primefaces 6.0 and
JAVA 1.8
Using below code to view the PDF document using DefaultStreamedContent.
<pe:documentViewer locale="en" height="600" value="#{documentMBean.pdfFile}" id="pdfDocViewer" >
Below code to get the Stream as pdfFile.
byte[] documentData = null;
setPdfFile(new DefaultStreamedContent());
documentData =//Getting the byte array from DB
getPdfFile().setStream(new ByteArrayInputStream(documentData));
getPdfFile().setContentType("application/pdf");
getPdfFile().setContentEncoding("UTF-8");
When I upload and store a PDF file which contents Chineese charactes getting below exception in PDF Viewer.
PDF.js v1.0.21 (build: f954cde) Message: InvalidPDFException
Note: Plain text PDF which contents English characters working fine and able to view the PDF.
I have tried to set different character-encoding such as UTF-8,UTF-16
Please assist me how to resolve above exception. Where I can find PDF.js for further analysis ?
I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
The code I use to export is:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?
Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
Is my font embedded so that if I share the pdf also computers not having this font can display the content?
How can I ensure this is JasperReport?
The deprecated method was to set attributes on the textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.
How to generate font extension .jar using iReport or JasperSoft Studio.
EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.
I have String which contains some html tags and it is coming from database, i want to write that in PDF file with same styling present in the String in the form of HTML tag. I tried to use XMLWorkerHelper like this
String html = What is the equation of the line passing through the
point (2,-3) and making an angle of -45<sup>2</sup> with the positive
X-axis?
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new
StringReader(html));
but it only reads the data which is inside the html tag(in this case only 2) other string it simply ignores. But i want the entire String with HTML formating.
With HTMLWorker it works perfectly but that is deprecated so please let me know how to achieve this.
I am using iText 5 lib
I am trying to convert html to pdf using aspose,also i have to use PageSize A1,A2,A3,A4 .this is worked perfectly..but i dont want set pagesize for pdf generation.So far i have tried below code
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
htmloptions.getPageInfo().setWidth(PageSize.getA2().getWidth());
htmloptions.getPageInfo().setHeight(PageSize.getA2().getHeight());
// Load HTML file
Document doc = new Document(basePath + "400010_DOC002_L_10_2508016.html", htmloptions);
// Save HTML file
doc.save("D:/Web+URL_output.pdf");
Can anyone suggest with out set page size i have convert html to pdf conversion ? or else please let me know what tools are available for this. Please let me know any other tools for this conversion.
#Shankar, you may use the below code sample in order to convert an HTML file to a PDF file without setting page size. By default, the page size of the rendered PDF file will be as of the A4 page size.
Simply omit the code which is setting a page size, else remains the same.
HtmlLoadOptions htmloptions = new HtmlLoadOptions(basePath);
// Load HTML file
Document doc = new Document(basePath + "400010_DOC002_L_10_2508016.html", htmloptions);
// Save HTML file
doc.save("D:/Web+URL_output.pdf");
Please let us know if you need any further assistance. I work with Aspose as Developer Evangelist.
I would like to get a JEditorPane to display RTF images like microsoft wordpad. I have a simple program I got from an example off of the web. I created a demo file in wordpad with all of the styles wordpad supports. Strikethrough, super-script, sub-script and highlight are not being read or displayed when reading the file. Highlight would be nice other than that I don't really need the others. The part that is critical is the images in the RTF, they show in wordpad but on in java. I am using:
RTFEditorKit rtf = new RTFEditorKit();
JEditorPane editor = new JEditorPane();
editor.setEditorKit(rtf);
rtf.read(fi, editor.getDocument(), 0);
If RTFEditorKit cannot support images is there a editor kit that can? I can't be the only person to try to get an RTF to work properly. I cannot use an HTML editor kit because I need the images to be embeded like the RTF format.