Thanks for the advice but that it does not work for C# (ASP.NET).
In C # are only these four methods: XMLWorkerHelper.GetInstance().ParseXHtml(IElementHandler d, TextReader inp); XMLWorkerHelper.GetInstance().ParseXHtml(IElementHandler d, Stream inp, Encoding charset); XMLWorkerHelper.GetInstance().ParseXHtml(PdfWriter writer, Document doc, TextReader inp); XMLWorkerHelper.GetInstance().ParseXHtml(PdfWriter writer, Document doc, Stream inp, Stream inCssFile, Encoding charset); Example in attachment. Please advise me? Ajula ______________________________________________________________
Od: "1T3XT BVBA" <[email protected]> Komu: Post all your questions about iText here <[email protected]> Datum: 17.05.2012 09:55 Předmět: Re: [iText-questions] wrong Encoding On 16/05/2012 19:34, [email protected] wrote:Hi, please advice. I have text with czech characters like "Ččůřšě" but I can convert them to PDF document. Please advise me?Your example is wrong for many different reasons. This is a non-exhaustive list:1. you store special characters in your code, but: - are you sure your code is stored as UTF-8? - are you sure your compiler compiles the code as UTF-8? 2. you have special characters in your String, but: - you don't tell XML Worker which encoding to use 3. you have special characters in your String, but: - you don't specify a font that knows those characters. I've solved these problems with the example in attachment:1. I changed the special characters into \u010C\u010D\u016F\u0159\u0161\u011B which is safer. 2. I specified the CharSet when converting the String to bytes and when parsing the XML.3. I use arial, because when I use Helvetica, only the š can be rendered. ---------- ------------------------------------------------------------------------------ Live Security Virtual ConferenceExclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/---------- _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
UTF8.aspx
Description: XML document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using iTextSharp.tool.xml;
using iTextSharp.tool.xml.pipeline;
using iTextSharp.tool.xml.pipeline.html;
namespace test_02_Web {
public partial class UTF8 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void btnCreatePDF_Click(object sender, EventArgs e) {
var output = new MemoryStream();
string htmlString = "<html
xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body><h1>ÄÄžšýáůš</h1></body></html>";
using (Document document = new Document(PageSize.A4, 25, 25, 25,
25)) {
PdfWriter writer = PdfWriter.GetInstance(document, output);
document.Open();
try {
StringReader sr = new StringReader(htmlString);
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document,
sr);
}
catch (Exception ex) {
throw;
}
}
Response.Charset = "";
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition",
string.Format("attachment;filename=Faktura_{0}.pdf", "EXAMPLE"));
Response.BinaryWrite(output.ToArray());
}
}
}------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
