ASF Bugzilla – Attachment 37473 Details for
Bug 64348
createWaterMark IndexOutOfBoundException
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
This is my implementation of watermarking, including watermarked service and watermarked ServiceImpl
service.txt (text/plain), 3.26 KB, created by
HanChong
on 2020-09-27 02:39:26 UTC
(
hide
)
Description:
This is my implementation of watermarking, including watermarked service and watermarked ServiceImpl
Filename:
MIME Type:
Creator:
HanChong
Created:
2020-09-27 02:39:26 UTC
Size:
3.26 KB
patch
obsolete
>public interface WatermarkService { > > /** > * ¸øÔ´Îļþ¼Óˮӡ > * @author eko.zhan at 2018Äê9ÔÂ1ÈÕ ÏÂÎç4:42:15 > * @param originFile > * @param watermark > * @return > * @throws IOException > */ > public byte[] handle(File originFile, String watermark) throws IOException; > /** > * ¸øÔ´Îļþ¼Óˮӡ > * @author eko.zhan at 2018Äê9ÔÂ1ÈÕ ÏÂÎç4:42:15 > * @param originFile > * @param watermark > * @return > * @throws IOException > */ > public byte[] handle(File originFile, String watermark, String color) throws IOException; >} > > > >@Service >public class WatermarkServiceImpl implements WatermarkService { > > private final static String DEFAULT_WATERMARK = "powered by eko.zhan"; > private final static String DEFAULT_FONT_COLOR = "#d8d8d8"; > > @Override > public byte[] handle(File originFile, String watermark) throws IOException { > return handle(originFile, watermark, DEFAULT_FONT_COLOR); > } > > @Override > public byte[] handle(File originFile, String watermark, String color) throws IOException { > watermark = StringUtils.isBlank(watermark)?DEFAULT_WATERMARK:watermark; > color = StringUtils.isBlank(color)?DEFAULT_FONT_COLOR:color; > if (originFile.getName().toLowerCase().endsWith("docx")) { > try (InputStream in = new FileInputStream(originFile)){ > XWPFDocument doc = new XWPFDocument(in); > addWaterMark(doc, watermark, color); > try (OutputStream out = new FileOutputStream(originFile)){ > doc.write(out); > doc.close(); > } > } > return IOUtils.toByteArray(new FileInputStream(originFile)); > } else if (originFile.getName().toLowerCase().endsWith("doc")) { > try (InputStream in = new FileInputStream(originFile)){ > HWPFDocument doc = new HWPFDocument(in); > addWaterMark(doc, watermark, color); > try (OutputStream out = new FileOutputStream(originFile)){ > doc.write(out); > doc.close(); > } > } > return IOUtils.toByteArray(new FileInputStream(originFile)); > } > return null; > } > > > > > private void addWaterMark(Object obj, String watermark, String color) { > if (obj instanceof XWPFDocument) { > XWPFDocument doc = (XWPFDocument) obj; > // create header-footer > XWPFHeaderFooterPolicy headerFooterPolicy = doc.getHeaderFooterPolicy(); > if (headerFooterPolicy == null) headerFooterPolicy = doc.createHeaderFooterPolicy(); > > // create default Watermark - fill color black and not rotated > headerFooterPolicy.createWatermark(watermark); > > // get the default header > // Note: createWatermark also sets FIRST and EVEN headers > // but this code does not updating those other headers > XWPFHeader header = headerFooterPolicy.getHeader(XWPFHeaderFooterPolicy.DEFAULT); > XWPFParagraph paragraph = header.getParagraphArray(0); > > // get com.microsoft.schemas.vml.CTShape where fill color and rotation is set > XmlObject[] xmlobjects = paragraph.getCTP().getRArray(0).getPictArray(0).selectChildren(new QName("urn:schemas-microsoft-com:vml", "shape")); > if (xmlobjects.length > 0) { > com.microsoft.schemas.vml.CTShape ctshape = (com.microsoft.schemas.vml.CTShape)xmlobjects[0]; > // set fill color > ctshape.setFillcolor(color); > // set rotation > ctshape.setStyle(ctshape.getStyle() + ";rotation:315"); > } > } else if (obj instanceof HWPFDocument) { > > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 64348
: 37473