fixed watermark
This commit is contained in:
parent
5c6abc4f60
commit
63e511e28f
@ -13,8 +13,8 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
export class LicenseInformationScreenComponent implements OnInit {
|
||||
constructor(
|
||||
public readonly permissionsService: PermissionsService,
|
||||
private readonly _licenseReportController: LicenseReportControllerService,
|
||||
public readonly appConfigService: AppConfigService,
|
||||
private readonly _licenseReportController: LicenseReportControllerService,
|
||||
private readonly _translateService: TranslateService
|
||||
) {}
|
||||
|
||||
|
||||
@ -127,7 +127,8 @@ export class WatermarkScreenComponent implements OnInit {
|
||||
licenseKey: environment.licenseKey ? atob(environment.licenseKey) : null,
|
||||
path: this._baseHref + '/assets/wv-resources',
|
||||
css: this._baseHref + '/assets/pdftron/stylesheet.css',
|
||||
fullAPI: true
|
||||
fullAPI: true,
|
||||
isReadOnly: true
|
||||
},
|
||||
this._viewer.nativeElement
|
||||
).then((instance) => {
|
||||
@ -139,7 +140,15 @@ export class WatermarkScreenComponent implements OnInit {
|
||||
});
|
||||
|
||||
this._disableElements();
|
||||
this._instance.loadDocument(`${window.location.origin}${this._baseHref}/assets/pdftron/blank.pdf`);
|
||||
|
||||
return this._http
|
||||
.request('get', '/assets/pdftron/blank.pdf', {
|
||||
responseType: 'blob'
|
||||
})
|
||||
.subscribe((blobData) => {
|
||||
console.log('load blank');
|
||||
this._instance.loadDocument(blobData, { filename: 'blank.pdf' });
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -149,46 +158,77 @@ export class WatermarkScreenComponent implements OnInit {
|
||||
}
|
||||
|
||||
private async _drawWatermark() {
|
||||
await this._instance.PDFNet.initialize();
|
||||
console.log('draw WV');
|
||||
|
||||
const PDFNet = this._instance.PDFNet;
|
||||
|
||||
const document = await this._instance.docViewer.getDocument().getPDFDoc();
|
||||
const pageSet = await this._instance.PDFNet.PageSet.createSinglePage(1);
|
||||
const doc = document;
|
||||
await this._instance.PDFNet.runWithCleanup(
|
||||
async () => {
|
||||
//const s = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
|
||||
|
||||
await this._instance.PDFNet.Stamper.deleteStamps(document, pageSet);
|
||||
// Specifies if the stamp is to be stamped as an annotation.
|
||||
// note that stamps created with this setting do not work with SetAsBackground, HasStamps, and DeleteStamps, if annotation is true.
|
||||
//s.setAsAnnotation(true);
|
||||
|
||||
const text = this.configForm.get('text').value || '';
|
||||
const fontSize = this.configForm.get('fontSize').value;
|
||||
const fontType = this.configForm.get('fontType').value;
|
||||
const orientation: WatermarkModel.WatermarkOrientationEnum = this.configForm.get('orientation').value;
|
||||
const opacity = this.configForm.get('opacity').value;
|
||||
const color = this.configForm.get('hexColor').value;
|
||||
// await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_center, PDFNet.Stamper.VerticalAlignment.e_vertical_top);
|
||||
// const font = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_courier);
|
||||
// await s.setFont(font);
|
||||
// const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
|
||||
// await s.setFontColor(redColorPt);
|
||||
// await s.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
|
||||
// await s.setAsBackground(false);
|
||||
// const pgSet = await PDFNet.PageSet.createRange(1, 2);
|
||||
// await s.stampText(doc, 'This is a title!', pgSet);
|
||||
//
|
||||
// s.setAsBackground(false);
|
||||
// const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
|
||||
// await s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
|
||||
|
||||
const rgbColor = hexToRgb(color);
|
||||
await document.lock();
|
||||
|
||||
const stamper = await this._instance.PDFNet.Stamper.create(3, fontSize, 0);
|
||||
await stamper.setFontColor(await this._instance.PDFNet.ColorPt.init(rgbColor.r, rgbColor.g, rgbColor.b));
|
||||
await stamper.setOpacity(opacity / 100);
|
||||
const pageSet = await this._instance.PDFNet.PageSet.createSinglePage(1);
|
||||
|
||||
switch (orientation) {
|
||||
case WatermarkModel.WatermarkOrientationEnum.VERTICAL:
|
||||
await stamper.setAlignment(0, 0);
|
||||
await stamper.setRotation(-90);
|
||||
break;
|
||||
case WatermarkModel.WatermarkOrientationEnum.HORIZONTAL:
|
||||
break;
|
||||
case WatermarkModel.WatermarkOrientationEnum.DIAGONAL:
|
||||
default:
|
||||
await stamper.setAlignment(0, 0);
|
||||
await stamper.setRotation(-45);
|
||||
}
|
||||
await this._instance.PDFNet.Stamper.deleteStamps(document, pageSet);
|
||||
|
||||
const font = await this._instance.PDFNet.Font.createAndEmbed(document, this._convertFont(fontType));
|
||||
await stamper.setFont(font);
|
||||
await stamper.setTextAlignment(0);
|
||||
await stamper.stampText(document, text, pageSet);
|
||||
const text = this.configForm.get('text').value || '';
|
||||
const fontSize = this.configForm.get('fontSize').value;
|
||||
const fontType = this.configForm.get('fontType').value;
|
||||
const orientation: WatermarkModel.WatermarkOrientationEnum = this.configForm.get('orientation').value;
|
||||
const opacity = this.configForm.get('opacity').value;
|
||||
const color = this.configForm.get('hexColor').value;
|
||||
|
||||
this._instance.docViewer.refreshAll();
|
||||
this._instance.docViewer.updateView([0], 0);
|
||||
this._changeDetectorRef.detectChanges();
|
||||
const rgbColor = hexToRgb(color);
|
||||
|
||||
const stamper = await this._instance.PDFNet.Stamper.create(3, fontSize, 0);
|
||||
await stamper.setFontColor(await this._instance.PDFNet.ColorPt.init(rgbColor.r / 255, rgbColor.g / 255, rgbColor.b / 255));
|
||||
await stamper.setOpacity(opacity / 100);
|
||||
|
||||
switch (orientation) {
|
||||
case WatermarkModel.WatermarkOrientationEnum.VERTICAL:
|
||||
await stamper.setAlignment(0, 0);
|
||||
await stamper.setRotation(-90);
|
||||
break;
|
||||
case WatermarkModel.WatermarkOrientationEnum.HORIZONTAL:
|
||||
break;
|
||||
case WatermarkModel.WatermarkOrientationEnum.DIAGONAL:
|
||||
default:
|
||||
await stamper.setAlignment(0, 0);
|
||||
await stamper.setRotation(-45);
|
||||
}
|
||||
|
||||
const font = await this._instance.PDFNet.Font.createAndEmbed(document, this._convertFont(fontType));
|
||||
await stamper.setFont(font);
|
||||
await stamper.setTextAlignment(0);
|
||||
await stamper.stampText(document, text, pageSet);
|
||||
|
||||
this._instance.docViewer.refreshAll();
|
||||
this._instance.docViewer.updateView([0], 0);
|
||||
this._changeDetectorRef.detectChanges();
|
||||
},
|
||||
environment.licenseKey ? atob(environment.licenseKey) : null
|
||||
);
|
||||
}
|
||||
|
||||
private _initForm() {
|
||||
|
||||
@ -52,8 +52,6 @@ export interface TypeValue {
|
||||
*/
|
||||
description?: string;
|
||||
|
||||
isDefaultFilter?: boolean;
|
||||
|
||||
virtual?: boolean;
|
||||
label?: string;
|
||||
entries?: string[];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user