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

Free Support Forum - aspose.com

Creating a line in the footer

Hi,

I’m having trouble trying to dynamically generate a line at the bottom of the page with my footer. I’ve called ProcessParagraphs() used an ImageStamp, TextStamp, and PageNumberStamp for most of the footer content, but I’ve been unable to find a good way to position a page rule above this. This line will be about 40 points from the bottom margin and the page’s bottom margin is about 47 points. The only way I’ve gotten something to draw properly is using the header, but it looks like the line disappears when page.PageInfo.isLandscape = true.

foreach (Page page in PdfDoc.Pages)
{
page.AddStamp(imageStamp);
page.AddStamp(textStamp);
page.AddStamp(pageNumberStamp);

page.Header = new HeaderFooter { Margin = new MarginInfo(27f, 0, 0, 0) };

var graph = new Aspose.Pdf.Drawing.Graph((float)page.MediaBox.Width, (float)page.MediaBox.Height);
var ruleLength = page.MedianBox.Width - 54;
var posArray = new[]
{
0f,
40f,
ruleLength,
4
};
var line = new Aspose.Pdf.Drawing.Line(posArray)
{
GraphInfo = { LineWidth = 0.75f }
};
graph.Shapes.Add(line);
page.Header.Paragraphs.Add(graph);
}

Is there a better way for me to position this line that won’t affect the content that’s already rendered in the page’s paragraphs?

Hi Ryan,


Thanks for your inquiry. You may use CreatePolyLine() method of PdfContentEditor class to add horizontal line in footer of the page. Please check following code snippet for the purpose, it will help you to accomplish the task.

string inputFile = @“c:\test.pdf”; // Any file<o:p></o:p>

string outputFile = @“c:\out.pdf”;<o:p></o:p>

// instantiate PdfContentEditor object<o:p></o:p>

using (PdfContentEditor editor = new PdfContentEditor())<o:p></o:p>

{<o:p></o:p>

// bind the source PDf file<o:p></o:p>

editor.BindPdf(inputFile);<o:p></o:p>

// create lineinfo object<o:p></o:p>

LineInfo lineInfo = new LineInfo();<o:p></o:p>

// specify the dimensions for line object<o:p></o:p>

lineInfo.VerticeCoordinate = new float[] { 0, 70, 600, 70 };<o:p></o:p>

// specify the visibility of line to true<o:p></o:p>

lineInfo.Visibility = true;<o:p></o:p>

// create a polyline<o:p></o:p>

editor.CreatePolyLine(lineInfo, 1, new System.Drawing.Rectangle(1, 1, 1, 1), “Welcome to Aspose”);<o:p></o:p>

// save the update PDF with horizontal line<o:p></o:p>

editor.Save(outputFile);<o:p></o:p>

}


Please feel free to contact us for any further assistance.

Best Regards,

Hi,


Thanks for the help, but unfortunately the CreatePolyLine is not the kind of line I’m looking for. It creates an interactive line that also has an annotation. I still need a static line that a user can’t interact with to create a page rule on the screen. Is there another way to position the graph on the page without affecting the rest of the pages paragraph content?

Hi Ryan,


Thanks for your feedback. You may flatten the PDF document to overcome the user interaction issue with the line as following. However if you still facing any issue then please share your sample code here and input/output document, it will help us to understand your issue exactly and we will address it accordingly.

Document doc = new
Document(inputFile);<o:p></o:p>

// instantiate PdfContentEditor object

PdfContentEditor editor = new PdfContentEditor();

// bind the source PDf file

editor.BindPdf(doc);

// create lineinfo object

LineInfo lineInfo = new LineInfo();

// specify the dimensions for line object

lineInfo.VerticeCoordinate = new float[] { 0, 70, 600, 70 };

// specify the visibility of line to true

lineInfo.Visibility = true;

// create a polyline

editor.CreatePolyLine(lineInfo, 1, new System.Drawing.Rectangle(1, 1, 1, 1), "");

// save the update PDF with horizontal line

doc.Flatten();

doc.Save(outputFile);

Please feel free to contact us for any further assistance.


Best Regards,