I try save text to pdf via http://code.google.com/p/droidtext/ . But I have problem with saving russian text. In created pdf I see all latin letters and symbols. But russian letters I don't see. If write text like: "dfыва-:", in pdf I see: "df-:". I use font which have russian letters. If somebody had same problem, help please.
Code:
Document doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("/sdcard/test.pdf");
doc.open();
BaseFont times = baseFont.createFont("/sdcard/test/TIMES.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
doc.add( new Paragraph("dfыва-:", new Font(times, 14) ) );
doc.close();
You need to set proper encoding.
This example will probably help you out.
Related
How i can diplay multiligual and mathamatical symbols in java itextpdf PDF?
I have tried arialuni.ttf in BaseFont,
But still Some Mathematical symbols are not shows in itextpdf.
Please help for this, I want exact text content accepted from web application wanted to show in itextpdf.
BaseFont bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Paragraph p = new Paragraph("Şinasi ıssız ile ağaç", new Font(bf, 22));
document.add(p);
I have the data containing emoji in database. I want to display in the generated document such as pdf or in excel format.
I am using spring boot application. Please suggest any java library for generating either PDF or excel which supports emoji.
iText supports this. Assuming
your emoji is a unicode character
you use a font that contains the correct glyph for this unicode character
Best way to test this is to try it.
This is how to get started with iText:
https://developers.itextpdf.com/content/itext-7-jump-start-tutorial/installing-itext-7
And this is a small code-snippet that adds text to a document with different fonts:
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
Text title =
new Text("The Strange Case of Dr. Jekyll and Mr. Hyde").setFont(bold);
Text author = new Text("Robert Louis Stevenson").setFont(font);
Paragraph p = new Paragraph().add(title).add(" by ").add(author);
document.add(p);
document.close();
For more information check out the tutorials.
https://developers.itextpdf.com/content/itext-7-building-blocks/chapter-1
I'm working with iText in java to write PDF files. I'm trying to write a paragraph like heading and then text start very after the heading in the same line like
Heading: this a para now ...
Heading is bold and para is in normal text but I'm unable to do this using iText. I tried to use:
fonts[2] = new Font(Font.HELVETICA, 8, Font.BOLD);
Paragraph paranumber = new Paragraph(
fonts[2].getCalculatedLeading(1),
headingText.trim()
+ " ", fonts[0]);
Paragraph para = new Paragraph(
fonts[0].getCalculatedLeading(1), contentText.trim(), fonts[0]);
para.setAlignment(Element.ALIGN_JUSTIFIED);
para.setSpacingAfter(3f);
//Now adding the para to paraNumber that is having the heading and expecting
//that it will be added very after the heading, but this does not show correct
//result, formatting issue.
paranumber.add(para);
mct.addElement(paranumber);
I also tried to create a new paragraph and added both paras(heading para and normal text para) to that new one, but that is also not showing proper result. please see below chunk for that.
Paragraph newPara = new Paragraph();
newPara.add(paranumber);
newPara.add(para);
but this also not show proper formatting.
Or if anyone can advise me to use some other way to create PDF from HTML that will be good too, so that i may rewrite the module to create required PDF. Please advise.
Paragraphs typically use concepts like indentation and increased leading to set them apart visually. They are block level elements, not inline.
It doesn't make sense to add a paragraph inside another paragraph. The added paragraph would typically start on a new line, essentially making it a separate paragraph anyway.
To get a paragraph with different fonts, like your example, you can use Chunks in iText. A Chunk is basically a piece of text with an associated font.
Font fontbold = new Font(BaseFont.createFont(BaseFont.HELVETICA_BOLD,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED), 12);
Font fontregular = new Font(BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED), 12);
Chunk header = new Chunk("Heading: ", fontbold);
Chunk content = new Chunk("this is a para now ...", fontregular);
Paragraph paragraph = new Paragraph();
paragraph.add(header);
paragraph.add(content);
document.add(paragraph);
The result looks like this:
It's not clear from your question and code sample how HTML is involved. I assume you are somehow parsing HTML input and converting the parsed content to PDF using iText Elements. This is a valid approach. Alternatively, you can look into iText XML Worker, which does XHTML (+CSS) to PDF conversion.
Hope someone can help me. It's about docx to pdf conversion having korean sign in docx document.
I'm able to convert a docx document to pdf with docx4j.
In pdf document, I can see the result. But if my docx document contains korean font, I can't see any korean font in my pdf document except the latin numbers.
What do I have to do to get korean font in my pdf from the docx document?
Here is my code:
File docXFile ="E:/contract2Files/test.docx";
WordprocessingMLPackage wordprocessingMLPackage = WordprocessingMLPackage.load(docXFile);
String out = docXFile .replace("docx","pdf");
File pdfFile = new File(out);
OutputStream pdfFileOs = new java.io.FileOutputStream(pdfFile);
org.docx4j.convert.out.pdf.PdfConversion c = new JanoPdfConversion(wordprocessingMLPackage);
c.output(pdfFileOs);
Please try http://www.docx4java.org/docx4j/docx4j-3_0-beta2.zip (link updated 15 Nov)
You might need to configure your font mapper, though things work out of the box with the Identity mapper on my Windows box, since I have the relevant font installed.
If this doesn't help, please put a sample docx somewhere StackOverflow users can see it.
thanks again. I tried the newest jar file with this code passage and it worked!!! Now I get the korean letters into pdf. Thank again.
ThemePart themePart =
wordprocessingMLPackage.getMainDocumentPart().getThemePart();
org.docx4j.dml.BaseStyles.FontScheme fontScheme = themePart.getFontScheme();
org.docx4j.dml.TextFont textFont = fontScheme.getMinorFont().getLatin();
textFont.setTypeface("Malgun Gothic");
I have to create report using itext but the language should be hindi or marathi.
Is it possible to make pdf file which contains marathi font like mangal,shruti,shree-dev...etc if yes plz reply me
Thank you!
Adding a marathi font in itext pdf is :
BaseFont kruti_Dev = BaseFont.createFont("c:/WINDOWS/Font/Kruti_Dev_010.ttf"
,BaseFont.CP1252,BaseFont.EMBEDDED);
Font font = new Font(kruti_Dev, 12, Font.NORMAL);
Try to use Aspose PDF Generator. Make request and response to utf-8.