Customization of Watermark image with propotion to Pdf pages

Hi Aspose team,


In our project, we have requirement like based on the settings we have to create the customize image and apply it as a watermark to the pdf, word and ppt files. We need to apply this watermark in different positions of the page like diagnol, bottom of the page, top of the page and both top and bottom page. Based on the image size and page size I need to set this image in an angle where the complete image should be visible and should be the center of the page as shown in the attachment (ExpectedOutput.pdf).

I have written the following code to achieve the same, but failed. We go out put as shown in the attachement (ActualOutput.pdf) .

I have attached the code also in the text (code_used_setWatermark.txt) document. Can you please help us in achieveing the same.

Hi Chandra,


Thanks for contacting support.

I have tested the scenario using code snippet which you have shared earlier and have observed that ImageStamp is not properly appearing. However if your requirement is to add Image stamp with Horizontal/Vertical Alignment as Center and with Rotating angle as 45, you may consider using following simple code.

For your reference, I have also attached the resultant file generated over my end.

[C#]

//Open
document
<o:p></o:p>

Document pdfDocument = new Document();

pdfDocument.Pages.Add();

//Create image stamp

ImageStamp imageStamp = new ImageStamp("c:/pdftest/watermark.jpeg");

imageStamp.Background = true;

imageStamp.Height = 80;

//imageStamp.Width = 300;

// add stamp at angle of 45 degree

imageStamp.RotateAngle = 45;

// set opacity for stamp object

imageStamp.Opacity = 0.5;

imageStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;

imageStamp.VerticalAlignment = VerticalAlignment.Center;

//Add stamp to particular page

pdfDocument.Pages[1].AddStamp(imageStamp);

//Save output document

pdfDocument.Save("c:/pdftest/CenterAligned_output.pdf");

Hi Team,


Thank you so much for your reply. But in my case I can not set the alignment manually, as my image size can vary from the front end. I have just given few settings in my code.

Please let me know, how can I get the position of x, y and rotation angle based on the page size and image size programatically.

Thanks,
Chandra.
chandra Banda:
Thank you so much for your reply. But in my case I can not set the alignment manually, as my image size can vary from the front end. I have just given few settings in my code.
Hi Chandra,

Thanks for the acknowledgement.

I have logged your original issue of incorrect appearance of watermark in our issue tracking system as PDFNEWNET-37808. We will further look into the details of this problem and will keep you updated on the status of correction.

chandra Banda:
Please let me know, how can I get the position of x, y and rotation angle based on the page size and image size programatically.
Do you need to get X,Y, Rotation angle for image once it has been added to PDF file ? Please note that unless the image is placed inside document, you cannot get information/properties associated with it.

Hi Team,


Thank you so much for the reply. we want to get the x, y and Rotation angle details before applying the image to pdf file. So that we can place that image in that postion on the pdf file. And I want the same behaviour on Word, ppt files as well.

I will be looking for your positive response at the earliest as it is very important for our current requirements.

Thanks,
Chandra.
chandra Banda:
Thank you so much for the reply. we want to get the x, y and Rotation angle details before applying the image to pdf file. So that we can place that image in that postion on the pdf file.
Hi Chandra,

Sorry for the delayed response.

Aspose.Pdf for .NET offers the feature to get position of image already present inside PDF but in your case, you need to add image to PDF file so you need to provide X,Y, Rotating Angle information instead. However the problem related to incorrect placement of watermark is already logged in our issue tracking system. We will further investigate the problem and will keep you updated on the status of correction.

chandra Banda:
And I want the same behaviour on Word, ppt files as well.
My fellow workers from Aspose.Slides and Aspose.Words will further look into this query and will reply accordingly.
Hi Chandra,

Thanks for your inquiry.
chandra Banda:

we want to get the x, y and Rotation angle details before applying the image to pdf file. So that we can place that image in that postion on the pdf file. And I want the same behaviour on Word, ppt files as well.

You can insert an image in Word document using DocumentBuilder.InsertImage. This method return the Shape node object. You can get the X, Y location and rotated angle of Shape node using following code example. Hope this helps you.


Document doc = new Document(MyDir + "in.docx");

LayoutCollector layoutCollector = new LayoutCollector(doc);

LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

var collection = doc.GetChildNodes(NodeType.Shape, true);

foreach (Shape shape in collection)

{

var renderObject = layoutCollector.GetEntity(shape);

layoutEnumerator.Current = renderObject;

RectangleF location = layoutEnumerator.Rectangle;

Console.WriteLine("X : " + location.X + " Y : " + location.Y);

Console.WriteLine("Angle : " + shape.Rotation);

}


Please read the following article about inserting watermark in the word document.
http://www.aspose.com/docs/display/wordsnet/How+to++Add+a+Watermark+to+a+Document

Please note that Aspose.Words mimics the same behaviour as MS Word does. In your case, the image size (width) is greater then default page size. For this case, DocumentBuilder.InsertImage does not mimics the MS Word behavior. This is an issue and logged in our issue tracking system as WORDSNET-10718. We will update you via this forum thread once this issue is resolved. We apologize for your inconvenience.

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

The issues you have found earlier (filed as WORDSNET-10718) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)