Overlay image in PDF document issue with PHP using GroupDocs.Annotation REST API

I’m adding an image or adding a logo, on the top of the existing logo within the document using the annotation PHP SDK.
It does not replace the image, even the image which I’m using, having a white background.
Ideally, it should have replaced the existing logo image with the new image logo.

There is one more line that gets highlighted for annotate comment. (actually, there isn’t any comment).

Attaching the doc for the reference
WRTSC-1286956274-10_Gr5TheEiffelTower_2.pdf (546.3 KB)

@tilalahmad can you please help here?

@gopalsharma

I am afraid I can not notice any annotation(comment) in the PDF document. Please share your input document and sample code. I will look into the issue and will suggest you accordingly.

@tilal.ahmad
You can not notice any annotation(comment), because you are viewing a pdf document instead of MS Word.
So all I need to do is to replace the logo. I need to add Red log on top of the existing Blue logo in a way that Red logo completely hides the Blue logo. Please, Let me know if you are not clear with it.

I’m adding both the document, the original document, and the annotation processed document.

Original Docs Uploading: WRTSC-1286956274-10_Gr5TheEiffelTower (1).docx…
After annotation Docs: WRTSC-1286956274-10_Gr5TheEiffelTower_2 (3).docx (746.2 KB)

Following is the code I’m using
try {
$apiInstance = self::GetAnnotationApiInstance();

            $a = new GroupDocs\Annotation\Model\AnnotationInfo();
            $pt = new GroupDocs\Annotation\Model\Point();
            $pt->setX(1);
            $pt->setY(1);
            $a->setAnnotationPosition($pt);
            $box = new GroupDocs\Annotation\Model\Rectangle();
            $box->setX(50);
            $box->setY(50);
            $box->setWidth(160;
            $box->setHeight(100);
            $a->setBox($box);
            $a->setPageNumber(0);
            $a->setImagePath("logoimage.png");
 
            $a->setPenStyle(GroupDocs\Annotation\Model\AnnotationInfo::PEN_STYLE_SOLID);
            $a->setOpacity(1);
            $a->setType(GroupDocs\Annotation\Model\AnnotationInfo::TYPE_IMAGE);
            //$a->setText("This is image annotation");
            //$a->setCreatorName("Anonym A.");   

            $options = new GroupDocs\Annotation\Model\AnnotateOptions();
            $options->setFileInfo($fileInfo);
            $options->setAnnotations([$a]);

            $file = pathinfo($filename, PATHINFO_FILENAME);
            $fileextn = pathinfo($filename, PATHINFO_EXTENSION);

            $options->setOutputPath("Output\\WRTSC-1286956274-10_Gr5TheEiffelTower_2.docx");
            
            $request = new GroupDocs\Annotation\Model\Requests\annotateRequest($options);
            $result = $apiInstance->annotate($request);
            
            echo "AddImageAnnotation: Image Annotation added: " . $result->getHref();
        } catch (Exception $e) {
            header('HTTP/1.1 500 Internal Server error');
            header('Content-Type: application/text; charset=UTF-8');
            die($e->getMessage());
            //PHP_EOL;
        }

There is one more option
$a->backgroundColor(“White”);
Don’t know, if I can make use of that.

1 Like

@tilal.ahmad any update on this?

I manage to resolve it to some extent when adding image to pdf file.
So, first I convert it to pdf from docx and then add the logo.

Only problem left is added logo image show up a rectangle border. I just need to get rid of the borderline.
DO you have any idea, how can I achieve that.
attaching the document for the refrence 2 I Shooting stars Booklet PAPER Doc (6).pdf (1.1 MB)

1 Like

@gopalsharma

Thanks for sharing the additional information. I have noticed the issue and logged an improvement ticket(ANNOTATIONCLOUD-131) for further investigation and resolving the issue.

1 Like

@gopalsharma

It seems a PDF viewer issue as when I open it on my end using Adobe Acrobat Pro it does not show any border.

@tilal.ahmad
I can see the black outlined, when openinig the doucment with web browser. Most of our user could be using a browser to view the document. Please check that, if you can resolve the issue at you end.
Thanks!!

1 Like

@gopalsharma

We have logged a ticket ANNOTATIONCLOUD-132 to investigate the issue. We will keep you updated about the issue resolution progress.

However, as a workaround you can change the default PDF Viewer in the browser, it will fix the issue.

@tilal.ahmad
This soultion is not working for us, overlaying a image not perfact most of the time.

Can you please help me with “Replace a image in Word or PDF document” using groupDocs API?
Is this even possible using GroupDocs API?

Thank you,
Gopal

@gopalsharma

About the black border issue in browser, I am afraid we are unable to fix it at our side because showing this border depends on viewer settings or behavior that how it will show certain elements inside the PDF documents. We mimics the behavior of Adobe Reader and follows its standards.

So if annotation border is showing in Chrome or Edge, it is their own settings and behavior and has nothing to do with out API.

I am afraid GroupDocs API does not provide option to replace image in a document.

In fix of ANNOTATIONCLOUD-131 we will provide you a solution to overlay an image in a document with better control.

The issues you have found earlier (filed as ANNOTATIONCLOUD-131) have been fixed in this update. This message was posted using Bugs notification tool by sergeiterentev

@gopalsharma

As stated above, your reported issue(ANNOTATIONCLOUD-131) is resolved in GroupDocs.Annotation Cloud 21.6 release. We have introduced the ZIndex property in this release. Now you can set ZIndex value > 1 to get the image on top as follows. Hopefully, it will help you to accomplish the task.

$a->setZIndex(3);
1 Like