public PrintTextValues GetTextValues(IEnumerable<string> texts, string title, bool extractValuesFromText = true) { // read : title // modify : infos, description, language, size, nbPages PrintTextValues textValues = new PrintTextValues(); List<string> description = new List<string>(); _exportDataWriter.zWriteStartDocument(); _exportDataWriter.zWrite("Title", title); _exportDataWriter.zWriteStartArray("Texts"); string name = null; foreach (string s in texts) { _exportDataWriter.zWrite(s); if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues : \"{0}\"", s); string name2; string text2; // Editeur : Presse fr bool textValues2 = false; if (extractValuesFromText) { textValues2 = ExtractTextValues2(s, out name2, out text2); if (s == "\r\n" || textValues2) { if (name != null) { if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = null", name); textValues.infos.SetValue(name, null); } name = null; if (textValues2) { if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name2, text2); if (text2 != null) textValues.infos.SetValue(name2, new ZString(text2)); else name = name2; } } } if (!textValues2) { // PDF | 116 pages | 53 Mb | French string s2 = ExtractTextValues(textValues.infos, s); s2 = Trim(s2); if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues ExtractTextValues : \"{0}\" - \"{1}\"", s, s2); if (s2 != "" && s2 != title) { if (s2.StartsWith(title)) s2 = Trim(s2.Substring(title.Length)); if (name != null) { if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, s2); textValues.infos.SetValue(name, new ZString(s2)); name = null; } else { NamedValues<ZValue> values = _textInfoRegexList.ExtractTextValues(ref s2); textValues.infos.SetValues(values); if (s2 != "") { if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues description.Add : \"{0}\"", s2); description.Add(s2); } } } } } if (name != null) { if (__trace) pb.Trace.CurrentTrace.WriteLine("SetTextValues SetValue : \"{0}\" = null", name); textValues.infos.SetValue(name, null); } textValues.description = description.ToArray(); _exportDataWriter.zWriteEndArray(); _exportDataWriter.zWriteName("PrintTextValues"); //_exportDataWriter.zWriteStartDocument("PrintTextValues"); _exportDataWriter.zSerialize(textValues); //_exportDataWriter.zWriteEndDocument(); _exportDataWriter.zWriteEndDocument(); _exportDataWriter.zWriteName("fake"); // ??? pour éviter l'erreur : WriteString can only be called when State is Value or Initial, not when State is Name (System.InvalidOperationException) _exportDataWriter.zWriteLine(); return textValues; }
public PrintTextValues GetTextValues(IEnumerable <string> texts, string title, bool extractValuesFromText = true) { // read : title // modify : infos, description, language, size, nbPages PrintTextValues textValues = new PrintTextValues(); List <string> description = new List <string>(); _exportDataWriter.zWriteStartDocument(); _exportDataWriter.zWrite("Title", title); _exportDataWriter.zWriteStartArray("Texts"); string name = null; foreach (string s in texts) { _exportDataWriter.zWrite(s); if (__trace) { pb.Trace.WriteLine("SetTextValues : \"{0}\"", s); } string name2; string text2; // Editeur : Presse fr bool textValues2 = false; if (extractValuesFromText) { textValues2 = ExtractTextValues2(s, out name2, out text2); if (s == "\r\n" || textValues2) { if (name != null) { if (__trace) { pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = null", name); } textValues.infos.SetValue(name, null); } name = null; if (textValues2) { if (__trace) { pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name2, text2); } if (text2 != null) { textValues.infos.SetValue(name2, new ZString(text2)); } else { name = name2; } } } } if (!textValues2) { // PDF | 116 pages | 53 Mb | French string s2 = ExtractTextValues(textValues.infos, s); s2 = Trim(s2); if (__trace) { pb.Trace.WriteLine("SetTextValues ExtractTextValues : \"{0}\" - \"{1}\"", s, s2); } if (s2 != "" && s2 != title) { if (s2.StartsWith(title)) { s2 = Trim(s2.Substring(title.Length)); } if (name != null) { if (__trace) { pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = \"{1}\"", name, s2); } textValues.infos.SetValue(name, new ZString(s2)); name = null; } else { NamedValues <ZValue> values = _textInfoRegexList.ExtractTextValues(ref s2); textValues.infos.SetValues(values); if (s2 != "") { if (__trace) { pb.Trace.WriteLine("SetTextValues description.Add : \"{0}\"", s2); } description.Add(s2); } } } } } if (name != null) { if (__trace) { pb.Trace.WriteLine("SetTextValues SetValue : \"{0}\" = null", name); } textValues.infos.SetValue(name, null); } textValues.description = description.ToArray(); _exportDataWriter.zWriteEndArray(); _exportDataWriter.zWriteName("PrintTextValues"); //_exportDataWriter.zWriteStartDocument("PrintTextValues"); _exportDataWriter.zSerialize(textValues); //_exportDataWriter.zWriteEndDocument(); _exportDataWriter.zWriteEndDocument(); _exportDataWriter.zWriteName("fake"); // ??? pour éviter l'erreur : WriteString can only be called when State is Value or Initial, not when State is Name (System.InvalidOperationException) _exportDataWriter.zWriteLine(); return(textValues); }