Hi,
I am reaching out to seek assistance regarding an issue we’ve encountered while using GroupDocs.Watermark for .NET.
We’re currently converting a watermarked docx file to a pdf file. We’ve successfully converted it to pdf and all watermarks are carried over. Upon uploading it to google drive and viewing it using google docs, all watermarks are gone. We’ve tried viewing the converted file to another 3rd party application and all watermarks are visible. Is this an issue on applying watermark to a document that is easily removed by the google docs? Do you have workaround on this?
@edecastro
Could you please share the resultant file? We’ll test that at our end.
docx 2.pdf (510.5 KB)
Hi,
Thanks for the response. I’ve attached the file.
@edecastro
We can view the watermark. Please take a look at this image (72.8 KB) and this image.
How you are converting the Word file with watermarks to PDF?
@atir.tahir
We converted the Word file to pdf by these steps:
- Open the Word file using MS Office Word App
- Select “Save As” and the select the pdf format.
And for the viewing of the converted file, we opened via GoogleDocs, see attached image:
image.png (29.3 KB)
@edecastro
Is this text Filam Software Property your watermark? It’s still visible when we open the document in Google Docs (we shared screenshot earlier).
@atir.tahir
Yes that is and We tried this approach. 16.05.2024_02.37.38_REC
@edecastro
Thanks for the screencast. This issue is reproduced at our end. Therefore, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WATERMARKNET-1693
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thanks for the update last week, any development on this issue? Just wanted to follow-up. Thanks again!
@edecastro
This ticket is still under investigation. We’ll notify you in case of any update.
@edecastro
This issue is reproduced at our end. In some cases watermark is displayed but not as expected. However, could you please share the sample code or application that you are using to create watermark?
Sure thing - I’ll have our developers provide the information. // em.dc
Hi @atir.tahir ,
We implement watermarking by using the code below:
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
using (Watermarker watermarker = new Watermarker(new MemoryStream(wordByteArray), loadOptions))
{
var content = watermarker.GetContent<WordProcessingContent>();
var section = content.Sections[0];
var pageSetup = section.PageSetup;
double pageWidth = pageSetup.Width;
double pageHeight = pageSetup.Height;
WordProcessingWatermarkPagesOptions options = new WordProcessingWatermarkPagesOptions
{
PageNumbers = GetAllPageNumbers(content),
};
#region Document Watermarking
using (ImageWatermark docWatermark = new ImageWatermark(new MemoryStream(watermarkImgBytes)))
{
docWatermark.SizingType = SizingType.ScaleToParentDimensions;
docWatermark.PagesSetup = new PagesSetup { AllPages = true };
docWatermark.HorizontalAlignment = GroupDocs.Watermark.Common.HorizontalAlignment.Center;
docWatermark.VerticalAlignment = GroupDocs.Watermark.Common.VerticalAlignment.Center;
docWatermark.Width = pageWidth;
docWatermark.Height = pageHeight;
docWatermark.Margins = new Margins
{
Bottom = 0,
Top = 0,
Left = 0,
Right = 0,
MarginType = MarginType.Absolute
};
docWatermark.Opacity = 1;
docWatermark.IsBackground = true;
watermarker.Add(docWatermark, options);
}
#endregion
watermarker.Save(completeFilePathName);
}
1 Like
@edecastro
Thanks for the code. We are further investigating the issue. You’ll be notified in case of any update.
1 Like
@edecastro
We investigated this scenario and it seems that the problem is in the mechanism for converting Google Drive from PDF to Word, and specifically for the case when a Word document contains an image close to the border. We were able to reproduce this problem on a Word document (“doc with image near boarder.docx”) that has a regular image next to the left border. If you save this document as a PDF, then upload it to Google Drive and open it in Google Docs, the image will not be visible. If you slightly shift the image to the right in the original Word document and then repeat conversion operations, the image will be visible in Google Docs.
Based on this, we can suggest to make a small change in your code:
instead of:
docWatermark.Width = pageWidth;
docWatermark.Height = pageHeight;
write
docWatermark.Width = pageWidth-10;
docWatermark.Height = pageHeight-10;
Please note that we have our own mechanism to create tiled watermarks (currently as we understand you use some ready image with tiled watermarks and set it as background).
1 Like
Good day @atir.tahir .
Thank you for the update. We’ll check your suggestion and update you on how it goes.
Regarding on how implemented our watermark, yes we are using a tiled image as background since we want some freedom on styling our watermark as requested by our clients. But we will check this also.
Thank you!
Hi @atir.tahir,
We’ve tried your suggestions, but they are still not working on our end. First, we tried them on a .doc file, but no watermarks showed when converted to PDF and uploaded to Google Drive. Then, we tried them on a .docx file. Watermarks appeared, but there were pages where the watermark did not appear, and the watermark position was scrambled.
Here’s the updated code with your suggestions:
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
using (Watermarker watermarker = new Watermarker(new MemoryStream(wordByteArray), loadOptions))
{
var content = watermarker.GetContent<WordProcessingContent>();
var section = content.Sections[0];
var pageSetup = section.PageSetup;
double pageWidth = pageSetup.Width;
double pageHeight = pageSetup.Height;
WordProcessingWatermarkPagesOptions options = new WordProcessingWatermarkPagesOptions
{
PageNumbers = GetAllPageNumbers(content),
};
#region Document Watermarking
using (ImageWatermark docWatermark = new ImageWatermark(new MemoryStream(watermarkImgBytes)))
{
docWatermark.SizingType = SizingType.ScaleToParentDimensions;
docWatermark.PagesSetup = new PagesSetup { AllPages = true };
docWatermark.HorizontalAlignment = GroupDocs.Watermark.Common.HorizontalAlignment.Center;
docWatermark.VerticalAlignment = GroupDocs.Watermark.Common.VerticalAlignment.Center;
docWatermark.Width = pageWidth - 10;
docWatermark.Height = pageHeight - 10;
docWatermark.Margins = new Margins
{
Bottom = 0,
Top = 0,
Left = 0,
Right = 0,
MarginType = MarginType.Absolute
};
docWatermark.Opacity = 1;
docWatermark.IsBackground = true;
watermarker.Add(docWatermark, options);
}
#endregion
watermarker.Save(completeFilePathName);
}
Adding my support team to this thread. Thanks! // em.dc
Hi @atir.tahir,
We’ve also tried the tiled watermarks, but they are still not showing when converted to PDF and uploaded to Google Drive. We also noticed that when Word documents with a tiled watermark are opened via Google Docs, the leaning position of the tiled watermark is removed. Please see the attached image for your reference:
image.png (64.8 KB)
Here’s the code we’ve implemented using the tiled watermark:
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
using (Watermarker watermarker = new Watermarker(new MemoryStream(wordByteArray), loadOptions))
{
//// Initialize the font to be used for watermark
//GroupDocs.Watermark.Watermarks.Font font = new GroupDocs.Watermark.Watermarks.Font("Arial", 19, GroupDocs.Watermark.Watermarks.FontStyle.Bold | GroupDocs.Watermark.Watermarks.FontStyle.Italic);
// Create the image watermark object
var wm = new ImageWatermark(watermarkImagePath)
{
// Configure tile options
TileOptions = new TileOptions()
{
LineSpacing = new MeasureValue()
{
MeasureType = TileMeasureType.Percent,
Value = 12
},
WatermarkSpacing = new MeasureValue()
{
MeasureType = TileMeasureType.Percent,
Value = 10
},
},
// Set watermark properties
Opacity = 1,
RotateAngle = -30,
SizingType = SizingType.Absolute,
HorizontalAlignment = GroupDocs.Watermark.Common.HorizontalAlignment.Center,
VerticalAlignment = GroupDocs.Watermark.Common.VerticalAlignment.Center,
};
// Add watermark
watermarker.Add(wm);
watermarker.Save(completeFilePathName);
}
Please note that we remove the leaning position of our watermark image when using the tiled watermark.
We couldn’t reproduce this issue. Please take a look at this file.zip (17.5 KB). If we upload it to Google drive and then view it using Google Docs, watermark will disappear. But if we apply following settings and repeat same process to view the document using Google Docs, watermark is properly visible.
docWatermark.Width = pageWidth-10;
docWatermark.Height = pageHeight-10;
Take a look at this screenshot.png (118.6 KB). Could you please specify the API version you are using? Also please share a screencast (short video) of this issue, explaining all steps using that we could reproduce it at our end as well.