ilovepdf / ilovepdf-php

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

Set opacity is not working #15

Closed divsbhalala closed 6 years ago

divsbhalala commented 6 years ago

Set opacity is not working while adding image into watermark task Please test here https://www.tweak.com/add-watermark-pdf/

divsbhalala commented 6 years ago

Here is my code

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->setOpacity($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;
}
maztch commented 6 years ago

Sorry, but I checked it right now and it's working...in our api and in your implementation.

What image are you using? Can you add it here?

divsbhalala commented 6 years ago

66 caheranne I am using this image

divsbhalala commented 6 years ago

Product List Instruction.pdf And Using this PDF

divsbhalala commented 6 years ago

Product-List-Instruction_9475640_05-12-2017_watermark_image.pdf Ia m getting this PDF as output

maztch commented 6 years ago

Ok, it's a cmyk image. Your code is correct. We are solving it on our api servers.

divsbhalala commented 6 years ago

Ok thanks

maztch commented 6 years ago

Done, try it now.

divsbhalala commented 6 years ago

ok let me check