Per cercare file PDF, utilizzeremo l’API Aspose.PDF che è un’API di manipolazione dei documenti ricca di funzionalità, potente e facile da usare. Apri il gestore di pacchetti NuGet, cerca Aspose.PDF e installa. È inoltre possibile utilizzare il seguente comando dalla console di Package Manager. Quando si firma un documento PDF utilizzando una firma, si conferma sostanzialmente il contenuto «così com’è». Di conseguenza, qualsiasi altra modifica apportata successivamente invalida la firma e quindi, sapresti se il documento è stato alterato.
Cerca un documento PDF senza aprirlo usando.NET:
- Crea un oggetto TextFragmentAbsorber con il testo da trovare come parametro.
- Ottieni la raccolta di tutti i frammenti di testo estratti.
- Scorri ogni frammento per ottenere tutte le informazioni.
Cerca file PDF
//Search Text from All the Pages of PDF Document
Document pdfDocument = new Document("SearchAndGetTextFromAll.pdf");
// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text");
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
// Get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
// Loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
Console.WriteLine("Text : {0} ", textFragment.Text);
Console.WriteLine("Position : {0} ", textFragment.Position);
Console.WriteLine("XIndent : {0} ", textFragment.Position.XIndent);
Console.WriteLine("YIndent : {0} ", textFragment.Position.YIndent);
Console.WriteLine("Font - Name : {0}", textFragment.TextState.Font.FontName);
Console.WriteLine("Font - IsAccessible : {0} ", textFragment.TextState.Font.IsAccessible);
Console.WriteLine("Font - IsEmbedded : {0} ", textFragment.TextState.Font.IsEmbedded);
Console.WriteLine("Font - IsSubset : {0} ", textFragment.TextState.Font.IsSubset);
Console.WriteLine("Font Size : {0} ", textFragment.TextState.FontSize);
Console.WriteLine("Foreground Color : {0} ", textFragment.TextState.ForegroundColor);
}