PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Nov 27, 2020 7:46 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Mon Mar 16, 2020 4:38 pm 
Offline

Joined: Mon Mar 16, 2020 4:23 pm
Posts: 6
I have some very simple code that:

1. Adds a watermark to a PDF document A (like explained here - first kind) - the font I use is "Arial"
2. Then adds "cover pages" from another PDF document B
3. Adds bookmarks (outline) for the added "cover pages"
4. Save the result as PDF document C again

I tried to write unit tests for this code.
My idea was to add A, B and C as binary files, run the code in my unit test and then compare the results with my pre-existing version of "C".
That works just fine on my computer.

But when I run the same unit test in TeamCity (as part of our CI), the test fails and the created PDF document is indeed different.
When I compare the file to my local version (text compare), it seems that the binary contents are indeed very different. But I don't know why. My best guess is that the TeamCity server has different fonts installed and that this somehow affects the output (though I think it's a bit strange because I thought "Arial" should be the same on all Windows machines).

Anyway, what would be a good way to test this?
I don't have to do a binary comparison - if there was a way to extract the watermark from the output PDF somehow, then I could also check if the watermark text is what I expect it to be, etc.
Any suggestions?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 16, 2020 5:29 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
A binary comparison is the best possible regression test.

It should work if you take the Arial TTF files from the Teamcity server and install them on your local machine to generate the exemplar for the binary comparison.

Checking only for the watermark string could succeed for files that are completely useless.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 16, 2020 6:20 pm 
Offline

Joined: Mon Mar 16, 2020 4:23 pm
Posts: 6
But then my co-workers also would have to install the Arial TTF files from the server on their machines etc. etc. - not an ideal solution, unless I can somehow package the file with my tests. Is that possible?

How could I check for the watermark string?


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 20, 2020 7:05 pm 
Offline

Joined: Mon Mar 16, 2020 4:23 pm
Posts: 6
So there is no way to either

a) Package the TTF file with the unit test, so that the output would be the same on every machine, or
b) Extract the watermark string?

Would be nice if someone could clarify that. Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 23, 2020 8:42 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
You can include the font in your project in use IFontResolver (assuming WPF build of PDFsharp) to have all machines use the same font.

You can extract the watermark text for comparison, but that would be a weaker check.
Simple implementation: Locate the watermark in the PDF and copy that block to your unit test.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 23, 2020 9:01 am 
Offline

Joined: Mon Mar 16, 2020 4:23 pm
Posts: 6
Thank you! You mean this kind of code, right? http://developer.th-soft.com/developer/ ... -migradoc/
Is that what made it into the final version 1.50.5147? We use the NuGet package - or would we have to use a special WPF build?

As an alternative, how would I extract the watermark? Would be great if you could point me in the right direction. Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 24, 2020 8:44 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
Marvino wrote:
As an alternative, how would I extract the watermark? Would be great if you could point me in the right direction. Thanks!
I would make a Diff of the PDFs with and without the Watermark to identify the watermark code. Thus you know what to search for in the unit test.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 24, 2020 6:27 pm 
Offline

Joined: Mon Mar 16, 2020 4:23 pm
Posts: 6
Thomas Hoevel wrote:
Marvino wrote:
As an alternative, how would I extract the watermark? Would be great if you could point me in the right direction. Thanks!
I would make a Diff of the PDFs with and without the Watermark to identify the watermark code. Thus you know what to search for in the unit test.


I'm not sure I understand. I have looked at the files in a diff tool. The difference is just binary data. I have no idea what to look for.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group