2
Is it possible to do this or do I really have to extract the file before to later read it?
In my code I’m doing so:
string zipPath = @"C:\Users\Analistas\Desktop\ZipFile.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
var sample = archive.GetEntry("PdfFile.pdf");
string pdfContent = ReadPdfFile("PdfFile.pdf");
if (sample != null)
{
using (var zipEntryStream = sample.Open())
{
MessageBox.Show(pdfContent);
}
}
}
And the method to read PDF:
public string ReadPdfFile(string fileName)
{
StringBuilder text = new StringBuilder();
if (File.Exists(fileName))
{
PdfReader pdfReader = new PdfReader(fileName);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
}
pdfReader.Close();
}
return text.ToString();
}
It’s not showing anything.
I believe that by
fileName
, would have to extract a stream and build a pdf clone from it.– Leandro Angelo