Hi Matt,
It took some while, but I was able to completely figure it out and have the custom annotations printed, shown in the WebViewer and redrawn in the WebViewer. What I did was the following:
- In PHP I create a temporary PDF for editing (this is important for loading the PDF, see a few steps below.)
- Created an annotation that basically extends the StampAnnotation, uses the BoxSelectionModel, and for creating the actual annotation the GenericAnnotationCreateTool is used. While drawing and serializing the annotation I set the 'Subject' attribute with a custom identifier for that type of Stamp (e.g. CustomSignHere).
This allows me to draw the new annotation on the screen (as shown in my previous code example, I actually draw an image on the Stamp's canvas.)
- On save I create images from the actual stamps, based on the 'Subject' every custom annotation is given I know which stamp to replace with which image (Stamp with Subject 'CustomSignHere' is replaced with 'customsignhere.png', 'CustomSignThere' with 'customsignthere.png', etc..). For this step I used the ElementBuilder and ElementWriter to allow for more advanced things than the Stamper.
Since it is now an image, still including the Subject, placed within the PDF, we can print it from all PDF-viewers.
- When the document is loading from the WebViewer while it contains the custom stamps, I remove the images having a Subject (that was included within the PDF as mentioned in the step above) indicating the annotation is a custom one. Since I created a temporary PDF first, and that PDF is the one loaded into the WebViewer, when the page is reloaded I won't lose my custom annotations and only the temporary PDF is disposed at that point.
As said, the temporary PDF allows me to keep my custom annotations when the page is reloaded, either by accident or something else.
- After the document is loaded into the WebViewer, because I override the standard Stamp's draw function, I can now draw my image back on top of the Stamp's canvas again to have it shown in the WebViewer as if it was drawn just at that moment by the user:
var originalStampDrawFunction = Annotations.StampAnnotation.prototype.draw;
Annotations.StampAnnotation.prototype.draw = function (ctx) {
switch (this.Subject) {
case 'CustomSignHere':
CustomSignHere.prototype.draw.call(this, ctx);
break;
case 'CustomSignThere':
CustomSignThere.prototype.draw.call(this, ctx);
break;
default:
originalStampDrawFunction.apply(this, arguments);
}
};
This solution, gives me printable, fully customizable, annotations, shown in all PDF viewers, and easily found within the PDF's binary source (because of the custom Subject.)
Kind regards,
Iwan Luijks
Op donderdag 13 november 2014 22:46:40 UTC+1 schreef Matt Parizeau: