Giter VIP home page Giter VIP logo

document-watermark's Introduction

Document Watermark

Latest Stable Version Total Downloads License

Generate text watermark on PDF and Word documents

Installation

Install document-watermark via composer

  $ composer require yasapurnama/document-watermark

Examples

Generate word document watermark. Using default section footer, text align right, font color 000000 and font size 10

$wordWatermark = WatermarkFactory::load(__DIR__ . '/files/word-sample.docx')
                            ->subDirectory('watermark')
                            ->setText('Last update on ' . date('m/d/Y'))
                            ->generate();

example-word-watermark

Generate PDF watermark with custom options

$pdfWatermark  = WatermarkFactory::load(__DIR__ . '/files/pdf-sample.pdf')
                            ->subDirectory('watermark')
                            ->setText('Last update on ' . date('m/d/Y'))
                            ->sectionHeader()
                            ->alignRight()
                            ->fontSize(9)
                            ->fontColor('ff0000')
                            ->generate();

example-pdf-watermark

Image watermark

Generate word document watermark using image at footer, with page margins x=1 y=1, align right, only in first page

$wordWatermark = WatermarkFactory::load(__DIR__ . '/files/word-sample.docx')
                            ->outputFile(__DIR__ . '/files/watermark/word-image-stamp-custom.docx')
                            ->setImage(__DIR__ . '/files/stamp.png')
                            ->sectionFooter(1, 1)
                            ->alignRight()
                            ->onlyFirstPage()
                            ->generate();

example-word-image-stamp

Generate pdf document watermark using image with default values

$pdfWatermark  = WatermarkFactory::load(__DIR__ . '/files/pdf-sample.pdf')
    ->outputFile(__DIR__ . '/files/watermark/pdf-image-stamp.pdf')
    ->setImage(__DIR__ . '/files/stamp.png')
    ->generate();

example-pdf-image-stamp

Contribute

Just submit pull request, your contributions are always welcomed!

Credits

This project was inspired by ajaxray's and using markpdf as depedencies.

document-watermark's People

Contributors

g-theodoroy avatar yasapurnama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

deawx yqhong606

document-watermark's Issues

PDF which name has space(s) would fail the command execution

Problem

Generating watermark on a PDF document which name has space(s) fails the command execution. I have not try this on a Word file.

Reproduce

$document = 'pdf doc with spaces.pdf';
WatermarkFactory::load($document)->setText('simple watermark')->generate();  // returns empty string instead

Temporary Solution

Using escapeshellarg() PHP function on getCommand() function on Yasapurnama\DocumentWatermark\PDFWatermark class.

// Yasapurnama\DocumentWatermark\PDFWatermark

...
        if ($this->image) {
            return sprintf(
                '%s %s %s %s %s %s',
                $this->getBinExecutable(),
                escapeshellarg($this->documentPath),  // escape the path as shell argument
                escapeshellarg($this->image),  // escape the path as shell argument
                escapeshellarg($this->outputFile),  // escape the path as shell argument
                $this->getPositionOption(),
                $this->getOpacityOption()
            );
        }

        return sprintf(
            '%s %s "%s" %s %s %s %s',
            $this->getBinExecutable(),
            escapeshellarg($this->documentPath),  // escape the path as shell argument
            $this->text,
            escapeshellarg($this->outputFile),  // escape the path as shell argument
            $this->getFontColorOption(),
            $this->getFontSizeOption(),
            $this->getPositionOption()
        );
...

Watermark with Image

Dear yasapurnama

It would be helpfull to add capability watermark with Image

I am from Greece and Greek language chars don't print when setText()

I made some tests and it can be done

Add please

setImage()
setOpacity()

and when generate()

if isset(text) getCommant() to watermark text
if isset(image) getCommant() to watermark image

maybe you could

setX()
setY()

so someone can give other values of the default.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.