How to Print logo with bill receipt? - c#

I'm working Windows Application and C#, my application based on restaurant billing process. when i generate the bill its print with logo.
Now, its only print text format.
We are using our application its write all text information through stream writer from notepad file.
This is my sample code,
string strTextFileName = "ESC" + "1" + ".txt";
string strTextFilePath = Application.StartupPath + "\\" + strTextFileName;
if (File.Exists(strTextFilePath))
File.Delete(strTextFilePath);
using (StreamWriter sw = new StreamWriter(strTextFilePath))
{
sw.WriteLine("---------------------");
sw.WriteLine("start s for testing of the Print in t end");
}
Please anyone help to me.

Related

Adobe Reader Parameters

Im trying to save a pdf file as a new pdf but printting it (required), Im using Adobe Acrobat to do that cause it brings me the option to introduce parameters.
The thing is : I need to do it silently (Not a single Window can been saw). So I need to set a printer, a path to my file and an output destination.
As I said I need to "print it" as a new pdf so I'm using Microsoft Print to PDF to do that (I don't know if it is the better option).
Thank you so much!
string file = name;
string pathFile = "C:\\DfPrinter\\" + name;
ProcessStartInfo infoPrintPdf = new ProcessStartInfo();
string printerName = "Microsoft Print to PDF";
infoPrintPdf.FileName = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe";
infoPrintPdf.Arguments = string.Format("/t" + " '" + pathFile + "'" +"' " +"'"+printerName+"'");
infoPrintPdf.CreateNoWindow = true;
infoPrintPdf.UseShellExecute = false;
infoPrintPdf.WindowStyle = ProcessWindowStyle.Hidden;
Process printPdf = new Process();
printPdf.StartInfo = infoPrintPdf;
printPdf.Start();
System.Threading.Thread.Sleep(10000);
if (!printPdf.CloseMainWindow())
printPdf.Kill(); printPdf.WaitForExit();
I don't think Acrobat Reader can print silently, but you could consider using the Win2PDF "printpdf" command line:
win2pdfd.exe printpdf "filename.pdf" Win2PDF "newfilename.pdf"
This prints the PDF silently to a new PDF specified by "newfilename" by using the Win2PDF printer.

How to display more than one photo from flicker api in WebBrowser

I am looking for solution how to display more than one photo in my webbrowser using winforms. I am using Flickr API to make my simple photo filtering application. I am using this method: https://www.flickr.com/services/api/flickr.photos.search.html
With this method, I get XML file which shows 100 photos components and later from this XML I am building my Url string.
My code looks like:
StringBuilder abc = new StringBuilder();
XmlTextReader sr = new XmlTextReader(Urlstring);
while (sr.Read())
{
if ((sr.NodeType == XmlNodeType.Element && (sr.Name == "photo")))
{
if (sr.HasAttributes)
abc.Append("https://farm" + sr.GetAttribute("farm") + ".staticflickr.com/" + sr.GetAttribute("server") + "/" + sr.GetAttribute("id") + "_" + sr.GetAttribute("secret") + ".jpg");
break;
}
}
With this code I get only one photo of that XML file. I want to get more, but when I remove break;. Webbrowser says there are no photos to display. Maybe you have any solution how to build string and read that xml that I could build more that one url and display in webbrowser application?
Thanks in advance.

Spreadsheetlight save as working too slow

I am working on a winform with spreadsheetlight library.I want to create a excel file with specific name under a specific folder when user clicked on "Save to Excel" button. Ihave tried the below code so far.
string path = System.IO.Path.GetTempPath();
sl.SaveAs(path + "\\" + dosyaismi + ".xlsx");
FileInfo fi = new FileInfo(path + "\\" + dosyaismi + ".xlsx");
if (fi.Exists)
{
System.Diagnostics.Process.Start(#path + "\\" + dosyaismi + ".xlsx");
}
else
{
MessageBox.Show("Dosya bulunamadı!");
}
When program run and clicked that button first time it takes 2 minutes to create file.But without closing program I clicked that button again with different filename it creates file immediately.
I searched for 2 hours but ı didn't find any solution.Can anyone help what is the problem?

Append to Start of a file. Use MemoryBuffer or Stream writer and ReadAll Text

I am creating and excel file with a few tabs on it. I create a StreamWriter bject and append excel XML to the file and all works fine.
However the issue I am having is that I need to put in a summary Tab at the start. In order to work out the summary I need to complete the other tabs and work out the records, rows and some stats and put on the summary tab.
The issue is, is that I cant append to the start of the file using Stream Writer. I did put in a place holder like a tag. Close the file and opened it again.. using ReadAllText and replacing the tag... then writing back to disk. Ok for small files but I am doing this over the network and the file is large so it looks like a double write when it happens and takes for ever.. well twice as long.
Is there a better way to do this. Should I use a memory buffer. Again I don't want to hog server resources. Speed is important here and the open and close and read all just isn't efficient.
Added some Code...
Straight forward code...
//Open a temp File and use Stream Writer..
TempFileName = Path.GetTempFileName();
using (_reportWriter = new StreamWriter(TempFileName, true, Encoding.ASCII, 2048))
{
WriteExcelXmlOpeningTags();
WriteAllDataToFile();
WriteWorksheetXmlClosingTags();
}
//Generate the Summary
String summary = GenerateReportSummary();
//Now I have to open the file, read all the bytes.. replace the tag with the summary and write all the data again...
.. This proc writes the opening tags in xml and a REPORTSUMMARYSHEET TagHolder to get replaced at the end.
public void WriteExcelXmlOpeningTags()
{
_reportWriter.WriteLine("<?xml version=\"1.0\"?>");
_reportWriter.WriteLine("<?mso-application Excel.Sheet?>");
_reportWriter.WriteLine("<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");
_reportWriter.WriteLine("<ss:Styles>");
_reportWriter.WriteLine("<ss:Style ss:ID=\"StdHeaderStyle\">");
_reportWriter.WriteLine("<ss:Font ss:Bold=\"1\"/>");
_reportWriter.WriteLine("</ss:Style>");
_reportWriter.WriteLine("<ss:Style ss:ID=\"StdRowStyle\">");
_reportWriter.WriteLine("<Alignment ss:Vertical=\"Top\" ss:WrapText=\"1\"/>");
_reportWriter.WriteLine("</ss:Style>");
_reportWriter.WriteLine("</ss:Styles>");
// This will be replaced with Report Summary Stats at the end of
_reportWriter.WriteLine("<REPORTSUMMARYSHEET_TAGHOLDER>");
_reportWriter.Flush();
}
public void WriteWorksheetXmlClosingTags(int cols)
{
_reportWriter.WriteLine("</Table>");
_reportWriter.WriteLine("<WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">" +
"<PageSetup>" +
"<Header x:Margin=\"0.3\"/>" +
"<Footer x:Margin=\"0.3\"/>" +
"<PageMargins x:Bottom=\"0.75\" x:Left=\"0.7\" x:Right=\"0.7\" x:Top=\"0.75\"/>" +
"</PageSetup>" +
"<Selected/>" +
"<FreezePanes/>" +
"<FrozenNoSplit/>" +
"<SplitHorizontal>1</SplitHorizontal>" +
"<TopRowBottomPane>1</TopRowBottomPane>" +
"<ActivePane>2</ActivePane>" +
"<Panes>" +
"<Pane>" +
"<Number>3</Number>" +
"</Pane>" +
"<Pane>" +
"<Number>2</Number>" +
"</Pane>" +
"</Panes>" +
"<ProtectObjects>False</ProtectObjects>" +
"<ProtectScenarios>False</ProtectScenarios>" +
"</WorksheetOptions>" +
"<AutoFilter x:Range=\"R1C1:R1C" + cols.ToString() +
"\" xmlns=\"urn:schemas-microsoft-com:office:excel\">" +
"</AutoFilter>");
_reportWriter.WriteLine("</Worksheet>");
_reportWriter.Flush();
}
I then have to close the file.. and open it with FileReadAlltext and replace the tag. This is like a double effort as I have to incur the same time expensive the write all the bytes again with the short summery tag populated.
regards M

Writing to text files using SaveFileDialog

I'm working on an Add In for Microsoft Excel in Visual Studio that records the balances for each account (or Worksheet) and saves them to a user-specified file. The ability to press a button and select a destination to save your work is an essential skill for any programmer, so I'm perplexed as to why there is so little information on how to do it. The closest thing I found was a tutorial on MSDN that saves a button icon image.
The code I'm currently using is as follows:
StringBuilder sb = new StringBuilder();
if (ThisAddIn.createdbudget)
{
string budget = "Budget = " + ThisAddIn.blake.budget;
SaveFileDialog savebudget = new SaveFileDialog();
savebudget.Filter = "Data files (*.dat)|*.dat|All files (*.*)|*.*";
savebudget.Title = "Save Budget";
savebudget.ShowDialog();
if (savebudget.FileName != "")
{
using (StreamWriter sr = new StreamWriter(savebudget.OpenFile()))
{
sb.AppendLine(budget);
}
}
}
else
{
MessageBox.Show("Control disabled. Budget does not yet exist.");
}
My objective is to allow the user to designate a file path via SaveFileDialog and save a new .dat (or .txt). The stream writer would record the account names and their respective balances line by line. Something like:
sr.WriteLine(Account1.Name + " Balance = " + Account1.Balance);
sr.WriteLine(Account2.Name + " Balance = " + Account2.Balance);
etc...
I know this sounds complicated. I have no problem saving data if I'm using a predetermined file path, but that's not very helpful. What I need to know is how to properly write files using SaveFileDialog.

Categories

Resources