2015-11-13 35 views
1

我仍然是C#中的初學者,我想知道是否有使用iTextSharp編寫斯拉夫語字母的選項(PDF格式,ć,š,ž)。我正在閱讀關於它的其他文章,但我無法將他們的解決方案應用於我的問題,也許作爲初學者有點複雜。這是我的代碼:iTextSharp中的克羅地亞字母

SaveFileDialog pdfFile = new SaveFileDialog(); 
pdfFile.Filter = "PDF|*.pdf"; 
pdfFile.Title = "Spremi PDF"; 
pdfFile.FileName = "Ispit"; 
if (pdfFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
{ 
    Document document = new Document(iTextSharp.text.PageSize.LETTER, 25, 25, 35, 35); 
    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName, FileMode.Create)); 
    document.Open(); 

    foreach (List<string> question in questions) 
    { 
      document.NewPage(); 
      foreach (string field in question) 
      { 
       document.Add(new Paragraph(field)); 
      } 
    } 

    document.Close(); 
} 

此代碼也許是簡單的,也許有一個很多更好的方法來做到這一點,但是這是我在C#代碼第一個。

+0

究竟是什麼,你看見了什麼?添加新段落時添加錯誤信息,或添加錯誤字符或...? –

+0

添加到pdf文本沒有這些字母 – PeMaCN

+4

捷克此出(沒有雙關語意):http://stackoverflow.com/questions/26631815/cant-get-czech-characters-while-generating-a-pdf 雖然捷克Croation的解決方案應該是類似的。 –

回答

1

我已經解決了我的問題。這是幫助我的代碼:

BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, false); 
Font titleFont = new Font(bf,20); 
Font infoFont = new Font(bf,16); 

謝謝大家

+0

不幸的是,它不適用於Xamarin.Android。 – mrisek

+0

@mrisek試試這個:https://developer.xamarin.com/guides/android/advanced_topics/localization/ – PeMaCN

+0

其實,你的代碼工作得很好。問題是Google Drive PDF查看器不支持克羅地亞字符。當我用Adobe Acrobat等其他應用程序打開相同的文件時,所有符號都存在。 – mrisek

相關問題