We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add page number to footer

Hi Ying,


Thanks for sharing the additional information. We are looking into it and will update you with our findings soon.

We are sorry for the inconvenience.

Best Regards,

Hi, just wondering what is your finding…

thanks,
Ying

Hi Ying,


Thanks for sharing the details and sorry for the delayed response.

In earlier response, you have shared a connection string but in order to fill the data inside the code, I need a database from which I need to programatically pull the data. Therefore as requested earlier, can you please share some sample project along with database backup/dump, so that we can again try replicating the issue in our environment. We are sorry for this inconvenience.

Hi,

i am generate pdf document by clink on a link in the page, i used to have this code pdf.Save(“Trustee.pdf”, SaveType.OpenInAcrobat, Response)
i believe it opened pdf by click on a link in the page.

now i have my page redone, and i can save the pdf as a file on directoy, but i can’t get the pdf open by click on the link in my page.
here is the code to same the pdf to a file on the directory.
doc.Save(filename, SaveFormat.Pdf) it works without problem

how do i get the pdf to open directly?

thanks
Ying


Hi,

have you get a chance to look at this?

thanks,
Ying

Hi Ying,


Thanks for sharing the details and sorry for the delayed response.

When using new Document Object Model of Aspose.Pdf namespace, you can save the output in Stream object and pass Stream contents to Response object, so that PDF file is rendered inside web browser.

[C#]

FileStream fs = new
FileStream(“c:/pdftest/SampleFileTextFragment.pdf”,
FileMode.Open, FileAccess.ReadWrite);<o:p></o:p>

// Instantiate Document instance

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);

Aspose.Pdf.Facades.FormEditor fe = new Aspose.Pdf.Facades.FormEditor(pdfDocument);

string submissionUrl = "http://localhost/app1/forms/test1";

string label = "Submit";

fe.SubmitFlag = Aspose.Pdf.Facades.SubmitFormFlag.Fdf;

fe.AddSubmitBtn(string.Format("SUBMITFORM_{0}", 1), 1, label, submissionUrl, 500, 765, 600, 790);

fe.Save(fs);

fs.Dispose();

MemoryStream stream = new MemoryStream();

// Save resulting PDF document.

pdfDocument.Save(stream);

StreamReader reader = new System.IO.StreamReader(Request.InputStream);

String Data = reader.ReadToEnd();

this.Title = Data;

Response.Clear();

Response.ClearHeaders();

Response.ClearContent();

Response.Buffer = true;

Response.Charset = "UTF-8";

Response.AddHeader("Accept-Header", stream.Length.ToString());

Response.AddHeader("Content-Length", stream.Length.ToString());

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

Response.AddHeader("Pragma", "cache");

Response.AddHeader("Cache-Control", "private");

Response.AddHeader("content-disposition", String.Format("inline;filename={0}", "article" + "docId"+ ".pdf"));

Response.ContentType = "application/pdf";

Response.AddHeader("Accept-Ranges", "bytes");

Response.BinaryWrite(stream.ToArray());

Response.Flush();

Response.End();

Hi, thank you for your help. do you have VB code for this? thanks again. Ying

Hi,

above code seems read a existing PDF, my case is different. i am generate a pdf document from database and i want this document opens in broswer instead of save it to a directory.

thanks,
Ying

Hi Ying,


Thanks for sharing the details.

Please try using the following code snippet to create new PDF document and render the output in web browser using VB.NET.

[VB.N]

’ Instantiate Document instance<o:p></o:p>

Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document()

pdfDocument.Pages.Add()

pdfDocument.Pages(1).Paragraphs.Add(New Aspose.Pdf.Text.TextFragment("First page of Document..."))

Dim fe As Aspose.Pdf.Facades.FormEditor = New Aspose.Pdf.Facades.FormEditor(pdfDocument)

Dim submissionUrl As String = "http://localhost/app1/forms/test1"

Dim label As String = "Submit"

fe.SubmitFlag = Aspose.Pdf.Facades.SubmitFormFlag.Fdf

fe.AddSubmitBtn(String.Format("SUBMITFORM_{0}", 1), 1, label, submissionUrl, 500, 765, 600, 790)

fe.Save(fs)

fs.Dispose()

Dim stream As MemoryStream = New MemoryStream()

' Save resulting PDF document.

pdfDocument.Save(stream)

Dim reader As StreamReader = New System.IO.StreamReader(Request.InputStream)

Dim Data As String = reader.ReadToEnd()

'this.Title = Data

Response.Clear()

Response.ClearHeaders()

Response.ClearContent()

Response.Buffer = True

Response.Charset = "UTF-8"

Response.AddHeader("Accept-Header", stream.Length.ToString())

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

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

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

Response.AddHeader("Cache-Control", "private")

Response.AddHeader("content-disposition", String.Format("inline;filename={0}", "article" + "docId" + ".pdf"))

Response.ContentType = "application/pdf"

Response.AddHeader("Accept-Ranges", "bytes")

Response.BinaryWrite(stream.ToArray())

Response.Flush()

Response.End()

Is there a way to apply a border (border color) around the page numbers? All I am doing is displaying simple page numbers at the footer of each page. I am not finding a way to apply styles for the page numbers

Using the following code-

var PageNumberText = new FormattedText("#", new FontColor(86, 86, 86), FontStyle.CourierBold, EncodingType.Winansi, false, 14);
var pageNumberStamp = new PageNumberStamp(PageNumberText);
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Right;
pageNumberStamp.VerticalAlignment = VerticalAlignment.Bottom;
pageNumberStamp.BottomMargin = 40;
pageNumberStamp.RightMargin = 15;
pageNumberStamp.ZoomX = 1;
pageNumberStamp.ZoomY = 1;

@adityarlv,

As per my understanding, you need to draw some border around the page number information. If so is the case, then please add rectangle around the page number information.

@adityarlv,

Please take a look over following code snippet to accomplish your requirement. Please note that in order to set vertical alignment, the position value is obtained by dividing page height. In case you encounter any issue, please share the input PDF file.

[C#]

// Open document
Document pdfDocument = new Document("c:/pdftest/AnchorText.pdf");

var PageNumberText = new FormattedText("#", new FontColor(86, 86, 86), Aspose.Pdf.Facades.FontStyle.CourierBold, EncodingType.Winansi, false, 14);
// Create page number stamp
PageNumberStamp pageNumberStamp = new PageNumberStamp(PageNumberText);//"#", new FontColor(86, 86, 86), FontStyle.CourierBold, EncodingType.Winansi, false, 14);
// Whether the stamp is background
pageNumberStamp.Background = false;
pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;
pageNumberStamp.BottomMargin = 10;  
pageNumberStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
pageNumberStamp.StartingNumber = 1;
// Set text properties
pageNumberStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
pageNumberStamp.TextState.FontSize = 14.0F;
pageNumberStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
pageNumberStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Italic;
pageNumberStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Aqua;

// create Graph object 
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100,200);
// Create rectangle object with specific dimensions
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle((float)pdfDocument.Pages[1].PageInfo.Width / 2 - 130, -(((float)pdfDocument.Pages[1].PageInfo.Height)/2)-138, 80, 20);
Console.WriteLine((float)pdfDocument.Pages[1].PageInfo.Height);
// Add rectangle object to shapes collection of Graph instance
canvas.Shapes.Add(rect);

// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(pageNumberStamp);
pdfDocument.ProcessParagraphs();
Console.WriteLine(pageNumberStamp.XIndent);
Console.WriteLine(pageNumberStamp.RightMargin);

pdfDocument.Pages[1].Paragraphs.Add(canvas);
// Save output document
pdfDocument.Save("c:/pdftest/PageNumnber.pdf");

Thanks for the code.

But my case here is not to display the entire rectangle, but only show borders on right and bottom sides of the page numbers. Is there a way to achieve this (like using some style on the page numbers)

@adityarlv,

In order to fulfill above stated requirement, you need to draw two line objects. For more information, please visit Add Line object to PDF file.

@codewarior,

Thanks, that was exactly what I was looking for.