We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cast to pdfDocument using some converter

Hi ,

I have the following lines of code which I am trying to make it work .

Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(this.fupManualFileUpload.FileContent);


Document pdfDocument = new Document(pdfExtractor.Document.FileName.ToString());


I am unable to get the object pdfDocument from the pdfExtractor .

pdfExtractor is what i have got from the Aspose.Barcode


I even tried out pdfDocument = (Document)pdfExtractor.Document;

post this , I am getting error at the following line :
pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_1A);

Hi Shilpi,


Thanks for your inquiry. I am afraid Aspose.Pdf.Document() can not be cast to PdfExtractor object. However you can use PdfExtractor output image files with Document() object as following.

However please share some more information about your requirements, so we will look into it and guide you accordingly.

PdfExtractor pdfExtractor = new PdfExtractor();<o:p></o:p>

pdfExtractor.BindPdf(myDir + "savetoStream.pdf");

//extract all the images

pdfExtractor.ExtractImage();

int i=1;

//get all the extracted images

while (pdfExtractor.HasNextImage())

{

MemoryStream ms = new MemoryStream();

pdfExtractor.GetNextImage(ms);

Document doc = new Document();

Aspose.Pdf.Page page=doc.Pages.Add();

Aspose.Pdf.Image image = new Aspose.Pdf.Image();

image.ImageStream = ms;

page.Paragraphs.Add(image);

doc.Save(myDir+i+"image.pdf");

ms.Close();

i++;

}


Please feel free to contact us for any further assistance.


Best Regards,

Hi ,

My question is vice versa .

I have the pdfExtractor.Document object with me and I want to cast it pdfDocument object. I did this using following code:

Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(this.fupManualFileUpload.FileContent);
// set page range for image extraction
pdfExtractor.StartPage = 1;

// extract the images
pdfExtractor.ExtractImage();
Document pdfDocument = new Document();
pdfDocument = (Document)pdfExtractor.Document;

I am able to get the pdfDocument object but when i perdorm following validation :


if ((pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_1A)) || (pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_1B)) ||
(pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_2A)) || (pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_2B)) ||
(pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_3A)) || (pdfDocument.Validate(“validation-result-A1A.xml”, PdfFormat.PDF_A_3B)))
{
flag=1;
}


I am gettign the folllowing error - Specified argument was out of the range of valid values.
Parameter name: offset

Hi Shilpi,


Thanks for sharing the details.

The PdfExtractor class is used to extract Text, Image and Attachment objects from PDF file and you cannot directly cast PdfExtractor object to Document instance. However the Document class provides the feature to Extract Text from Pages using Text Device, Extract Images from the PDF File and Get All Attachments from a PDF Document through Document instance and also you can use the same object to Convert PDF File to PDF-A.

Hi,

Please provide me with the code sample … I am facing difficulty in integrating and achieving . I have a limitation that I cant get the value of pdfDocument like this,
Document pdfDocument = new Document(Server.MapPath(savePath1));

I have the value available in the pdfExtractor

pdfExtractor.BindPdf(this.fupManualFileUpload.FileContent);

Thanks,
Shilpi

Hi Shilpi,


Thanks for your sharing sample code. I have tested the code with sample PDF document and it is working fine. Please share your sample document here, we will look into it and will guide you accordingly.

PdfExtractor pdfExtractor = new PdfExtractor();<o:p></o:p>

int flag =0;

pdfExtractor.BindPdf(myDir + "input.pdf");

Document pdfDocument = pdfExtractor.Document;

if ((pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_1A)) || (pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_1B)) ||

(pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_2A)) || (pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_2B)) ||

(pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_3A)) || (pdfDocument.Validate("validation-result-A1A.xml", PdfFormat.PDF_A_3B)))

{

flag = 1;

}

Console.WriteLine(flag);

We are sorry for the inconvenience caused.

Best Regards,