0

" i have uploaded a file on server i want when a user from my website download this file he should be a watermarked file (watermark text will be 'his email id' in pdf file) "

Controller:

public function actionDownloadFiles()
{
     ignore_user_abort(true);

     $path =  ( Yii::app()->basePath.'/../images/prequlification_form/'.$_GET['path'] );
      $fullPath = $path ;
     if ($fd = fopen ($fullPath, "r")) {
      $fsize = filesize($fullPath);
      $path_parts = pathinfo($fullPath);

      header("Content-type: application/octet-stream");
      header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");

      header("Content-length: $fsize");
      header("Cache-control: private");
      while(!feof($fd)) {
       $buffer = fread($fd, 2048);
       echo $buffer;
      }
     }
     fclose ($fd);
     exit;
}

View:

<h3><p class="note"><span class="required">form</span> Filling is  required.</p></h3>
    <?php echo $form->errorSummary($model); ?>
    <!--here is the user id-->
    <?php //echo $id;?>
    <div class="file-dwnload">
    <?php 
    $data=prequalificationForm::model()->findByPk(1);
    if(!empty($data))  {

     echo '<div class="dwnload-file"><li>'.
                 CHtml::link( $data->file_path,array("prequalificationForm/downloadFiles","path"=>($data->file_path))).

       '</li></div> <div class="dwnload-butn"><li>'.
        CHtml::link('Download File',array("prequalificationForm/downloadFiles","path"=>($data->file_path)))
      ."</li></div> " ;
   }?></div>

    <div class="row">
        <?php echo $form->labelEx($model,'file_path'); ?>
        <?php echo $form->fileField($model,'file_path',array('size'=>60,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'file_path'); ?>
    </div>

    <div class="row buttons">
        <?php //echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save',array('class'=>'submit-btn')); ?>
    </div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Sandeep Jindal
  • 14,510
  • 18
  • 83
  • 121

1 Answers1

0

So you want to watermark the pdf with some data from the user.

You would have some options to do that.

The easier would be if you don't do it on a uploaded file, instead you generate html content and convert html to pdf on the fly.

But if you need to do it on a uploaded file, maybe this could help you: Writing/Drawing over a PDF template document in PHP

Community
  • 1
  • 1