Skip to content

Commit

Permalink
Text Position related update
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaxray committed Jan 19, 2019
1 parent 0c2ec52 commit af04428
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x -20 -y 20 -o
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --offset-x=100 --offset-y=-100 --angle=45
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x 100 -y -100 -a 45

# stretch full with of page at page middle
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --scale-width-center
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -W
# stretch full with of page at page middle, with 30% opacity
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --scale-width-center --opacity=0.3
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -Wo 0.3
# Note the capital "W"

# stretch full with of page at page bottom
Expand All @@ -60,31 +60,54 @@ markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -wy -10

### Text watermarking

> Note : Text watermarking is not completed yet.
```bash
# watermark text at right top with 20px offset from edge
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --offset-x=-20 --offset-y=20
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -x -20 -y 20

# Place text at center with bold-italic "Times Roman" font in blue color
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --color=0000FF
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -l 0000FF

# Place text at center with large bold-italic "Times Roman" font in blue color
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --font-size=24.0 --color=0000FF
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -s 24.0 -l 0000FF
```


#### Allowed font identifiers

Currently the following font names are supported:
- **Courier**: `courier`, `courier_bold`, `courier_oblique`, `courier_bold_oblique`
- **Helvetica**: `helvetica`, `helvetica_bold`, `helvetica_oblique`, `helvetica_bold_oblique`
- **Times Roman**: `times`, `times_bold`, `times_italic`, `times_bold_italic`

### Additional notes

- **Specifying Colors**: write them as 6 or 3 digit hexadecilal as used in CSS, without the #
- Allowed font specifiers
- Negaive offset will set content positioning from opposite side (right for offsetX and botom from offsetY)
- Text with opacity is not supported at this moment. Instead, you can create a transperent background PNG image with your text and then use it for watermarking.

- `--color`, `--font` and `--font-size` flag has no impact for Image watermarking
- `--scale-*` and `--opacity` flag has no impact for Text watermarking
- Negative offset will set content positioning from opposite side (right for offsetX and botom from offsetY)
- Text with opacity is not supported at this moment. Instead, you can [create a transperent background PNG image](http://www.picturetopeople.org/text_generator/others/transparent/transparent-text-generator.html) with your text and then use it for watermarking.

## Roadmap

✅ Draw image on every page of PDF
✅ Configure Opacity option
✅ Configure watermark position by X and Y offset
✅ Allow negative values to for offset to adjust from opposite direction
✅️ Easy option for positioning at center
✅ Configure rotation angle
✅ Options to Stretch watermark to width or height, proportionately
✅ Options to Stretch watermark to width or height at the middle of page
◻️ Render text on every page
◻️ Configure text color, style and font
✅️ Easy option for positioning image at center
✅ Configure image rotation angle
✅ Options to Stretch watermark to page width or height, proportionately
✅ Options to Stretch watermark to page width or height at the middle of page
◻️ Tile Image all over the page
✅ Render text on every page
✅ Configure text color, style and font
◻️ Configure text opacity
◻️ Configure text rotation angle
◻️ Text placement by offset
◻️ Put text at page center
Configure text rotation angle
Text placement by offset
Put text at page center

### Contribute

Expand Down
14 changes: 6 additions & 8 deletions text_watermark.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ func adjustTextPosition(p *creator.Paragraph, c *creator.Creator) {
p.SetEnableWrap(false)

if center {
// To set text at middle, widthining the paragraph to page width and setting center allignment
// then placing the box at left side of the page
p.SetWidth(c.Context().PageWidth)
p.SetWidth(p.Width()) // Not working without setting it manually
p.SetTextAlignment(creator.TextAlignmentCenter)
offsetX = 0

offsetX = (c.Context().PageWidth / 2) - (p.Width() / 2)
offsetY = (c.Context().PageHeight / 2) - (p.Height() / 2)
} else {
if offsetX < 0 {
// To set text from right side, widthining the paragraph to (page width - preferred offset)
// then placing the box at left side of the page
p.SetWidth(c.Context().PageWidth - math.Abs(offsetX))
p.SetWidth(p.Width()) // Not working without setting it manually
p.SetTextAlignment(creator.TextAlignmentRight)
offsetX = 0

offsetX = c.Context().PageWidth - (math.Abs(offsetX) + p.Width())
}
if offsetY < 0 {
offsetY = c.Context().PageHeight - (math.Abs(offsetY) + p.Height())
Expand Down

0 comments on commit af04428

Please sign in to comment.