I am using Dynamsoft Barcode Readeing Dll In My Barcode Reader Project.I am getting Correct Output Of Given Barcode at Running Time But With Output I am getting License error.How can I solve it...Just I am only using Barcode dll..
Here With I have Attached That Output screenshot And code...
[License Error Screen Shot
{
Stopwatch watch = new Stopwatch();
BarcodeReader reader = new BarcodeReader();
public String BarcodePathAndName = "";
int i = 0, n = 0;
public bool nextimgs = true;
ThreadClassnextImage obj = new ThreadClassnextImage();
public Barcodes()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
obj.BcH += obj_BcH;
}
private void obj_BcH(Image BarcodeNextImages, string barcodeImagePath)
{
rTbBarCodeResults.Text = "";
PbLoadBarcodeImage.Image = BarcodeNextImages;
watch.Reset();
watch.Start();
BarcodeResult[] result = reader.DecodeFile(barcodeImagePath);
n = result.Length;
for (i = 0; i < n; i++)
{
BarcodeResult barcode = result[i];
rTbBarCodeResults.Text = rTbBarCodeResults.Text + barcode.BarcodeFormat.ToString() + "\r\n";
rTbBarCodeResults.Text = rTbBarCodeResults.Text + barcode.BarcodeText + "\r\n";
rTbBarCodeResults.Text = rTbBarCodeResults.Text + barcode.BarcodeData.ToString() + "\r\n";
watch.Stop();
rTbBarCodeResults.Text += "\n\nTotal Sec: " + watch.Elapsed.TotalSeconds+"\r\n";
rTbBarCodeResults.Text+="\r\nTotal Minutes: "+watch.Elapsed.TotalMinutes+"\r\n";
rTbBarCodeResults.Text+="\r\nTotal Mill Seconds: "+watch.Elapsed.TotalMilliseconds+"\r\n";
rTbBarCodeResults.Text+="\r\nTotal Nano Seconds:"+watch.Elapsed.TotalMilliseconds*1000000+"\r\n";
}
}`
`]1
Dynamsoft Barcode Reader is a commercial software. You have to set a valid license, trial or full, as follows:
BarcodeReader reader = new BarcodeReader { LicenseKeys = "t0260NQAAAFUZbbNi3xJ4oViu+0+5Eim8wPzn6GeJZrIvrb/HLjzJ8Mn+GRjbfdoa/f+iRLzKTudXVEkKqj9tKlzzDP+xKzZ2IdknzMXimKDmKBivdKTXM3T5ACPK25omqoQkqNw00zExtCrR532mHig0QU6dsF5EmvkgDLxsbWw/M54wj1F1pGagM7YfKzpLN0/qvCeejimX2nvTMfOzv+M37m+0RPsnyp20pITycnvBGyWkZ3OWQ97U8UNYl+OyyfuHymz8EcjqQm9nxvYTm4nYHERHkiXMmI6jWLgK+4+jIlcS9WLgWd8pMKkI0bZCcwmVzk5z+vuGYKjZVK/iuYIx7McOP9k=" };
You can get the trial license from the SDK installer.
Related
void BuildProjects()
{
String outputPath = #"D:\PIT\ProcessImprovementTool\DLL";
console = new Process();
console.StartInfo.FileName = "cmd.exe";
console.StartInfo.UseShellExecute = false;
console.StartInfo.CreateNoWindow = true;
console.StartInfo.RedirectStandardInput = true;
console.StartInfo.RedirectStandardOutput = true;
console.StartInfo.RedirectStandardError = true;
console.Exited += new EventHandler((sender, e) =>
{
Console.WriteLine("if (console.Exited) --> ExitCode: " + console.ExitCode);
BuildProjects();
});
console.OutputDataReceived += new DataReceivedEventHandler(ConsoleOutputHandler);
console.ErrorDataReceived += new DataReceivedEventHandler(ConsoleOutputHandler);
console.Start();
using (StreamWriter sw = console.StandardInput)
{
sw.AutoFlush = true;
console.StandardInput.AutoFlush = true;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("D:\\PIT\\ProcessImprovementTool\\callVcvars32.bat");
sw.WriteLine("cls");
for (int ctr = 0; ctr < 5; ctr++)
{
sw.WriteLine("msbuild /property:OutputPath=" + outputPath + #";OutputType=Library " + lines[ctr]);
//console.BeginOutputReadLine();
sw.Flush();
}
}
if (tryout)
{
Console.WriteLine("working");
}
sw.Close();
//sw.Flush();
}
console.BeginOutputReadLine();
console.BeginErrorReadLine();
//console.WaitForExit();
counter++;
}
in the
for (int ctr = 0; ctr < 5; ctr++)
{
sw.WriteLine("msbuild /property:OutputPath=" + outputPath + #";OutputType=Library " + lines[ctr]);
//console.BeginOutputReadLine();
sw.Flush();
}
if i set the limit for ctr to 40 (ctr < 40) my application hangs, and I get that the stream is already at its limit.
Based on my research, .Flush() should do the trick. or setting AutoFlush to True, but doesn't seem to work.
so how do I clear previous stream records, or anything that would let me input more than 40 lines? (i got 100+ but not more than 150 lines to write in streamWriter).
lines variable stores the value of "build.txt".
void readFromBuild()
{
doneReading = true;
lines = System.IO.File.ReadAllLines(#"D:\PIT\ProcessImprovementTool\Build\build.txt");
//System.Console.WriteLine("Contents of WriteLines2.txt = ");
foreach (string line in lines)
{
lineCount++;
}
Console.WriteLine(lineCount);
lineCount = lineCount - limit;
}
"build.txt" contains all files to be compiled to produce DLL files.
For me, this is as good as answered. I just did it in another way, though it may not be that good.
buildProgress.Enabled = true;
buildProgress.Maximum = lineCount;
for (int ctr = 0; ctr < lineCount; ctr++)
{
String outputPath = #"Q:\";
StreamReader reader;
String outputLine;
console = new Process();
console.StartInfo.FileName = "cmd.exe";
console.StartInfo.UseShellExecute = false;
console.StartInfo.CreateNoWindow = true;
console.StartInfo.RedirectStandardInput = true;
console.StartInfo.RedirectStandardOutput = true;
console.StartInfo.RedirectStandardError = true;
console.Start();
using (StreamWriter sw = console.StandardInput)
{
sw.AutoFlush = true;
console.StandardInput.AutoFlush = true;
if (sw.BaseStream.CanWrite)
{
sw.WriteLine(#"Q:\");
sw.WriteLine("msbuild /property:OutputPath=" + outputPath + #";OutputType=Library " + lines[ctr]);
sw.Flush();
}
sw.Close();
}
reader = console.StandardOutput;
outputLine = reader.ReadToEnd();
console.WaitForExit();
//if (console.HasExited)
//{
Console.Write(outputLine);
//outputTextBox.Text += outputLine;
pathToLog = #"Q:\" + fileList[ctr];
File.Create(pathToLog).Dispose();
File.WriteAllText(pathToLog, outputLine);
buildProgress.Value = ctr;
string[] readThatLog = File.ReadAllLines(pathToLog);
foreach(string line in readThatLog)
{
if (line == "Build succeeded.")
{
outputTextBox.AppendText(lines[ctr]);
outputTextBox.AppendText(Environment.NewLine + line);
outputTextBox.AppendText(Environment.NewLine + Environment.NewLine);
}
else if (line == "Build FAILED.")
{
outputTextBox.AppendText(lines[ctr]);
outputTextBox.AppendText(Environment.NewLine + line);
outputTextBox.AppendText(Environment.NewLine + Environment.NewLine);
}
}
//}
}
buildProgress.Value = 0;
buildProgress.Enabled = false;
Console.WriteLine("\n\n\n\nDONE!!!");
I have a zpllabel.txt file that I read into memory but I want to get all the ^FO values from the textfile and add to it the value that user enters to offset the printer.
^XA^MCY^PRD,D,D^MMT,N^XZ
^XA
^DFCASENEW^FS
^LH0,0
^FO33,45^A0N,90,98^FN01^FS^FX Company^FS
^FO879,28^A0N,263,214^FN02^FS^FX Product^FS
^FO30,159^A0N,90,58^FN03^FS^FX Description^FS
^FO42,321^A0N,65,68^FN04^FS^FX NumberIn^FS
^FO100,436^A0N,75,66^FN05^FS^FX SelectCode^FS
^BY6,,230^FO260,252^BCN,,N,N,N,N^FN06^FS^FX RotationProduct^FS
^FO660,503^A0N,32,98^FN07^FS^FX RotationProduct^FS
^BY4,3.0,204^FO60,518^B2N,,N,N,N^FN08^FS^FX UPCCode^FS
^FO170,732^A0N,24,47^FN09^FS^FX UPCCode^FS
^FO32,516^GB590,0,10^FS
^FO32,717^GB590,0,10^FS
^FO640,573^A0N,226,212^FN10^FS^FX Rotation^FS
^FO1362,546^A0N,90,66^FDBest Before^FS
^FO1235,628^A0N,134,140^FN11^FS^FX BestBefore^FS
^FO55,391^A0N,43,77^FDSEL^FS
^FO30,267^A0N,54,100^FDQTY^FS
^XZ
^XA^XFCASENEW
^FN01^FDCompany^FS
^FN02^FDProduct^FS
^FN03^FDDescription^FS
^FN04^FDNumberIn^FS
^FN05^FDSelectCode^FS
^FN06^FDRotationProduct^FS
^FN07^FD^FS
^FN08^FDUPCCode^FS
^FN09^FD^FS
^FN10^FDRotation^FS
^FN11^FDBestBefore^FS
^PQ1,0,1,Y
^XZ
^XA^ID*.*^XZ
so for example 5th line of the label needs to be FO43 if the user enters an offset value of 10 and needs to be 23 if he enters -10 as the offset value, I am a noob at handling textfiles in c# please help
I have this code that replaces a pair of text:
try
{
byte[] file = File.ReadAllBytes("C:\\Users\\something\\Documents\\Visual Studio 2013\\Projects\\zplTest\\zplTest\\zpllabel3.txt");
using (MemoryStream memory = new MemoryStream(file))
{
using (TextReader reader = new StreamReader(memory))
{
string input = reader.ReadToEnd();
// for (int i = 0; 1 < file.Length; i++)
{
using (MemoryStream writermemory = new MemoryStream())
using (StreamWriter writer = new StreamWriter(writermemory))
{
Dictionary<string, string> replacementcollections =
new Dictionary<string, string>();
replacementcollections.Add
("^FN01^FDCompany^FS", compname);
replacementcollections.Add
("^FN02^FDProduct^FS", stlabel23);
replacementcollections.Add
("^FN03^FDDescription^FS", stlabel24);
replacementcollections.Add
("^FN04^FDNumberIn^FS", stlabel25);
replacementcollections.Add
("^FN05^FDSelectCode^FS", stlabel26);
replacementcollections.Add
("^FN06^FDRotationProduct^FS", stlabel27);
replacementcollections.Add
("^FN07^FD^FS", stlabel28);
replacementcollections.Add
("^FN08^FDUPCCode^FS", stlabel29.TrimEnd());
replacementcollections.Add
("^FN09^FD^FS", stlabel30.TrimEnd());
replacementcollections.Add
("^FN10^FDRotation^FS", "^FN10^FD" + TxtRotcode.Text.Trim() + "^FS");
replacementcollections.Add
("^FN11^FDBestBefore^FS", "^FN11^FD" + TxtBestBefore.Text.Trim() + "^FS");
replacementcollections.Add
("^PQ1,0,1,Y", "PQ" + TxtQty.Text.Trim() + ",0,1,Y");
string output = input;
foreach (KeyValuePair<string, string>
replacement in replacementcollections)
{ output = output.Replace(replacement.Key, replacement.Value); }
Label256.Visible = true;
zplcode.Text = output;
zplcode.Visible = true;
writer.Close();
ZplPreview();
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
Console.WriteLine(ex.Message.ToString());
}
so what I would like to accomplish
1) read text file into memory
2) find all the values of "FO"
3) add or subtract that value with what the user enters
4) send it to the textbox
5) I later send that text to the zebra printer
I tried:
using
(TextReader reader = new StreamReader(memory))
{
int offset = Convert.ToInt32(txtOffSet.Text);
string inputs = reader.ReadToEnd();
Regex r = new Regex("\\^FO([0-9]*)", RegexOptions.Singleline);
string res = r.Replace(Convert.ToString(reader), (input) => "^FO" + (int.Parse(input.Groups[1].Value) + offset).ToString());
// for (int i = 0; 1 < file.Length; i++)
{
Ok, your question is really vague and your code has nothing to do with what you asked, but this can help you on the replacement you requested.
string fileContent = File.ReadAllText("path/to/your/file");
int offset = 10; //Store here your offset, positive to add it, negative to subtract it
Regex r = new Regex("\\^FO([0-9]*)", RegexOptions.Singleline);
string res = r.Replace(fileContent, (input) => "^FO" + (int.Parse(input.Groups[1].Value) + offset).ToString());
//Now you have the content of the file with the FO replaced with it's new values
Debug.Write(res);
I'm trying to read some files with ReadLine, but my file have some break lines that I need to catch (not all of them), and I don't know how to get them in the same array, neither in any other array with these separators... because... ReadLine reads lines, and break these lines, huh?
I can't replace these because I need to check it after the process, so I need to get the breaklines AND the content after that. That's the problem. How can I do that?
Here's my code:
public class ReadFile
{
string extension;
string filename;
System.IO.StreamReader sr;
public ReadFile(string arquivo, System.IO.StreamReader sr)
{
string ext = Path.GetExtension(arquivo);
sr = new StreamReader(arquivo, System.Text.Encoding.Default);
this.sr = sr;
this.extension = ext;
this.filename = Path.GetFileNameWithoutExtension(arquivo);
if (ext.Equals(".EXP", StringComparison.OrdinalIgnoreCase))
{
ReadEXP(arquivo);
}
else MessageBox.Show("Extensão de arquivo não suportada: "+ext);
}
public void ReadEXP(string arquivo)
{
string line = sr.ReadLine();
string[] words;
string[] Separators = new string[] { "<Segment>", "</Segment>", "<Source>", "</Source>", "<Target>", "</Target>" };
string ID = null;
string Source = null;
string Target = null;
DataBase db = new DataBase();
//db.CreateTable_EXP(filename);
db.CreateTable_EXP();
while ((line = sr.ReadLine()) != null)
{
try
{
if (line.Contains("<Segment>"))
{
ID = "";
words = line.Split(Separators, StringSplitOptions.None);
ID = words[0];
for (int i = 1; i < words.Length; i++ )
ID += words[i];
MessageBox.Show("Segment[" + words.Length + "]: " + ID);
}
if (line.Contains("<Source>"))
{
Source = "";
words = line.Split(Separators, StringSplitOptions.None);
Source = words[0];
for (int i = 1; i < words.Length; i++)
Source += words[i];
MessageBox.Show("Source[" + words.Length + "]: " + Source);
}
if (line.Contains("<Target>"))
{
Target = "";
words = line.Split(Separators, StringSplitOptions.None);
Target = words[0];
for (int i = 1; i < words.Length; i++)
Target += words[i];
MessageBox.Show("Target[" + words.Length + "]: " + Target);
db.PopulateTable_EXP(ID, Source, Target);
MessageBox.Show("ID: " + ID + "\nSource: " + Source + "\nTarget: " + Target);
}
}
catch (IndexOutOfRangeException e)
{
MessageBox.Show(e.Message.ToString());
MessageBox.Show("ID: " + ID + "\nSource: " + Source + "\nTarget: " + Target);
}
}
return;
}
If you are trying to read XML, try using the built in libaries, here is a simple example of loading a section of XML with <TopLevelTag> in it.
var xmlData = XDocument.Load(#"C:\folder\file.xml").Element("TopLevelTag");
if (xmlData == null) throw new Exception("Failed To Load XML");
Here is a tidy way to get content without it throwing an exception if missing from the XML.
var xmlBit = (string)xmlData.Element("SomeSubTag") ?? "";
If you really have to roll your own, then look at examples for CSV parsers,
where ReadBlock can be used to get the raw data including line breaks.
private char[] chunkBuffer = new char[4096];
var fileStream = new System.IO.StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
var chunkLength = fileStream.ReadBlock(chunkBuffer, 0, chunkBuffer.Length);
I have finally, successfully, figured out how to fill a PDF with an XFA Form with my custom data using iTextSharp.
The problem is that I've lost the code that I had that let me make the XFA read-only. I have made the horrible mistake of changing my code before committing a working version to my source control. And now, after searching Google for like an hour I still can't find it :( If someone could remind me of the code that would be much appreciated.
PdfReader.unethicalreading = true;
PdfReader reader = new PdfReader(pdfFileName);
PdfStamper stamper = new PdfStamper(reader, ms);
XfaForm xfa = new XfaForm(reader);
XmlDocument doc = new XmlDocument();
doc.LoadXml(CreateXmaData(XDocument.Parse(xfa.DomDocument.InnerXml)));
xfa.DomDocument = doc;
xfa.Changed = true;
XfaForm.SetXfa(xfa, stamper.Reader, stamper.Writer);
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
stamper.Writer.SetOpenAction(action);
// Somewhere here I had the code that made my XFA form read only...
stamper.Writer.CloseStream = false;
stamper.Close();
reader.Close();
byte[] buffer = new byte[ms.Position];
ms.Position = 0;
ms.Read(buffer, 0, buffer.Length);
return buffer;
Not sure if I was dreaming that I had the read-only working or what, and I doubt that this is the best way, but here is how I was finally able to do it:
...
doc.LoadXml(CreateXmaData(XDocument.Parse(xfa.DomDocument.InnerXml)));
PdfAction readOnlyAction = PdfAction
.JavaScript(MakeReadOnly(xfa.DomDocument.InnerXml), stamper.Writer);
stamper.Writer.AddJavaScript(readOnlyAction);
xfa.DomDocument = doc;
...
private string MakeReadOnly(string xml)
{
string formName = string.Empty;
int subFormStart = xml.IndexOf("<subform", 0);
if (subFormStart > -1)
{
int nameTagStart = xml.IndexOf("name", subFormStart);
int nameStart = xml.IndexOf("\"", nameTagStart);
int nameEnd = xml.IndexOf("\"", nameStart + 1);
formName = xml.Substring(nameStart + 1, (nameEnd - nameStart) - 1);
}
string readOnlyFunction = "ProcessAllFields(xfa.form." + formName + ");";
readOnlyFunction += "function ProcessAllFields(oNode) {";
readOnlyFunction += " if (oNode.className == \"exclGroup\" || oNode.className == \"subform\" || oNode.className == \"subformSet\" || oNode.className == \"area\") { ";
readOnlyFunction += " for (var i = 0; i < oNode.nodes.length; i++) {";
readOnlyFunction += " var oChildNode = oNode.nodes.item(i); ProcessAllFields(oChildNode);";
readOnlyFunction += " }";
readOnlyFunction += " } else if (oNode.className == \"field\") {";
readOnlyFunction += " oNode.access = \"readOnly\"";
readOnlyFunction += " }";
readOnlyFunction += "}";
return readOnlyFunction;
}
This worked for me
String script = "for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { var oFields = xfa.layout.pageContent(nPageCount, \"subform\"); var nNodesLength = oFields.length;";
script += "for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { oFields.item(nNodeCount).access = \"readOnly\"; } } ";
I have a large CSV file around 25G. I need to parse each line which has around 10 columns and do some processing and finally save it to a new file with parsed data.
I am using dictionary as my datastructure. To avoid the memory overflow I am writing the file after 500,000 records and clearing the dictionary.
Can anyone suggest whether is this good way of doing. If not, any other better way of doing this? Right now it is taking 30 mins to process 25G file.
Here is the code
private static void ReadData(string filename, FEnum fileType)
{
var resultData = new ResultsData
{
DataColumns = new List<string>(),
DataRows = new List<Dictionary<string, Results>>()
};
resultData.DataColumns.Add("count");
resultData.DataColumns.Add("userid");
Console.WriteLine("Start Processing : " + DateTime.Now);
const long processLimit = 100000;
//ProcessLimit : 500000, TimeElapsed : 30 Mins;
//ProcessLimit : 100000, TimeElaspsed - Overflow
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Dictionary<string, Results> parsedData = new Dictionary<string, Results>();
FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
using (StreamReader streamReader = new StreamReader(fileStream))
{
string charsRead = streamReader.ReadLine();
int count = 0;
long linesProcessed = 0;
while (!String.IsNullOrEmpty(charsRead))
{
string[] columns = charsRead.Split(',');
string eventsList = columns[0] + ";" + columns[1] + ";" + columns[2] + ";" + columns[3] + ";" +
columns[4] + ";" + columns[5] + ";" + columns[6] + ";" + columns[7];
if (parsedData.ContainsKey(columns[0]))
{
Results results = parsedData[columns[0]];
results.Count = results.Count + 1;
results.Conversion = results.Count;
results.EventList.Add(eventsList);
parsedData[columns[0]] = results;
}
else
{
Results results = new Results {
Count = 1, Hash_Person_Id = columns[0], Tag_Id = columns[1], Conversion = 1,
Campaign_Id = columns[2], Inventory_Placement = columns[3], Action_Id = columns[4],
Creative_Group_Id = columns[5], Creative_Id = columns[6], Record_Time = columns[7]
};
results.EventList = new List<string> {eventsList};
parsedData.Add(columns[0], results);
}
charsRead = streamReader.ReadLine();
linesProcessed++;
if (linesProcessed == processLimit)
{
linesProcessed = 0;
SaveParsedValues(filename, fileType, parsedData);
//Clear Dictionary
parsedData.Clear();
}
}
}
stopwatch.Stop();
Console.WriteLine(#"File : {0} Batch Limit : {1} Time elapsed : {2} ", filename + Environment.NewLine, processLimit + Environment.NewLine, stopwatch.Elapsed + Environment.NewLine);
}
Thank you
The Microsoft.VisualBasic.FileIO.TextFieldParser class looks like it could do the job. Try it, it may speed things up.