Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Um arquivo PDF pode conter tanto texto quanto imagens. Às vezes, um usuário pode precisar descobrir se um arquivo PDF contém apenas texto ou se contém apenas imagens. Também podemos descobrir se contém ambos ou nenhum.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CheckIfPdfContainsTextOrImages()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Instantiate a memoryStream object to hold the extracted text from Document
using (var ms = new MemoryStream())
{
// Create the PdfExtractor
using (var extractor = new Aspose.Pdf.Facades.PdfExtractor())
{
// Bind PDF document
extractor.BindPdf(dataDir + "FilledForm.pdf");
// Extract text from the input PDF document
extractor.ExtractText();
// Save the extracted text to a text file
extractor.GetText(ms);
// Check if the MemoryStream length is greater than or equal to 1
bool containsText = ms.Length >= 1;
// Extract images from the input PDF document
extractor.ExtractImage();
// Calling HasNextImage method in while loop. When images will finish, loop will exit
bool containsImage = extractor.HasNextImage();
// Now find out whether this PDF is text only or image only
if (containsText && !containsImage)
{
Console.WriteLine("PDF contains text only");
}
else if (!containsText && containsImage)
{
Console.WriteLine("PDF contains image only");
}
else if (containsText && containsImage)
{
Console.WriteLine("PDF contains both text and image");
}
else if (!containsText && !containsImage)
{
Console.WriteLine("PDF contains neither text or nor image");
}
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.