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
string outputFile = @"c:\out.pdf";

// Instantiate PdfContentEditor object
using (PdfContentEditor editor = new PdfContentEditor())
{
    // Bind the source PDF file
    editor.BindPdf(inputFile);

    // Create LineInfo object
    LineInfo lineInfo = new LineInfo();

    // Specify the dimensions for the line object
    lineInfo.VerticeCoordinate = new float[] { 0, 70, 600, 70 };

    // Set the visibility of the line to true
    lineInfo.Visibility = true;

    // Create a polyline
    editor.CreatePolyLine(lineInfo, 1, new System.Drawing.Rectangle(1, 1, 1, 1), "Welcome to Aspose");

    // Save the updated PDF with the horizontal line
    editor.Save(outputFile);
}

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);

// 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 the line object
lineInfo.VerticeCoordinate = new float[] { 0, 70, 600, 70 };

// Set the visibility of the line to true
lineInfo.Visibility = true;

// Create a polyline
editor.CreatePolyLine(lineInfo, 1, new System.Drawing.Rectangle(1, 1, 1, 1), "");

// Flatten the document
doc.Flatten();

// Save the updated PDF with the horizontal line
doc.Save(outputFile);

Please feel free to contact us for any further assistance.

Best Regards,