Skip to content

Commit af04428

Browse files
committed
Text Position related update
1 parent 0c2ec52 commit af04428

2 files changed

Lines changed: 45 additions & 24 deletions

File tree

‎README.md‎

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x -20 -y 20 -o
4848
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" --offset-x=100 --offset-y=-100 --angle=45
4949
markpdf "path/to/source.pdf" "img/logo.png" "path/to/output.pdf" -x 100 -y -100 -a 45
5050

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

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

6161
### Text watermarking
6262

63-
> Note : Text watermarking is not completed yet.
63+
```bash
64+
# watermark text at right top with 20px offset from edge
65+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --offset-x=-20 --offset-y=20
66+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -x -20 -y 20
67+
68+
# Place text at center with bold-italic "Times Roman" font in blue color
69+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --color=0000FF
70+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -l 0000FF
71+
72+
# Place text at center with large bold-italic "Times Roman" font in blue color
73+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" --center --font=times_bold_italic --font-size=24.0 --color=0000FF
74+
markpdf "path/to/source.pdf" "The Company Name" "path/to/output.pdf" -cf times_bold_italic -s 24.0 -l 0000FF
75+
```
76+
77+
78+
#### Allowed font identifiers
79+
80+
Currently the following font names are supported:
81+
- **Courier**: `courier`, `courier_bold`, `courier_oblique`, `courier_bold_oblique`
82+
- **Helvetica**: `helvetica`, `helvetica_bold`, `helvetica_oblique`, `helvetica_bold_oblique`
83+
- **Times Roman**: `times`, `times_bold`, `times_italic`, `times_bold_italic`
6484

6585
### Additional notes
6686

6787
- **Specifying Colors**: write them as 6 or 3 digit hexadecilal as used in CSS, without the #
68-
- Allowed font specifiers
69-
- Negaive offset will set content positioning from opposite side (right for offsetX and botom from offsetY)
70-
- 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.
88+
89+
- `--color`, `--font` and `--font-size` flag has no impact for Image watermarking
90+
- `--scale-*` and `--opacity` flag has no impact for Text watermarking
91+
- Negative offset will set content positioning from opposite side (right for offsetX and botom from offsetY)
92+
- 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.
7193

7294
## Roadmap
7395

7496
✅ Draw image on every page of PDF
7597
✅ Configure Opacity option
7698
✅ Configure watermark position by X and Y offset
7799
✅ Allow negative values to for offset to adjust from opposite direction
78-
✅️ Easy option for positioning at center
79-
✅ Configure rotation angle
80-
✅ Options to Stretch watermark to width or height, proportionately
81-
✅ Options to Stretch watermark to width or height at the middle of page
82-
◻️ Render text on every page
83-
◻️ Configure text color, style and font
100+
✅️ Easy option for positioning image at center
101+
✅ Configure image rotation angle
102+
✅ Options to Stretch watermark to page width or height, proportionately
103+
✅ Options to Stretch watermark to page width or height at the middle of page
104+
◻️ Tile Image all over the page
105+
✅ Render text on every page
106+
✅ Configure text color, style and font
84107
◻️ Configure text opacity
85-
◻️ Configure text rotation angle
86-
◻️ Text placement by offset
87-
◻️ Put text at page center
108+
✅ Configure text rotation angle
109+
✅ Text placement by offset
110+
✅ Put text at page center
88111

89112
### Contribute
90113

‎text_watermark.go‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@ func adjustTextPosition(p *creator.Paragraph, c *creator.Creator) {
3030
p.SetEnableWrap(false)
3131

3232
if center {
33-
// To set text at middle, widthining the paragraph to page width and setting center allignment
34-
// then placing the box at left side of the page
35-
p.SetWidth(c.Context().PageWidth)
33+
p.SetWidth(p.Width()) // Not working without setting it manually
3634
p.SetTextAlignment(creator.TextAlignmentCenter)
37-
offsetX = 0
35+
36+
offsetX = (c.Context().PageWidth / 2) - (p.Width() / 2)
3837
offsetY = (c.Context().PageHeight / 2) - (p.Height() / 2)
3938
} else {
4039
if offsetX < 0 {
41-
// To set text from right side, widthining the paragraph to (page width - preferred offset)
42-
// then placing the box at left side of the page
43-
p.SetWidth(c.Context().PageWidth - math.Abs(offsetX))
40+
p.SetWidth(p.Width()) // Not working without setting it manually
4441
p.SetTextAlignment(creator.TextAlignmentRight)
45-
offsetX = 0
42+
43+
offsetX = c.Context().PageWidth - (math.Abs(offsetX) + p.Width())
4644
}
4745
if offsetY < 0 {
4846
offsetY = c.Context().PageHeight - (math.Abs(offsetY) + p.Height())

0 commit comments

Comments
 (0)
⌂ 换网址