Citește PDF linie Cu Linie folosind iText7 și Umple pe Casete Winforms

0

Problema

Am de lucru pe o aplicație WinForms. Eu folosesc fișier pdf pentru a reseta parola și valorile pe pdf sunt stocate ca perechi cheie-valoare(e-mail: [email protected], pass: 11111).

Ceea ce vreau sa fac:

Citiți fișierul PDF de linie și umplere corespunzătoare casete.

Ce am facut:

public bool CreatePDF(string location, string email, string key)
    {
        if(location != "" && email != "" && key != "")
        {
            PdfWriter pdfwriter = new PdfWriter(location);
            PdfDocument pdf = new PdfDocument(pdfwriter);
            Document document = new Document(pdf);
            Paragraph fields = new Paragraph("Email: "+email + "\n" + "Secret Key: "+key);
            document.Add(fields);
            document.Close();
            return true;
        }            
        else
        {
            return false;
        }
    }

    public string ReadPDF(string location)
    {
        var pdfDocument = new PdfDocument(new PdfReader(location));
        StringBuilder processed = new StringBuilder();
        var strategy = new LocationTextExtractionStrategy();
        string text = "";
        for (int i = 1; i <= pdfDocument.GetNumberOfPages(); ++i)
        {
            var page = pdfDocument.GetPage(i);
            text += PdfTextExtractor.GetTextFromPage(page, strategy);
            processed.Append(text);
        }
        return text;
    }
}

Va multumesc anticipat Baieti!. Orice sugestii cu privire la CreatePDF sunt de asemenea binevenite.

c# pdf winforms
2021-11-22 11:36:14
1

Cel mai bun răspuns

0

Aceasta este ceea ce am venit cu,

var pdfDocument = new PdfDocument(new PdfReader("G:\\Encryption_File.pdf"));
        StringBuilder processed = new StringBuilder();
        var strategy = new LocationTextExtractionStrategy();
        string text = "";
        for (int i = 1; i <= pdfDocument.GetNumberOfPages(); ++i)
        {
            var page = pdfDocument.GetPage(i);
            text += PdfTextExtractor.GetTextFromPage(page, strategy);
            processed.Append(text);                
        }
        text.Split('\n');
        string line = "";                        
        line = text + "&";            
        string[] newLines = line.Split('&'); 
        textBox1.Text = newLines[0].Split(':')[1].ToString(); 
        textBox2.Text = newLines[0].Split(':')[2].ToString();
2021-11-23 02:40:57

În alte limbi

Această pagină este în alte limbi

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................