75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using DevExpress.Pdf;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BeWo.Service.Import.AvisImport
|
|
{
|
|
public class LvrAvisPdfReader
|
|
{
|
|
public List<Avis> LeseAvise(byte[] daten)
|
|
{
|
|
List<Avis> avise = new List<Avis>();
|
|
|
|
using (var processor = new PdfDocumentProcessor())
|
|
{
|
|
using (var ms = new MemoryStream(daten))
|
|
{
|
|
processor.LoadDocument(ms);
|
|
|
|
var pdfText = processor.Text;
|
|
|
|
var klientenListe = CreateKlientenBereiche(pdfText);
|
|
foreach (var kg in klientenListe)
|
|
{
|
|
avise.AddRange(kg.LeseEinzelAvise());
|
|
}
|
|
}
|
|
}
|
|
|
|
return avise;
|
|
|
|
}
|
|
|
|
private List<LvrAvisKlientGesamt> CreateKlientenBereiche(string pdfText)
|
|
{
|
|
var bereiche = new List<LvrAvisKlientGesamt>();
|
|
|
|
var lines = pdfText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
int index = 0;
|
|
|
|
while (index < lines.Length)
|
|
{
|
|
var line = lines[index++];
|
|
if (line.StartsWith("GP:"))
|
|
{
|
|
String aktenzeichen = line.Replace("GP:", "").Trim();
|
|
StringBuilder textBereich = new StringBuilder();
|
|
textBereich.AppendLine(line);
|
|
|
|
var bereich = new LvrAvisKlientGesamt();
|
|
bool endeBereich = false;
|
|
while (index < lines.Length && !endeBereich)
|
|
{
|
|
line = lines[index++];
|
|
textBereich.AppendLine(line);
|
|
if (line.Contains("Gesamtsumme") && line.Contains(aktenzeichen))
|
|
{
|
|
endeBereich = true;
|
|
bereich.GesamtText = textBereich.ToString();
|
|
bereiche.Add(bereich);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return bereiche;
|
|
}
|
|
|
|
}
|
|
}
|