¿Está convirtiendo HTML a PDF? Si es así, debe tener en cuenta que, de lo contrario, no importa. La única razón por la que pregunto es que su último comentario sobre cómo obtener æ
me hace pensar eso. Si es así, consulte esta publicación: iTextSharp 5 polish character
Además, a veces, cuando las personas dicen "Unicode", lo que realmente están tratando de hacer es colocar símbolos como Wingdings en un PDF. Si quieres decir que echa un vistazo a esta publicación y sabes que Unicode y Wingding Symbols realmente no están relacionados en absoluto. Unicode symbols in iTextSharp
He aquí un ejemplo de trabajo completo que utiliza dos formas de escribir caracteres Unicode, uno que usa el carácter en sí y otro que usa la secuencia de escape C#. Asegúrese de guardar su archivo en un formato que admita caracteres anchos. Esta muestra usa iTextSharp 5.0.5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Create our document object
Document Doc = new Document(PageSize.LETTER);
//Create our file stream
using (FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
{
//Bind PDF writer to document and stream
PdfWriter writer = PdfWriter.GetInstance(Doc, fs);
//Open document for writing
Doc.Open();
//Add a page
Doc.NewPage();
//Full path to the Unicode Arial file
string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
//Create a base font object making sure to specify IDENTITY-H
BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//Create a specific font object
Font f = new Font(bf, 12, Font.NORMAL);
//Write some text, the last character is 0x0278 - LATIN SMALL LETTER PHI
Doc.Add(new Phrase("This is a test ɸ", f));
//Write some more text, the last character is 0x0682 - ARABIC LETTER HAH WITH TWO DOTS VERTICAL ABOVE
Doc.Add(new Phrase("Hello\u0682", f));
//Close the PDF
Doc.Close();
}
}
}
}
Cuando se trabaja con iTextSharp usted tiene que asegurarse de que usted está utilizando una fuente compatible con los puntos de código Unicode que desea utilizar. También necesita especificar IDENTITY-H
cuando usa su fuente. No sé por completo lo que significa, pero se habla de ello aquí: iTextSharp international text
¿Qué problemas estás viendo? Si le faltan caracteres, eche un vistazo aquí: http://stackoverflow.com/questions/1322303/html-to-pdf-some-characters-are-missing-itextsharp – Nick
Sí, los caracteres faltan en el pdf, pero tengo Ya visto y probado este enlace, cuando descargué el código fuente de itextsharp, no tenía el archivo 'FactorySettings.cs' en él. Y también, él está usando "arial.ttf", quiero caracteres UTF-8. – teenup
En realidad, el bloc de notas desde el que estaba buscando la cadena se guardó como código ANSI, cuando lo cambié como "UTF-8" codificado, ahora esos caracteres aparecen en pdf como 'æ'. – teenup