|
|
How to get the page number and display it
Last post 07-18-2008, 9:06 AM by seawolf. 12 replies.
-
07-04-2008, 12:54 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
How to get the page number and display it
Hi,
I am new to aspose. I want to get the page number of the document in the following format
Page Number / Total Page Number (e.g 3/99. in this 3 is page number and 99 is total pages).
I need to display page number in this format as watermark. Is there any method to get the each page number and total page number. so that i can add this as a string the in the stamp and i can display it as a water mark. Kindly help me in this.
Thank you in advance
Regards
Srirangam K
|
|
-
07-04-2008, 3:28 AM |
-
07-07-2008, 7:54 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
Re: How to get the page number and display it
Hi,
FileStream aFS = new FileStream(@"C:\CSharp.pdf", FileMode.Open, FileAccess.Read);
Int32 aLength = (Int32)aFS.Length;
FileStream aOS = new FileStream(@"C:\CSharpcopy.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
MemoryStream aMS1 = new MemoryStream(aLength + 1000000);
PdfFileStamp aPFS = new PdfFileStamp(aFS, aMS1);
FormattedText aFT = new FormattedText(DateTime.Now.ToString());
aPFS.AddFooter(aFT,20);
//Instantiate a stamp object
Stamp logoStamp = new Stamp();
//Instantiate an object of FormattedText class
FormattedText formatText = new FormattedText("User Name", System.Drawing.Color.FromArgb(192, 192, 192), FontStyle.TimesItalic, EncodingType.Winansi, false, 50);
//BindLogo to PDF
logoStamp.BindLogo(formatText);
logoStamp.Rotation = 50;
logoStamp.SetOrigin(200, 275);
aPFS.AddStamp(logoStamp);
PdfFileInfo fileInfo = new PdfFileInfo(@"C:\CSharp.pdf");
FormattedText ft = new FormattedText("#" + "/" + fileInfo.NumberofPages);
aPFS.AddPageNumber(ft);
aPFS.Close();
aMS1.WriteTo(aOS);
aFS.Close();
aMS1.Flush();
aMS1.Close();
I am using the above code. here i am trying to add water mark, footer and page number. Now i have placed the code for adding page number, below the footer and water mark. now what is hppening is only page number is displayed in the page. Footer and water mark is not getting displayed. i have given different position for displaying page number like bottom right, upper right. but still footer and water mark is not getting displayed. If i move the adding page number code above the footer and water mark display code then page number is not getting displayed. but footer and water mark are getting displayed. I think footer and water mark is overwriting page number. Depends on the order of the code one thing is overwriting others. Kindly help me how to display water mark, footer and page number together.
Thank you............
Regards
Srirangam K
|
|
-
07-07-2008, 3:28 PM |
-
codewarior
-
-
-
Joined on 05-05-2008
-
-
Posts 570
-
-
-
-
|
Re: How to get the page number and display it
Hello Srirangam,
We apologies for the inconvenience. I have tested the code and have been able to reproduce the issue. I have discussed it with the concerned department, soon you will be udpated with the status.
Nayyer Shahbaz Support Developer Aspose Changsha Team About Us
|
|
-
07-08-2008, 8:35 AM |
-
seawolf
-
-
-
Joined on 04-01-2006
-
-
Posts 119
-
-
-
-
|
Re: How to get the page number and display it
hi,
Sorry for the inconvenience, I make some complements for the PdfFileStamp, in PdfFileStamp, the function of AddStamp and the function of AddPageNumber can not be used at the same time, or only one function work. We will add some comments for the use of these functions. now I modified your code in order to finished your task, please refer to the code below:
FileStream aFS = new FileStream(TestPath +"example1.pdf", FileMode.Open, FileAccess.Read); FileStream aOS = new FileStream(TestPath +"addFooter_out.pdf", FileMode.Create, FileAccess.ReadWrite); MemoryStream ms = new MemoryStream(); PdfFileStamp aPFS1 = new PdfFileStamp(aFS, ms); FormattedText aFT = new FormattedText(DateTime.Now.ToString()); aPFS1.AddFooter(aFT, 20, 30, 0); Stamp logoStamp = new Stamp(); FormattedText formatText = new FormattedText("User Name", System.Drawing.Color.FromArgb(192, 192, 192), FontStyle.TimesItalic, EncodingType.Winansi, false, 50); logoStamp.BindLogo(formatText); logoStamp.Rotation = 50; logoStamp.SetOrigin(200, 275); aPFS1.AddStamp(logoStamp); aPFS1.Close(); PdfFileInfo fileInfo = new PdfFileInfo(TestPath + "example1.pdf"); ms.Position = 0; PdfFileStamp aPFS2 = new PdfFileStamp(ms, aOS); FormattedText ft = new FormattedText("#" + "/" + fileInfo.NumberofPages); aPFS2.AddPageNumber(ft); aPFS2.Close(); aFS.Close(); aOS.Close();
Allen Wen Developer Aspose Changsha Team
|
|
-
07-09-2008, 2:37 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
Re: How to get the page number and display it
Hi,
Thank you for your quick reply. The work around which was given by is working fine. Once againg thank you for your quick respone. Actually i need one more clarification. Can we display the page number anywhere in the page or we should display it only in the predefined positions like bottom middle, top center, top right etc? Because in my application i should display it in the center of the page like water mark display. is it possible to display it in the center of the page? Kindly help me on this.
Thank you in advance
Regards
Srirangam K
|
|
-
07-09-2008, 4:34 AM |
-
seawolf
-
-
-
Joined on 04-01-2006
-
-
Posts 119
-
-
-
-
|
Re: How to get the page number and display it
Hi,
Now, no method in our kit supports to add page number anywhere like water mark display, but we can add such a method to support your application.
Allen Wen Developer Aspose Changsha Team
|
|
-
07-09-2008, 7:06 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
Re: How to get the page number and display it
Hi Allen Wen,
Can you give me the method to add page number anywhere in the page as you told? so that it will be very greatful for us. As I told I need to display the page number in the center of the page.
Regards
Srirangam K
|
|
-
07-09-2008, 9:27 AM |
-
seawolf
-
-
-
Joined on 04-01-2006
-
-
Posts 119
-
-
-
-
|
Re: How to get the page number and display it
Hi,
Sorry for not explainning this problem carefully.
First, our kit don't support add page number anywhere, but we can add a interface to support the function.
Second, if you only need add page number in the center of the page, you can refer to the code below:
FileStream aFS = new FileStream(TestPath +"example1.pdf", FileMode.Open, FileAccess.Read); FileStream aOS = new FileStream(TestPath +"addFooter_out.pdf", FileMode.Create, FileAccess.ReadWrite); PdfFileStamp aPFS1 = new PdfFileStamp(aFS, aOS ); PdfFileInfo fileInfo = new PdfFileInfo(TestPath + "example1.pdf"); FormattedText ft = new FormattedText("#" + "/" + fileInfo.NumberofPages); //you can adjust the leftMargin or rightMargin to adapt your document aPFS1.AddPageNumber(ft,6,300,0,0,0); aPFS1.Close(); aFS.Close(); aOS.Close();
Allen Wen Developer Aspose Changsha Team
|
|
-
07-10-2008, 12:40 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
Re: How to get the page number and display it
Hi Allen,
Once again thank you for your quick response. Actually can i display the page number with particular angle. because water mark we can display with particular angle using "Rotation" Property. Is any way to display the page number in particular angle? Kindly help me on this.
Thank You
Regards
Srirangam K
|
|
-
07-10-2008, 2:15 AM |
-
seawolf
-
-
-
Joined on 04-01-2006
-
-
Posts 119
-
-
-
-
|
Re: How to get the page number and display it
Hi,
Our kit don't support to display the page number in particular angle now, but we can not improve the AddPageNumber to support rotation.
Allen Wen Developer Aspose Changsha Team
|
|
-
07-10-2008, 6:40 AM |
-
yuvan
-
-
-
Joined on 06-27-2008
-
-
Posts 26
-
-
-
-
|
Re: How to get the page number and display it
Hi Allen,
Thank you. So we can't display the page number with angle of rotation. I will give this as reference to my client and try to convince them.
Thank You
Regards
Srirangam K
|
|
-
07-18-2008, 9:06 AM |
-
seawolf
-
-
-
Joined on 04-01-2006
-
-
Posts 119
-
-
-
-
|
Re: How to get the page number and display it
Hi,
In my last post, I am sorry that a typewriting error was happened, my real intent is that we can improve the function of AddPageNumber to support rotation, moreover, we have finished the work and the function will appear in our future verion.
Allen Wen Developer Aspose Changsha Team
|
|
|
|