Unable to view MICR font in print preview - c#

I have written a code to print a cheque using MICR font, every thing works fine but when coming to print preview I am getting normal text but while printing the document I am getting the required in MICR font. How can I show MICR font in print preview
This is my code
PrivateFontCollection PFC = new PrivateFontCollection();
PFC.AddFontFile(Server.MapPath("ADVMICR.TTF"));
FontFamily fm = new FontFamily(PFC.Families[0].Name, PFC);
Font PrintFont = new Font(fm, 12);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Specify the printer to use.
pd.PrinterSettings.PrinterName = "SnagIt 9";
PrintPreviewDialog ppdlg = new PrintPreviewDialog();
ppdlg.Document = pd;
ppdlg.ShowDialog();

Try this
ppdlg.PrintPreviewControl.Font = new Font("ADVMICR.TTF", 12);

Related

Printing from a preview (PrintPreviewDialog) without calling PrintPageEventHandler again, and recreating the PrintDocument

I'm certain I'm missing something here...
I create a PrintDocument (which is very time consuming 600-1200 pages), and then allow the user to preview it with PrintPreviewDialog.
However, when the user chooses to print the document (from the preview dialog) the print document gets created again. I just want the document that has been created, previewed, accepted by the user, to be printed. How do I print the created document directly?
The code is simply this...
PageSettings pageSettings = new PageSettings();
pageSettings.Margins.Top = 40;
pageSettings.Margins.Bottom = 40;
pageSettings.Margins.Left = 40;
pageSettings.Margins.Right = 40;
LoadChartsBook chartsBook = new LoadChartsBook(chartsData);
PrintDocument docToPrint = chartsBook.CreatePrintDocument();
docToPrint.DefaultPageSettings = pageSettings;
PrintPreviewDialog previewDialog = new PrintPreviewDialog();
previewDialog.Document = docToPrint;
previewDialog.ShowDialog();
Then the called code for CreatePrintDocument()
public PrintDocument CreatePrintDocument()
{
index.resetCounter();
coverPagePrinted = false;
currentChartIndex = 0;
pageNumber = 0;
PrintDocument printDocument = new PrintDocument();
printDocument.DocumentName = (index.totalEntries()+1).ToString() + ", of Load Charts Book: " + chartBookID;
printDocument.PrintPage += new PrintPageEventHandler(PrintLoadChartsBookEventHandler);
return printDocument;
}
Each chart is very processor intensive and hence time consuming to create, I need to avoid this apparent second call to CreatePrintDocument() but can't see why it's being called in again anyway.
Am I missing a setting in the preview dialog?
Any help appreciated.

How to send cut command in Thermal Printer using PrintDocument in c#

I am Using PrintDocument to print the billing content. But I am unable to send auto cut command. I am using the code below to print content.
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.PrinterSettings.PrinterName = "TestPrinter";
printDocument.Print();
printDocument.Dispose();
Can anyone help me which command I have to use for auto cut?
I have tried a combination of below two code blocks
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.PrinterSettings.PrinterName = "TestPrinter";
printDocument.Print();
printDocument.Dispose();
and at the end, I am sending below commands it's working fine for me
string GS = Convert.ToString((char)29);
string ESC = Convert.ToString((char)27);
string documentName ="x"
string COMMAND = this.textBox.T`ext;
COMMAND = ESC + "#";
COMMAND += GS + "V" + (char)1;
RawPrinterHelper.SendStringToPrinter(this.textBox1.Text, COMMAND,documentName);

How to print word document using PrintDocument class

My requirement is to print a Word document using c#.
Since Interop Word is not recommended to use at server side, I would like to print Word file using PrintDocument class.
So, how to print Word document using c#?
I tried the below code, but it printed out 2 blank pages:
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "E:\\WordPrint\\Output\\TEST.docx";
printDoc.DefaultPageSettings.PrinterSettings.PrinterName = "Bullzip PDF Printer";
printDoc.DefaultPageSettings.PrinterSettings.Copies = 2;
printDoc.Print();
try
{
streamToPrint = new StreamReader ("C:\\My Documents\\MyFile.txt");
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
You can find more information on the msdn site:
https://msdn.microsoft.com/de-de/library/system.drawing.printing.printdocument(v=vs.110).aspx

Printing to a thermal printer with ASP.NET C# WebForms (4.5)

I have a requirement for a project at work to print to a thermal printer (specifically a Citizen CT-S651) that is attached to the computer via USB from ASP.NET C# Webforms. So far, I have tried a few things and did a lot of research. The main three things I have tried was using QZ Tray (formerly known as JZebra, found here https://qz.io/), however the non-free version costs too much right now, and the free version is too annoying in its popups to be of much use right now. I also tried to generate a PDF using MigraDoc (http://www.pdfsharp.net/), but when I try to print to the printer, it uses far too much paper before it even prints "Hello World" code for that shown below:
private void print()
{
Document document = CreateDocument();
document.UseCmykColor = true;
const bool unicode = false;
const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
//pdfRenderer.Save("C:/Users/jamesl/Documents/Visual Studio 2013/Projects/TestCheckScanner/TestCheckScanner/TestDocument.pdf");
MemoryStream stream = new MemoryStream();
pdfRenderer.PdfDocument.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();
}
private Document CreateDocument()
{
Document document = new Document();
MigraDoc.DocumentObjectModel.Unit width, height;
width = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(80);
height = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(50);
Section section = document.AddSection();
section.PageSetup.PageHeight = height;
section.PageSetup.PageWidth = width;
section.PageSetup.PageHeight = height;
section.PageSetup.PageWidth = width;
section.PageSetup.LeftMargin = 0;
section.PageSetup.RightMargin = 0;
section.PageSetup.TopMargin = 0;
Paragraph paragraph = section.AddParagraph();
paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black; //Same as System.Drawing.Color
paragraph.AddFormattedText("Hello, World!");
return document;
}
Since that hasn't worked very well, I have gotten it to print a little bit using PrintDocument, however, the main problems I have with this way are twofold: 1. Formatting it print a proper receipt is going to be very tedious although if it is ends up being the best way with my current constraints I am all for it. 2. This method only works if I print from Visual Studio, when I try it on the test web app I have set up on a server, I get an error of "Settings to access printer 'CITIZEN CT-S651' are not valid." Here is my code for that:
private void print()
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = "CITIZEN CT-S651";
pd.Print();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.End();
}
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString("Test Print", new System.Drawing.Font("Arial", 12), new SolidBrush(Color.Black), 60, 0);
e.Graphics.DrawString("Test Again", new System.Drawing.Font("Arial", 12), new SolidBrush(Color.Black), 60, 20);
}
Any help you can give on this matter would be awesome!

Printing two seperate documents without two print dialogues

I need to print 2 different copies of this receipt using the same printer, and with only one print dialogue. Right now, the first copy prints fine, but then the fax dialogue comes up for the second one, because that's my default printer.
How would I do both using one printer? Or is there a way to print to a non default printer without the print dialogue. In this case, the printer will never change.
Thanks!
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.BuildCustomerReciept);
PrintDialog pdi = new PrintDialog();
pdi.Document = pd;
PrintDocument pdd = new PrintDocument();
pdd.PrintPage += new PrintPageEventHandler(this.BuildStoreReciept);
PrintDialog pddi = new PrintDialog();
pddi.Document = pdd;
if (pdi.ShowDialog() == DialogResult.OK)
{
pd.Print();
pdd.Print();
}
Did you tried that?
...
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Specify the printer to use. You can check its name in control panel
pd.PrinterSettings.PrinterName = "NameofThePrinter";
pd.Print();
...

Categories

Resources