Adding watermark in XOD files

429 views
Skip to first unread message

kouko...@gmail.com

unread,
May 5, 2014, 10:42:52 AM5/5/14
to pdfnet-w...@googlegroups.com
Hello.

I wanted to add watermarks to my XOD files so what I did in code is:
I open the XOD ZIP file, get each XAML page, get its first "Canvas" element and then:

First Approach : I add a new "Glyphs" element in it.
This has the problem that I must calculate the appropriate trasnform for it (to neuteralize the RenderTransform of the FixedPage).
Although I have done some great job at it, something goes wrong, probably not in my code as I saw later.


Second Approach :  I move the old Canvas element inside a new Canvas element that I have created and that has RenderTransform="1,0,0,1,0,0" (identity).
Then I append my Glyphs element to the newly created Canvas (that is not trasformed in any way).
This also works fine BUT it only works for some XODs (the same exact problem existed with my previous approach and on the same XODs).
It seems that when the rendering transform of the old Canvas is something like that:
"1.3333333,0,0,-1.3333333,0,1122.72"
...everything is great, while when it is something like that:
"0,1.3333333,1.3333333,0,-81.148,-36.44"
...things go very wrong. My watermark is misplaced and I can't figure out why.
But I don't know if it is the RenderTrasform that causes this divergence in behaviour of something else like the page orientation (if such thing exists in XODs) or something...

In the 2nd approach there is no RenderTransform in any parent of my new Glyphs element.
Yet, it doesn't go when I tell it to go all of the times.
E.g.: I use "10,0,0,10,20,20" and I expect it to start from (20,20) and continue horizontally. Instead it is totally invisible !

Any idea what I am missing here?
You have done some similar work while adding your demo watermark ("www.pdftron.com") in the XOD converter.
You seem to use the 1st approach mentioned here.

Thanks.

Matt Parizeau

unread,
May 5, 2014, 2:23:29 PM5/5/14
to pdfnet-w...@googlegroups.com
Hi,

I would recommend either adding the watermark to the PDF before converting to XOD using PDFNet or something similar, or you could create a dynamic watermark using WebViewer. See https://groups.google.com/d/msg/pdfnet-webviewer/8NpF3fks3gM/ffYgBpajHXQJ and https://groups.google.com/d/msg/pdfnet-webviewer/bl-PeZqI920/u0TheyCRfUcJ for more information. This would probably save you some headaches from dealing with xaml content directly.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

kouko...@gmail.com

unread,
May 6, 2014, 3:46:04 AM5/6/14
to pdfnet-w...@googlegroups.com
Hi.

Thanks for your reply.
My files are usually not PDF, so I try to avoid the overhead of converting back and forth for just to apply the watermark.
I need to apply the watermark when a user requests the file (e.g. I may need to inclue date and time in the watermark), so this is quite extreme to do for every file request.

On the other hand, addding watermarks as HTML may be a somewhat good solution but I see these problems:
1) We want to have the same watermark on all viewers (HTML5, Flash, Silverlight) and, I guess, the best way to achieve this is by modifying the XOD.
2) I am not sure about this, but I have the impression that embedding the watermark in the XOD is much safer and more difficult to remove (Our watermarks are needed for one addditional reason: to add accountablity to the user that retrieves the file to view it). Having the watermarking done in the server and merging it directly with the XOD file seems the best solution.

I would suggest you to create some fuctionality (separate library maybe?) that watermarks XOD files.
As far as I see, you have already done this for watermarking your XODs produced by the demo/trial version of PdfNet.
There might be people out there that need this functionality (I centrainly do need it...).
If it could be flexible so that it adds the watermark on custom page corners and with custom rotations it would be even better.

Thanks.

kouko...@gmail.com

unread,
May 7, 2014, 3:46:02 AM5/7/14
to pdfnet-w...@googlegroups.com
Finally, I have managed to put the watermark when I needed it, but in the Flash viewer, the letters seem shuffled:
In HTML5 it looks great.
Do you have any idea why this happens?
I have tried changing the text's RenderTransform and the font used (I usually provide my own custom font for the watermark), but nothing seems to help.


Τη Δευτέρα, 5 Μαΐου 2014 9:23:29 μ.μ. UTC+3, ο χρήστης Matt Parizeau έγραψε:

kouko...@gmail.com

unread,
May 7, 2014, 3:52:25 AM5/7/14
to pdfnet-w...@googlegroups.com


Τη Δευτέρα, 5 Μαΐου 2014 9:23:29 μ.μ. UTC+3, ο χρήστης Matt Parizeau έγραψε:

Ryan - PDFNet Developer

unread,
May 7, 2014, 5:56:26 PM5/7/14
to pdfnet-w...@googlegroups.com
Hi, going back a bit in this issue, to clarify a few things.

Internally, all conversions go through PDF on their way to XOD. Regardless of what the input is.

So calling
ToXod("file.xlsx")
should be the same processing time as
ToXod(ToPDF("file.xlsx"));

So if you want to watermark the document, then call ToPDF, and then apply the watermak, and then call ToXod.
Here is a good posting on this.
https://groups.google.com/forum/?fromgroups#!searchin/pdfnet-sdk/watermark|sort:date/pdfnet-sdk/H5xaMbHdJs4/CfnKP6edvO8J

You can create a temp PDFDoc object, add a page, and use the stamper class to add an annotation containing text. Stamper.StampText.
Then call FlattenAnnotations on the temp doc.
Then stamp all the pages of your PDFDoc using Stamper.StampPage, using the page from the temp PDFDoc object.
This will create a PDFDoc with the watermark text in the content stream as a graphics. This will be very difficult to remove from the xod file afterwards.

Modifying the Xod file afterwards has a lot of pitfalls. Our Xod files are carefully crafted so that they appear, and function (e.g. text selection) across different devices, browsers and viewers. Even how the xod file is zipped is carefully crafted so the resources needed for page 1 are at the beginning of the xod file, so streaming works fast.

a a

unread,
May 8, 2014, 12:09:58 PM5/8/14
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
I understand, but since the watermark should be added on the fly (this is not my decision, but the requirements), the "Stamper.StampPage" is not an efficient method at all.
I can't convert a file in XOD every time a request for that file is sent to the server (especially if Office interop is involved in it's conversion).

Puting the watermark on the client might be doable, but I will need to do it in both the Flash version and the HTML5 version of the viewer. We will think about that.

Concerning the streaming and the way the ZIP is crafted, we actually don't need the viewer to retrieve pieces (although I haven't found out a way to achive that in the Flash viewer yet).
Downloading the whole file at once might be OK. I don't know if there are other problems that may come-up with that.

Thanks.


--
You received this message because you are subscribed to a topic in the Google Groups "PDFTron WebViewer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pdfnet-webviewer/CwrxTrHvUiw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pdfnet-webview...@googlegroups.com.
To post to this group, send email to pdfnet-w...@googlegroups.com.
Visit this group at http://groups.google.com/group/pdfnet-webviewer.
For more options, visit https://groups.google.com/d/optout.

a a

unread,
May 12, 2014, 6:13:51 AM5/12/14
to PDFTron WebViewer on behalf of Ryan - PDFNet Developer
Hi again.

I know that you don't like the idea of me messing with the XOD files but, if you want, follow me on this:
I have found a case of XOD that I have modified that your viewer doesn't display nice (nothing peculiar so far).
your viewer doesn't log any JS error on the browser but the pages are rendered using the preview images (as far as I can tell) that seem blurry.
I have validated the XOD with Microsoft's "isXPS.exe" and it only returned warnings (that didn't originate from my edits).
I have also opened the file with Window's XPS viewer and it seemed perfect.

I don't know if this case interests you, but to tell you the truth I have some curiosity to learn why your viewer doesn't like these XOD files.
As far as I can tell, the problem becomes visible when I add a relation to a font resource for a XAML page (In the \Pages\_rels\sth.xaml.rels files) (I have included the obfuscated font resource myself previously).
Whenever I do that (no matter which document I use), your viewer displays only the preview images that seem blurry.
I send you a sample XOD to have a look if you are interested.
Perhaps this has sth to do with the order of insertion of the resources that you've mentioned earlier?

Thank you and sorry for bugging you for such low level stuff.
Even if we finally add watermarks by other means, I would like to figure this one out, just to feel the satisfaction. :)


2014-05-08 0:56 GMT+03:00 Ryan - PDFNet Developer via PDFTron WebViewer <pdfnet-webviewer+noreply-APn2wQc...@googlegroups.com>:

--
123.xod

Matt Parizeau

unread,
May 13, 2014, 3:15:36 PM5/13/14
to pdfnet-w...@googlegroups.com
I tried viewing the document you've attached and I can view it just fine in the current 1.7.1 version. Maybe there is an issue with a customization you've done in the viewer?

Matt Parizeau
Software Developer
PDFTron Systems Inc.


On Monday, May 12, 2014 3:13:51 AM UTC-7, a a wrote:
Hi again.

I know that you don't like the idea of me messing with the XOD files but, if you want, follow me on this:
I have found a case of XOD that I have modified that your viewer doesn't display nice (nothing peculiar so far).
your viewer doesn't log any JS error on the browser but the pages are rendered using the preview images (as far as I can tell) that seem blurry.
I have validated the XOD with Microsoft's "isXPS.exe" and it only returned warnings (that didn't originate from my edits).
I have also opened the file with Window's XPS viewer and it seemed perfect.

I don't know if this case interests you, but to tell you the truth I have some curiosity to learn why your viewer doesn't like these XOD files.
As far as I can tell, the problem becomes visible when I add a relation to a font resource for a XAML page (In the \Pages\_rels\sth.xaml.rels files) (I have included the obfuscated font resource myself previously).
Whenever I do that (no matter which document I use), your viewer displays only the preview images that seem blurry.
I send you a sample XOD to have a look if you are interested.
Perhaps this has sth to do with the order of insertion of the resources that you've mentioned earlier?

Thank you and sorry for bugging you for such low level stuff.
Even if we finally add watermarks by other means, I would like to figure this one out, just to feel the satisfaction. :)
To unsubscribe from this group and all its topics, send an email to pdfnet-webviewer+unsubscribe@googlegroups.com.
To post to this group, send email to pdfnet-webviewer@googlegroups.com.

a a

unread,
May 14, 2014, 5:23:01 AM5/14/14
to PDFTron WebViewer on behalf of Matt Parizeau
It seems that I use version 1.7.1 too.
I have just tried restoring all the viewer files in a demo project and keeping the viewer initialization as simple as possible (I don't think there is any customization in this project now - I hope I am not missing anything). However, I still see blurry pages (I have tried in both FireFox and Chrome):




Viewer initialization in PdfTronTest\Views\Home\PreView.cshtml :


<script type="text/javascript" src="~/Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="~/Scripts/PdfTron/WebViewer.min.js"></script>

<script type="text/javascript">
$(function() {
var viewerElement = document.getElementById('viewer');
var myWebViewer = new PDFTron.WebViewer({
type: "html5,Silverlight,flash",
initialDoc: "/Content/GettingStarted.xod",
html5Path: "/Scripts/PdfTron/html5/ReaderControl.html"
}, viewerElement);
});
</script>

<div id="viewer" style="min-height:1000px;height:1000px;"></div>

Here is a link to the whole Visual Studio project in case you want it: http://www.speedyshare.com/krW6r/PdfTronTest.zip
When I upload the XOD file in your online viewer demos, everything seems fine too (although the demo preprocesses the XOD file again as far as I understand).
I really can't understand how we could get different results. :(



To unsubscribe from this group and all its topics, send an email to pdfnet-webview...@googlegroups.com.
To post to this group, send email to pdfnet-w...@googlegroups.com.

Matt Parizeau

unread,
May 14, 2014, 3:01:41 PM5/14/14
to pdfnet-w...@googlegroups.com
I'm not able to easily run the project since I think I'm missing some of the libraries. If you have a public link that I could test at then I could take a look. My guess is that there is an error in the JavaScript console (F12) which could help explain the issue.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

a a

unread,
May 15, 2014, 4:12:41 AM5/15/14
to PDFTron WebViewer on behalf of Matt Parizeau
Unfortunatelly, I see no error in the browser's console (If you exclude the error for the missing annotations handler). :(

To run the project, try going to:
View->Other Windows->Package Manager Console
In the window that opens there must be an "update" or "restore packages" button that will download all the missing libraries.
In case that sth is still missing, I send you a link to all the packages I have on my PC:
They should be placed next to the project folder.

However, now that I have tried to publish the site to IIS7, it seems that it works fine there.
So, I think this is probably a problem with byte-range requests that work OK in IIS, but not in IIS express.
Here is the published site that you can put in IIS (use .net framework v.4 for the application pool):
But this will work fine.

These are some thoughts I had before finding out some things. You can ignore them :
Most probably, I will face problems with this, since I want to return the file from a controller action and not get it a from a static file link.
I have used this byte-range library:
..that handles byte requests but I doubt if this is working well either.
If I could disable byte-range request by the viewer (at least the HTML version) it would be great.

Now I see that everything seems to work OK in IIS. And I don't know why.
The only problem is that the watermark doesn't seem fine when I view it in normal zoom, while it seems fine when I view it zoomed in at e.g. 300%.

​I will have to work this one out...


To unsubscribe from this group and all its topics, send an email to pdfnet-webview...@googlegroups.com.
To post to this group, send email to pdfnet-w...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages