Invalid index: index should be in the range [1..n] where n equals to the pages count

Hello,

I am getting this below error while i am trying to download pdf code.
Error - Invalid index: index should be in the range [1…n] where n equals to the pages count.

Used code -

<?php require_once DIR . '/vendor/autoload.php'; require_once DIR . '/Utils.php'; use Aspose\PDF\PdfApi; use Aspose\PDF\AsposeApp; class Text { public $pdfApi; public function __construct() { AsposeApp::$appSID = Utils::appSID; AsposeApp::$apiKey = Utils::apiKey; $this->pdfApi = new PdfApi(); } public function postDocumentReplaceTextList() { // Upload file to Aspose Cloud Storage $fileName = "Example.pdf"; Utils::uploadFile($fileName); $body = array('TextReplaces' => array(array('OldValue' => "05/30/2017", 'NewValue' => "09/07/2018", 'Regex' => true), array('OldValue' => "Cable ID", 'NewValue' => "Jayendra", 'Regex' => true))); $result = $this->pdfApi->PostDocumentReplaceTextList($fileName, $storage = "", $folder = "", $body); //echo "
"; print_r ( $result ); die();
  if(!empty($result))
  {
   //$result = $this->pdfApi->GetTextItems($fileName, $withEmpty = "", $storage = "", $folder = "");
   //echo "
"; print_r ( $result ); die();
   //$jsresp = $this->pdfApi->GetDocumentAttachments($fileName, $storage = "", $folder = "");
   $jsresp = $this->pdfApi->GetDownloadDocumentAttachmentByIndex($fileName, 1, $storage = "", $folder = "");
   echo "
"; print_r($jsresp); 
  }else
  {
   echo "not";
  }
 }
}

$text = new Text();
$text->postDocumentReplaceTextList();
?>

Even i am using default api code for download pdf.

Here is below code -

public function getDownloadDocumentAttachmentByIndex() {
// Upload file to Aspose Cloud Storage
$fileName = “SampleAttachment.pdf”;
Utils::uploadFile($fileName);
$result = $this->pdfApi->GetDownloadDocumentAttachmentByIndex($name=$fileName, $attachmentIndex=1, $storage = “”, $folder = “”);
print_r ( $result );
}

@rahuliitm69

Thanks for contacting support.

By looking at the error message, it seems that an invalid index has been passed to access the page from Aspose.Pdf.Pages Collection, as it is quite possible that the PDF, which is being used for TextReplacement, contains no pages. Please note that the indices for Page Collection start from 1, as it is also mentioned in the error description.

Would you please double check the file, being used, over your end and in case you keep experiencing same issue, please share a sample document with us. We will test the scenario in our environment and address it accordingly.

Hello Asad

Thanks for reply.

I am using Example.pdf file for testing.

Text Replacement works fine, after text replacement when i am getting text of pdf it shows new words which i replaced.

But after that when i am downloading the pdf file then error will occur.

I also tried it with “SampleAttachment.pdf” but it give same error.

I also tried this code without TextReplacement but it give same error.

If you find any solution then please provide me code.

Files are attached below.

<?php public function getDownloadDocumentAttachmentByIndex() { // Upload file to Aspose Cloud Storage $fileName = "SampleAttachment.pdf"; Utils::uploadFile($fileName); $result = $this->pdfApi->GetDownloadDocumentAttachmentByIndex($name=$fileName, $attachmentIndex=3, $storage = "", $folder = ""); echo "
"; print_r ( $result );
	}
}

$attachment = new Attachment();
$attachment->getDownloadDocumentAttachmentByIndex();
?>

Example.pdf (301.4 KB)
SampleAttachment.pdf (179.4 KB)

@rahuliitm69

Thanks for providing requested details.

We are looking into the scenario and will get back to you shortly. Please be patient and spare us little time.

Still waiting for solution.

@rahuliitm69

Thanks for your patience and sorry for the delay.

We are working over setting up the things, in order to test the complete scenario, and will try to get back to you by tomorrow, with our findings. Please spare us little time.

We are sorry for the inconvenience.

Hello Asad,
Thank you for your response. but i need to fix this issue on urgent basis so please help me out asap.
It will be really great favor for me if you tell me solution of this problem asap. I am really waiting for your response.

@rahuliitm69

Thanks for your patience.

We have tested the scenario in our environment with PDF, Ruby and .NET examples, and observed same error in the response. When we ran getDocumentAttachments method of the API the response was as follows:

{"Attachments":{"List":[],"Links":[{"Href":"http://api.aspose.cloud/v1.1/pdf/TestForAnnot.pdf/attachments","Rel":"self","Type":null,"Title":null}]},"Code":200,"Status":"OK"}

As you can see that, API was returning the attachment list as null, whereas we have tried above method with a valid PDF file having valid attachment. However, we have logged an issue in our issue tracking system, for the sake of detailed investigation. We will further look into the details of this issue and keep you informed with the status of its correction. Please be patient and spare us little time.

We are sorry for this inconvenience.