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.
Related
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();
I have a problem. If I create a Paragraph by giving it the value of my string surname, I dont know, how to give this Paragraph style which comes after that into a PDF File with this -> document.Add(surnameValue);
Paragraph surnameValue = new Paragraph(surname);
You can add font like this in iTextSharp:
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
Font times = new Font(bfTimes, 12, Font.BOLD, Color.RED);
Paragraph testP = new Paragraph("This is a Red Font Test using Times Roman", times)
EDIT
Here Documentation about Font.
I'm working on a C# application and i'm using itextsharp(v5.5.2) to read pdf documents.
I have a problem to read some pdf files because the "PdfReader.NumberOfPages" attibute sometimes returns a wrong value.
i.e.: a document contains 18 pages(adobe reader) but the attribute "PdfReader.NumberOfPages" return 2.
When i try with this code(for testing) to get the text from a page by the page number
PdfReader reader = new PdfReader(fileInfo.FullName);
PdfReaderContentParser pdfReaderContentParser = new PdfReaderContentParser(reader);
ITextExtractionStrategy iTextExtractionStrategy = pdfReaderContentParser.ProcessContent(myPageNumber, new SimpleTextExtractionStrategy());
String pdfText = iTextExtractionStrategy.GetResultantText();
, I have the results:
if myPageNumber = 1 => return the text from the page 1
if myPageNumber = 2 => return the text from the page 8!!!
if myPageNumber = 3 => create an error as expected (the reader "see" only 2 pages)
I discovered a possible cause of this problem but i'm not sure of it: the type of the font type.
When I have "type1" in the document, i don't have problems. But i have the problem with the truetype font type.
I unfortunatly can't share the problematic pdf files.
Thank you for any assistance.
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.
Please refer my code where i am writing values on pdf. But i want to align numeric fields to the right.
Is there any property/method for that. I am using this property PdfFormField.MK_CAPTION_RIGHT but it is not working.
var pdfReader = new PdfReader(outputPath);
string fontsfolder1 = #"D:\ItextSharp\Fonts\acmesab.TTF";
var pdfStamper1 = new PdfStamper(pdfReader, new FileStream(outputPath3, FileMode.Create));
BaseFont customfont1 = BaseFont.CreateFont(fontsfolder, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
AcroFields af = pdfStamper1.AcroFields;
List<BaseFont> list1 = new List<BaseFont>();
list.Add(customfont1);
iTextSharp.text.Font bold1 = new iTextSharp.text.Font(customfont1, 6, 0, BaseColor.BLACK);
af.SubstitutionFonts = list;
foreach (var field1 in af.Fields)
{
af.SetFieldProperty(field1.Key, "textalignment", PdfFormField.MK_CAPTION_RIGHT, null);
af.SetField(field1.Key, "123");
}
pdfStamper1.FormFlattening = false;
pdfStamper1.Close();
I don't know how you can do this directly using ItextSharp Property.But one way is to add the spaces to the left of the content,to do this you can get the Field Length and based on that length and length of the content, you can calculate the spaces to be added to the left of the content.it will automatically put your content to the right side of the PDF field.hope this way can help you solve your problem...
You can align the text by using the ShowTextAligned method which takes an alignment parameter, like this:
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT,"Text is left aligned",200,800,0);
cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT,"Text is right aligned",200,788,0);
where cb is PdfContentByte
For Detail