Forum Discussion
- shankar_rCommunity Hero
I use below code to get images from PDF document, this may help you
var pdfObject = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(fileName); var pageArray = pdfObject.getDocumentCatalog().getAllPages().toArray(); // Get the collection of pages var curPage = pageArray.oleValue[1];//use page number here var arrofImages = curPage.getResources().getImages().values().toArray(); for(p = 0 ; p < arrofImages.length ; p++) { var curImage = arrofImages.items(p); }
- jasmeenkaur27Contributor
Hi,
Thanks for the help. I am getting the an error : Object doesn't support this property or method
function test()
{
strPDFPath = "J:\\Documents\\PV.ps.pdf"
strImagePath = "J:\\Documents\\expectedgrapgh.png"
objFile = JavaClasses.java_io.File.newInstance(strPDFPath)
objDoc = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_2(objFile);
arrPages = objDoc.getDocumentCatalog().getPages();
//var pageArray = pdfObject.getDocumentCatalog().getAllPages().toArray(); // Get the collection of pages
for(var i=1; i<=arrPages.getCount(); i++)
{
pageObj = objDoc.getPage(i);
arrofImages = pageObj.getResources().getImages().values().toArray(); //getting error at this line
imgMap = pageObj.getResources().getXObject();
imgArray = imgMap.values().toArray();
//imageObj = imgArray.items(imgIndex);
for(var j = 0 ; j < imgArray.length ; j++)
{
curImage = imgArray.items(p);
- AlexKaras
Champion Level 3
a) It might help if you let us know where the mentioned error occurs;
b) The following threads might help:
Getting exception while trying to read PDF file using pdfbox dll
http://community.smartbear.com/t5/Functional-Web-Testing/Getting-exception-while-trying-to-read-PDF-file-using-pdfbox-dll/td-p/85511
http://smartbear.com/forums/f81/t88540/getting-exception-while-trying-to-read-pdf-file/
how to get the content of a pdf file on window (PDFBox)
https://community.smartbear.com/t5/TestComplete-Desktop-Testing/Compare-pdf-files/m-p/122339
http://community.smartbear.com/t5/Functional-Web-Testing/how-to-get-the-content-of-a-pdf-file-on-window/td-p/60183
http://smartbear.com/forums/f75/t61368/how-to-get-the-content-of-a-pdf-file-on-window/
Unable to read pdf : “dotNET.org_apache_pdfbox_pdmodel.PDDocument” is null or not an object
http://community.smartbear.com/t5/Functional-Web-Testing/Unable-to-read-pdf-dotNET-org-apache-pdfbox-pdmodel-PDDocument/td-p/94722> var curImage = arrofImages.items(p);
Wondering in what format the image is stored to the curImage variable? Is it Base64 encoded byte array or something else? Have you tried (and, hopefully succeeded in) to convert it to something compatible with TestComplete's Picture object?