问题 - 在c#中打印其他语言 [英] problem-print other language in c#

查看:64
本文介绍了问题 - 在c#中打印其他语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi.i想以我的形式制作打印按钮,但目前无法正常工作。

当我使用像سلام这样的波斯文本打印程序时打印此 。

这是我的代码

---------------------------

私有StreamReader objStreamToPrint; 
private Font objPrintFont;

private void btnprint_Click(object sender,EventArgs e)
{

PrintDocument objPrintDocument = new PrintDocument();

objPrintDocument.DocumentName =文本文件打印演示;

printDialog1.AllowPrintToFile = false;
printDialog1.AllowSelection = false;
printDialog1.AllowSomePages = false;

printDialog1.Document = objPrintDocument;

if(printDialog1.ShowDialog()== DialogResult.OK)
{

objStreamToPrint = new StreamReader(as.txt);

objPrintFont = new Font(tahoma,10);

objPrintDocument.PrinterSettings = printDialog1.PrinterSettings;



objPrintDocument.PrintPage + = new PrintPageEventHandler(prtPage);

objPrintDocument.Print();

objStreamToPrint.Close();
objStreamToPrint = null;
}
}







private void prtPage(对象发送者,PrintPageEventArgs) e)
{

float sngLinesPerpage = 0;
float sngVerticalPosition = 0;
int intLineCount = 0;
float sngLeftMargin = e.MarginBounds.Left;
float sngTopMargin = e.MarginBounds.Top;
string strLine;

sngLinesPerpage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics);


strLine = objStreamToPrint.ReadLine();
while((intLineCount& lt; sngLinesPerpage)&&
(strLine!= null))
{

sngVerticalPosition = sngTopMargin +
(intLineCount * objPrintFont.GetHeight(e.Graphics));

e.Graphics.DrawString(strLine,objPrintFont,
Brushes.Black,sngLeftMargin,
sngVerticalPosition,
new StringFormat());

intLineCount = intLineCount + 1;

if(intLineCount& lt; sngLinesPerpage)
{
strLine = objStreamToPrint.ReadLine();
}
}

if(strLine!= null)
{
e.HasMorePages = true;
}
其他
{
e.HasMorePages = false;
}
}

解决方案

这意味着打印机只读取ASCII或其他有限的字符集而不是说UNICODE。



您需要更改字符集或将所有内容转换为图像才能正确打印。



多一点看,也有可能你可以做一些事情



 System.Globalization.CultureInfo 


hi.i want to make a print buttom in my form but not currently work.
when i use a persian text like سلام for printing the program print this ����.
this is my code
---------------------------

private StreamReader objStreamToPrint; 
        private Font objPrintFont;

        private void btnprint_Click(object sender, EventArgs e)
        {
            
PrintDocument objPrintDocument = new PrintDocument(); 

 objPrintDocument.DocumentName = "Text File Print Demo"; 

 printDialog1.AllowPrintToFile = false; 
 printDialog1.AllowSelection = false; 
 printDialog1.AllowSomePages = false; 

 printDialog1.Document = objPrintDocument; 

if(printDialog1.ShowDialog() == DialogResult.OK) 
 { 

     objStreamToPrint = new StreamReader("as.txt");
 
     objPrintFont = new Font("tahoma", 10);
  
  objPrintDocument.PrinterSettings = printDialog1.PrinterSettings; 

  

  objPrintDocument.PrintPage += new PrintPageEventHandler(prtPage); 
 
  objPrintDocument.Print(); 
 
  objStreamToPrint.Close(); 
  objStreamToPrint = null; 
 } 
        }







        private void prtPage(object sender, PrintPageEventArgs e) 
{ 
 
float sngLinesPerpage = 0; 
float sngVerticalPosition = 0; 
int intLineCount = 0; 
float sngLeftMargin = e.MarginBounds.Left; 
float sngTopMargin = e.MarginBounds.Top; 
string strLine; 
 
 sngLinesPerpage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics); 
 
 
 strLine = objStreamToPrint.ReadLine(); 
while((intLineCount < sngLinesPerpage) && 
  (strLine != null)) 
 { 
 
  sngVerticalPosition = sngTopMargin + 
 (intLineCount * objPrintFont.GetHeight(e.Graphics)); 

  e.Graphics.DrawString(strLine, objPrintFont, 
Brushes.Black, sngLeftMargin, 
      sngVerticalPosition, 
      new StringFormat()); 
 
  intLineCount = intLineCount + 1; 
 
if(intLineCount < sngLinesPerpage) 
  { 
   strLine = objStreamToPrint.ReadLine(); 
  } 
 } 
 
if(strLine != null) 
 { 
  e.HasMorePages = true; 
 } 
else 
 { 
  e.HasMorePages = false; 
 } 
}

解决方案

What it means is that the printer is only reading an ASCII or other limited character set instead of say UNICODE.

You will need to change the character set or convert everything to an image to print correctly.

A little more looking and it is also possible that you might be able to do something with

System.Globalization.CultureInfo


这篇关于问题 - 在c#中打印其他语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆