Hi Yinf,
Thanks for sharing the details. Can you please share some sample project, so that we can test the scenario in our environment. We are sorry for your inconvenience.
Hi Yinf,
Thanks for sharing the details. Can you please share some sample project, so that we can test the scenario in our environment. We are sorry for your inconvenience.
Hi Ying,
Hi Ying,
thanks for your response.
Hi Ying,
Hi, just wondering what is your finding…
Hi Ying,
Hi,
Hi,
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);
// 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,
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
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)
Dim fs As MemoryStream = New MemoryStream()
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()
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;
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.
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)
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.