Hi,
Hi John,
Thank you for considering Aspose.Pdf for .NET.
I think you may try Facades.PdfFileSecurity
to decrypt the file first and then check / extract the images from the Pdf file.
Please see the following sample code and let us know if it fits your needs:
FileStream inputStream = new FileStream(@"D:\AP Data\Source_Files\input.pdf", FileMode.Open);
MemoryStream outputStream = new MemoryStream();
PdfFileSecurity fileSecurity = new PdfFileSecurity(inputStream, outputStream);
fileSecurity.DecryptFile("abc123");
//open input PDF
PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.BindPdf(outputStream);
//extract images
pdfExtractor.ExtractImage;
//get extracted images
while (pdfExtractor.HasNextImage())
{
//read image into memory stream
MemoryStream memoryStream = new MemoryStream();
pdfExtractor.GetNextImage(memoryStream);
//write to disk, if you like, or use it otherwise.
FileStream fileStream = new FileStream(
@"D:\AP Data\Source_Files\" + DateTime.Now.Ticks.ToString() + ".jpg",
FileMode.Create);
memoryStream.WriteTo(fileStream);
fileStream.Close();
}
Thank You & Best Regards,
Thanks Nausherwan,
Hi John,
I think you may try to navigate through pages and check the Page.Resources.Images
to get your desired result. Please see the following sample code in this regard:
FileStream inputStream = new FileStream(@"D:\AP Data\Source_Files\input.pdf", FileMode.Open);
MemoryStream outputStream = new MemoryStream();
PdfFileSecurity fileSecurity = new PdfFileSecurity(inputStream, outputStream);
fileSecurity.DecryptFile("abc123");
//open document
Document pdfDocument = new Document(outputStream);
//get the page where image needs to be added
foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
//check image count in Images collection of Page Resources
if (page.Resources.Images.Count > 0)
{
//Your Code Here If Image Exists
}
}
If you need any further assistance, please feel free to contact support.
Thank You & Best Regards,