ilovepdf / ilovepdf-php

iLovePDF Rest Api - PHP Library (https://developer.ilovepdf.com)
146 stars 39 forks source link

Add watermark text to center of the PDF is not working #9

Closed divsbhalala closed 6 years ago

divsbhalala commented 6 years ago

Hello Add watermark to the center of the PDF is not working. here are the Params that I am passing to the Request http://prntscr.com/h6wkz0

Here is the function for that.

    public function addWatermarkToPdf($files, $watermark_type='text', $watermark_text='', $watermark_image='', $fontSize=18, $fontColor='#000',
$fontFamily='courier', $range='all', $horizontalPosition='left', $verticalPosition='bottom', $opacity=50, $page_layer_pos='bottom', $watermark_rotation=35, $rotation=[], $name, $pkjFileName){
    $watermark = new WatermarkTask( $this->publicKey, $this->secretKey );
    foreach ($files as $key => $file) {
        $fileA = $watermark->addFile($file);
        $fileA->setRotation($rotation[$key] ? $rotation[$key] : 0);
    }
    // $fileA = $watermark->addFile($pdfFilePath);

    if($watermark_type=='text'){
        $watermark->setText($watermark_text);
        $watermark->setFontFamily($fontFamily);
        $watermark->setFontSize($fontSize);
        $watermark->setFontColor($fontColor);
    }
    else if(!empty($watermark_image)){
        $watermark->setMode('image');
        //$watermark->setImage($img);
        $image = $watermark->addFile($watermark_image);
        $watermark->setImage($image->server_filename);
    }

    // $watermark->setMosaic(true);
    $watermark->setPages($range);
    $watermark->setHorizontalPosition($horizontalPosition);
    $watermark->setVerticalPosition($verticalPosition);
    $watermark->setTransparency($opacity);
    $watermark->setLayer($page_layer_pos);
    $watermark->setRotation($watermark_rotation);

    $watermark->setOutputFilename($name);
    $watermark->setPackagedFilename($pkjFileName);
    // print_r($watermark);
    $watermark->execute();
    // print_r($watermark);
    return $watermark;
}

and on output response I an getting this PDF https://www.tweak.com/wp-content/uploads/pdf/20539441-8_9953793_06-11-2017_watermark_text.pdf

divsbhalala commented 6 years ago

For testing this functionality you can check here https://www.tweak.com/add-watermark/?v=2.1

maztch commented 6 years ago

Hello divsbhalala, Your code is correct. It's a problem in our binaries in api server. We are looking to solve it right now. I'll comment this thread once we solve it. Thanks!

divsbhalala commented 6 years ago

@maztch thanks for back to me. Please let me know ASAP when the issue is resolved.

maztch commented 6 years ago

Solved