보세요 라인으로 라인을 사용하여 iText7 고 채우기 상자에 Winforms

0

질문

나는 WinForms 응용 프로그램. 내가 사용하는 pdf 파일을 암호를 다시 설정 값에서 pdf 파일로 저장되는 키 값 쌍(이메일:[email protected] 통:11111).

내가 무엇을 하고 싶:

읽 PDF 파일을 줄고 채우기 위해 적당한 텍스트 상자.

내가 무엇을 했:

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;
    }
}

사전에 감사들!. 에 어떤 제안이 CreatePDF 도 환영합니다.

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

최고의 응답

0

이것은 무엇을 내놓았,

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

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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