Watermark is Shrinking on big Pdfs (Poster size)

Watermark is Shrinking on big Pdfs (Poster size)

I wonder if there is an absolute and relative approach to the waterwark size on a document

see below for more details......

CASE #

PDFKITNET-5763

Hi,

I am using the following code. I used font size as 40 to display the watermark. but for some document the watermark is diplayed with the proper font size. for certain pdf document the font size is getting shrunk. for some other file it is saying that font is not available. so it is displaying watermark as dots. for all the documents same code and machine is used to display the watermark.

Shrink Watermark Display doc: ShrinkWatermark.pdf ( Look in the left bottom of doc to see the watermark. see the text NBCUConfidential. This text is displayed as watermark)

Original Shrink Watermark Display doc: OriginalShrinkWatermark.pdf(Use this doc to reproduce the issue)

Font Not Supporting doc: Fontnotsupporting.pdf (Here watermark is displyed as dots since font is not supported. In the same machine for other docs water mark is coming. only for this doc it is coming as dots)

Original Font Not Supporting Doc: OriginalFontNotSupporting.pdf (Use this doc to reproduce the same)

Proper Watermark Display Doc: Properwatermarkdisplay.pdf (For this document watermark is displayed properly)

Original Proper watermark display doc: orginalproperwatermarkdisplay.pdf (Use this doc for testing)

Note: All the docs are used in the same machine using the below code. In the same machine and for same code, it is giving different result. I think there should be some document dependency.

Kindly go through these issues and give me solution as early as possible.

aFS = New FileStream(strfilename, FileMode.Open, FileAccess.Read)

aMS1 = New MemoryStream

Dim aPFS As PdfFileStamp = New PdfFileStamp(aFS, aMS1)

' Add Footer

Dim aFT As FormattedText = New FormattedText(DateTime.Now.ToString(), System.Drawing.Color.FromArgb(0, 0, 255), "Arial", EncodingType.Winansi, False, 12)

aPFS.AddFooter(aFT, 20)

'Instantiate a stamp object

Dim strWatermark As String = ConfigurationSettings.AppSettings("WaterMarkText")

Dim logoStamp As Stamp = New Stamp

logoStamp.Opacity = 0.5F

Dim formatText As FormattedText = New FormattedText(strWatermark, System.Drawing.Color.FromArgb(192, 192, 192), "Arial", EncodingType.Winansi, False, 40)

formatText.AddNewLineText(strUsername)

'BindLogo to PDF

logoStamp.BindLogo(formatText)

logoStamp.IsBackground = False

logoStamp.Rotation = 50

logoStamp.SetOrigin(100, 150)

aPFS.AddStamp(logoStamp)

aPFS.Close()

Dim aPdfFI As New PdfFileInfo(strfilename)

Dim aMS2 As MemoryStream = New MemoryStream

Dim aPFS1 As PdfFileStamp = New PdfFileStamp(aMS1, aMS2)

Dim formatPageNoText As FormattedText = New FormattedText("Page #" + " of " + aPdfFI.NumberofPages.ToString(), System.Drawing.Color.FromArgb(0, 0, 255), "Arial", EncodingType.Winansi, False, 10)

aPFS1.AddPageNumber(formatPageNoText, 1)

aPFS1.Close()

a = aMS2.ToArray()

Response.Clear()

Response.AddHeader("Content-Length", a.Length.ToString())

Response.AppendHeader("Content-disposition", "filename=" + filename)

Response.ContentType = "application/pdf"

Response.AddHeader("Expires", "0")

Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0")

Response.AddHeader("Pragma", "public")

Response.BinaryWrite(a)

Response.Flush()

aFS.Flush()

aFS.Close()

aMS1.Flush()

aMS1.Close()

aMS2.Close()

aMS2.Close()

Response.End()

Thank You

Regards

Srirangam K

Hello Srirangam,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The issue is not with adding watermark. Once the watermark is applied, the customer is advised to view the pdf with zoom factor to 100%. When viewing the pdf at 50%, watermark appears to shrink. You can also check it by your self, while accessing the customers file, if it’s not marked as private.

I understand what you are saying but that's not my business need, what I need is....

I need to apply a watermark across the whole document so when is printed, my watermark cover the whole document and not only a small section, Does Aspose offers any way to achieve this?

Regards.

AJ Ornelas.

Hi,

We are working on this issue and we will reply to you ASAP..

As for PDFKITNET-5763, the problem that the font can not be created has been solved.

Hi Guys,

I need an update on the watermark shrinking, when are you going to provide a fix or what is the plan here, please share

Regards,

AJ Ornelas.

Hi,

As for the watermark shrinking problem, we think you can augment the size of the font and adjust the coordinate of watermark according to your pdf size. The attachment is an example of adding watermark in large page size, the page size of the attachment is A0 (2384, 3370), the watermark can across the whole document.

BTW: please post your pdf documents in which the watermark is shrunk., it can help me to investigate this problem.

I understand what you are saying but that's not my business need, what I need is....

I need to apply a watermark across the whole document so when is printed, my watermark cover the whole document and not only a small section, Does Aspose offers any way to achieve this?

Regards.

AJ Ornelas.

--------------------------------------------------------------------------------


hi

I have attached the sample pdf document without(OrgShrinkingWatermark.pdf) and with watermark(ShrinkingWatermark.pdf ). Give me solution for the watermark to print across the whole document for poster size pdf asap.



Srirangam.

Hi,

I guess your requirement would be to apply a watermark, with the proper size and location, to a random size document. If so, you need to rewrite some lines of your code, to ajust the related parameters(list below) based the page size of the document. (more details about getting page size, please refer to PdfPageEditor.GetPageSize and PageSize Properties)

Dim formatText As FormattedText = New FormattedText(strWatermark, System.Drawing.Color.FromArgb(192, 192, 192), "Arial", EncodingType.Winansi, False, 40)

logoStamp.SetOrigin(100, 150)

Thanks,

Hi Felix,

You mean to say we can get the size of the pdf and according to that we need to set the font size and coordinates of the watermark?

Regards,

Srirangam.

Hi,

Yes, because the current version of Aspose.Pdf.Kit does not support the feature of automaticlly adjusting for watermark, you need to set the font size and coordinates according to the size of Pdf files.

Thanks & Regards,

hi Felix,

But the size of the pdf file is not going to be same it varies.How can we set the font for pdf of different sizes?Can you give me any sample code for it or Is there anyother way we can implement it?

Regards,

Srirangam.

Hi Srirangam,

FYI, the following is a sample witten in C#, hope that would be help.

PdfPageEditor pageGetter = new PdfPageEditor(); //use PdfPageEditor to get page size
pageGetter.BindPdf(InPath+"variableSize.pdf");
PageSize thePageSize = pageGetter.GetPageSize(1); // should get the page number if the pagesize differs inside a pdf, here we get page 1
int fontSize = ProperFontSize(thePageSize.Width,thePageSize.Height); // the ProperFontSize defined below
PdfFileStamp fileStamp= new PdfFileStamp(InPath+"variableSize.pdf",OutPath+"PageAndFont.pdf");
Stamp fontStamp = new Stamp();
FormattedText fTxt= new FormattedText("NBCU Confidencial",Color.Red,"Arial",EncodingType.Winansi,false,fontSize);
fTxt.AddNewLineText("Felix Liu test");
fontStamp.BindLogo(fTxt);
fontStamp.Rotation=45;
//fontStamp.SetOrigin(100,150);
fileStamp.AddStamp(fontStamp);
fileStamp.Close();

///


/// caculate the proper font size for stamping to a PDF page
///

/// the width of the page
/// the height of the page
/// the font size
public int ProperFontSize(float width,float height) //the function works in my testing, for your requirement, maybe you want to rewrite it with cases statement or with different formula.
{
int fontsize = 0;
if (width<height) // portait , calulate the fontsize with the width
{
fontsize = (int)width/10;
}
else // landscape, caculate it with height
{
fontsize = (int)height/10;
}
return fontsize;
}

Thanks,

hi Felix,

Thank you.I will use it according to my requirement.

Regards,

Srirangam.