ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Save PDF as Text (txt) File in ASP.Net using C# and VB.Net<p>Hey <a class="username" rel="Vikash21">Vikash21</a>,</p> <p>Please refer below code.</p> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.IO; using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.IO Imports iTextSharp.text.pdf.parser Imports iTextSharp.text.pdf</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { ReadPdfFile(); } public void ReadPdfFile() { string path = @&#34;D:\File\File.txt&#34;; StringBuilder sb = new StringBuilder(); foreach (string file in Directory.GetFiles(@&#34;D:\\Folder\&#34;, &#34;*.pdf&#34;)) { PdfReader pdfReader = new PdfReader(file); for (int page = 1; page &lt;= pdfReader.NumberOfPages; page++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy); string[] theLines = currentText.Split(&#39;\n&#39;); foreach (var theLine in theLines) { sb.AppendLine(theLine); } } } File.WriteAllText(path, sb.ToString()); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load ReadPdfFile() End Sub Public Sub ReadPdfFile() Dim path As String = &#34;D:\File\File.txt&#34; Dim sb As StringBuilder = New StringBuilder() For Each file As String In Directory.GetFiles(&#34;D:\\Folder\&#34;, &#34;*.pdf&#34;) Dim pdfReader As PdfReader = New PdfReader(file) For page As Integer = 1 To pdfReader.NumberOfPages Dim strategy As ITextExtractionStrategy = New SimpleTextExtractionStrategy() Dim currentText As String = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy) Dim theLines As String() = currentText.Split(vbLf) For Each theLine In theLines sb.AppendLine(theLine) Next Next Next File.WriteAllText(path, sb.ToString()) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><strong>Pdf</strong></p> <p><span style="text-decoration: underline;"><strong><img src="https://imgur.com/bSPMRyw.jpg" alt="" width="472" height="176" /></strong></span></p> <p><strong>Notepad</strong></p> <p><strong><img src="https://imgur.com/hOS9UQf.jpg" alt="" width="253" height="131" /></strong></p>https://www.aspforums.net:443/Threads/195625/Save-PDF-as-Text-txt-File-in-ASPNet-using-C-and-VBNet/https://www.aspforums.net:443/Threads/195625/Save-PDF-as-Text-txt-File-in-ASPNet-using-C-and-VBNet/Mon, 26 Nov 2018 05:39:38 GMT