I want to display one word of chinese characters in PDF along with english characters. Currently chinese characters are not getting displayed in PDF.I have used itextsharp to generate pdf with contents.I have tried some chinese fonts but not working. How to show chinese characters along with english characters in PDF using itextsharp?
var docIndex = new Document(new Rectangle(792, 612));
var writer = PdfWriter.GetInstance(docIndex, new FileStream(Server.MapPath("~") + "/pdf/Project-" + report.pulledId + currentTime + ".pdf", FileMode.Create));
docIndex.Open();
FontFactory.Register("c:/windows/fonts/msmincho.ttc");
StyleSheet style = new StyleSheet();
style.LoadTagStyle("body", "face", "songti");
style.LoadTagStyle("body", "encoding", BaseFont.IDENTITY_H);
foreach (var elementIndex in HTMLWorker.ParseToList(
new StringReader(sbsample.ToString()), style))
{
docIndex.Add(elementIndex);
}
docIndex.Close();
Related
I am going to change the font color of the specific character instead of the whole paragraph on the MS document.
I'd like to do this in C#.
Now I can change the font color of the whole paragraph using DOCX library, but not able to change the character.
Looking to hearing any help.
In the examples of this Library you have this code:
// Insert a Paragraph into this document.
var p = document.InsertParagraph();
// Append some text and add formatting.
p.Append( "This is an " ).Font( new Font( "Arial" )).Color(Color.Black)
.Append( " E" ).Font( new Font( "Arial" )).Color( Color.Blue )
.Append( " xample." ).Font( new Font( "Arial" )).Color( Color.Black);
In a paragraph you are able to add and format any kind of text. If you want to change the format of a letter, you need to add a letter + the format. This code will be displaying "This is an Example" and the letter "E" will be blue.
I am trying to align to center a paragraph but is not having any affection on the paragraph.I am using OpenXml. Below is the code:
//paragraph properties
ParagraphProperties User_heading_pPr = new ParagraphProperties();
//trying to align center a paragraph
Justification justification1 = new Justification() { Val = JustificationValues.Center };
// build paragraph piece by piece
Text text = new Text(DateTime.Now.ToString() + " , ");
Text text1 = new Text(gjenerimi + " , ");
Text text2 = new Text(merreshifren());
var run = new Run();
run.Append(text,text1,text2);
Paragraph newParagraph = new Paragraph(run);
User_heading_pPr.Append(justification1);
newParagraph.Append(User_heading_pPr);
Here is how I am trying to align center the paragraph.
Reverse the order in which you assign text and paragraph properties:
User_heading_pPr.Append(justification1);
Paragraph newParagraph = new Paragraph(User_heading_pPr);
newParagraph.Append(run);
In valid and well-formed Word Open XML the paragraph properties must precede the run. So you have to build the Open XML document the same way.
This is a bit different than object models, the way we're typically used to dealing with them - the order does matter!
This question already has an answer here:
Rupee symbol is not showing in android
(1 answer)
Closed 5 years ago.
How can I insert this currency symbol: "₡" to pdf, using itextSharp 5.5.10?
this is what I have:
string fontpath = "C:\\Users\\PC\\Desktop\\";
var font = BaseFont.CreateFont(fontpath + "arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font fontArial = new iTextSharp.text.Font(font, 8);
string Colones = new Chunk("\u20A1", fontArial).ToString();
I am able to get the symbol but. When I want to insert the symbol in the pdf, it does not work.
I do it like this:
table2.AddCell(new PdfPCell(new Paragraph(Colones+" "+Subtotal)));
I don't know what I am doing wrong.
Thanks in advance.
I think this might be a font problem. If iText detects that the font you're using (Arial in this case) can not render that symbol, it will not insert the glyph in the content.
Creating a simple example
PdfWriter writer = new PdfWriter("C:\\CurrencySymbol.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document doc = new Document(pdf);
doc.add(new Paragraph("AB₡DEF"));
doc.flush();
doc.close();
yields the same problem. The resulting pdf only contains the text "ABDEF".
Try switching the font.
I have a problem with umlauts on characters when using openxml. Every char in the string is in Arial, but the ä is in Calibri. I really dont know why.
Can someone help me?
this is my code:
DocumentFormat.OpenXml.Wordprocessing.Run run = new DocumentFormat.OpenXml.Wordprocessing.Run();
RunProperties runProp = new RunProperties(); // Create run properties.
RunFonts runFont = new RunFonts(); // Create font
runFont.Ascii = "Arial"; // Specify font family
runProp.Append(runFont);
run.Append(runProp);
run.Append(new Text("Kapazität"));
You need to specify the HighAnsi property of the RunFonts object.
runFont.HighAnsi = "Arial";
As you would expect, Ascii font designation only accounts for ASCII characters (and a very short range of Unicode U+0000-U+007F). The umlaut characters are in the "extended" unicode range, and HighAnsi is responsible for most of that character set.
I'm trying to print an pdf with chinese characters using RazorPdf.
I've already try to create the font "STSong-Light with the enconding "UniGB-UCS2-H".
http://stderr.org/doc/libitext-java-doc/www/tutorial/ch09.html
http://www.codeproject.com/Articles/196019/Display-Chinese-Characters-in-PDF-created-by-iText
My Code:
string fontpath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\Content\\fonts\\stsong.ttf";
BaseFont baseFT = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//BaseFont baseFT = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
Am I missing anything?
Thanks in advance and regards.