Border Issue While Multiple pages


#1

I have big Html in a single string. I cant insert border for the whole page with adding Paragraphs option in aspose, and an issue with border it is overlapping with content my code is below

Document pdfDocument = new Document();
        var htmlStrinfg = "long_html_string";
        var fullc = new HtmlFragment(htmlStrinfg);
        string strHtml = "<table style=\"height: 18px; width: 100%; background-color: #03a9f4;\"><tbody><tr style=\"height: 18px;\"><td style=\"color: blue; height: 18px; width: 98.8166%;\" align=\"left\"><span style=\"color: #ffffff;\"> [TemplateName]12</span></td><td style=\"height: 18px; width: 0.986193%;\" align=\"right\"><span style=\"color: #ffffff;\"><img id=\"imgCompanyLogo\" style=\"width: 312px; height: 100px;\" src=\"../images/CompanyLogoPdf.png\" /></span></td></tr></tbody></table>";

        Aspose.Pdf.HtmlFragment headerHtml = new Aspose.Pdf.HtmlFragment(strHtml);
        Aspose.Pdf.HeaderFooter hf;

        foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
        {
            Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)page.PageInfo.Width, (float)page.PageInfo.Height);
            page.PageInfo.Margin = new MarginInfo(0, 1, 0, 65);
            page.Paragraphs.Add(graph);
            Aspose.Pdf.Drawing.Line bottomline = new Aspose.Pdf.Drawing.Line(new float[] { 10, 10, (float)page.PageInfo.Width - 10, 10 });
            Aspose.Pdf.Drawing.Line topline = new Aspose.Pdf.Drawing.Line(new float[] { 10, (float)page.PageInfo.Height - 10, (float)page.PageInfo.Width - 10, (float)page.PageInfo.Height - 10 });
            Aspose.Pdf.Drawing.Line rightline = new Aspose.Pdf.Drawing.Line(new float[] { (float)page.PageInfo.Width - 10, 10, (float)page.PageInfo.Width - 10, (float)page.PageInfo.Height - 10 });
            Aspose.Pdf.Drawing.Line leftline = new Aspose.Pdf.Drawing.Line(new float[] { 10, 10, 10, (float)page.PageInfo.Height - 10 });
            graph.Shapes.Add(topline);
            graph.Shapes.Add(bottomline);
            graph.Shapes.Add(rightline);
            graph.Shapes.Add(leftline);

            hf = new Aspose.Pdf.HeaderFooter();
            hf.Paragraphs.Add(headerHtml);
            hf.Margin.Top = 0;
            hf.Margin.Left = 0;
            hf.Margin.Right = 0;
            hf.Margin.Bottom = 10;
            page.Header = hf;
        }

        MemoryStream outStream = new MemoryStream();
        pdfDocument.Save(outStream);
        HttpContext.Current.Response.Expires = 0;
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=output.pdf");
        HttpContext.Current.Response.ContentType = "application/pdf";
        HttpContext.Current.Response.BinaryWrite(outStream.ToArray());
        outStream.Close();
        HttpContext.Current.Response.End();

#2

@mehaboob

Thank you for contacting support.

We have modified your code snippet a little and tried plugging in different values for expected results. Below is a code snippet and generated PDF document for your kind reference. Border_19.9.pdf

Document pdfDocument = new Document();
pdfDocument.Pages.Add();
var htmlStrinfg = "long_html_string";
var fullc = new HtmlFragment(htmlStrinfg);
string strHtml = "<table style=\"height: 18px; width: 100%; background-color: #03a9f4;\"><tbody><tr style=\"height: 18px;\"><td style=\"color: blue; height: 18px; width: 98.8166%;\" align=\"left\"><span style=\"color: #ffffff;\"> [TemplateName]12</span></td><td style=\"height: 18px; width: 0.986193%;\" align=\"right\"><span style=\"color: #ffffff;\"><img id=\"imgCompanyLogo\" style=\"width: 312px; height: 100px;\" src=\"../images/CompanyLogoPdf.png\" /></span></td></tr></tbody></table>";

Aspose.Pdf.HtmlFragment headerHtml = new Aspose.Pdf.HtmlFragment(strHtml);
Aspose.Pdf.HeaderFooter hf;

foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
    Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)page.PageInfo.Width, (float)page.PageInfo.Height);
    page.PageInfo.Margin = new MarginInfo(0, 1, 0, 0);
    page.Paragraphs.Add(graph);
    Aspose.Pdf.Drawing.Line bottomline = new Aspose.Pdf.Drawing.Line(new float[] { 1, 1, (float)page.PageInfo.Width - 1, 1 });
    Aspose.Pdf.Drawing.Line topline = new Aspose.Pdf.Drawing.Line(new float[] { 1, (float)page.PageInfo.Height - 1, (float)page.PageInfo.Width - 1, (float)page.PageInfo.Height - 1 });
    Aspose.Pdf.Drawing.Line rightline = new Aspose.Pdf.Drawing.Line(new float[] { (float)page.PageInfo.Width - 1, 1, (float)page.PageInfo.Width - 1, (float)page.PageInfo.Height - 1 });
    Aspose.Pdf.Drawing.Line leftline = new Aspose.Pdf.Drawing.Line(new float[] { 1, 1, 1, (float)page.PageInfo.Height - 1 });
    graph.Shapes.Add(topline);
    graph.Shapes.Add(bottomline);
    graph.Shapes.Add(rightline);
    graph.Shapes.Add(leftline);

    hf = new Aspose.Pdf.HeaderFooter();
    hf.Paragraphs.Add(headerHtml);
    hf.Margin.Top = 2;
    hf.Margin.Left = 2;
    hf.Margin.Right = 2;
    hf.Margin.Bottom = 10;
    page.Header = hf;
}

MemoryStream outStream = new MemoryStream();
pdfDocument.Save(dataDir + "Border_19.9.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.


#3

Thank you for your response.

Still, we having issues that we have already mentioned. While we inserting Html As content the header is overlapping and the content is coming on outside of the border. and another question is can we add padding for border now it is coming on the edges of the page.
here is my code

Document pdfDocument = new Document();
        var fullc = new HtmlFragment("<H1>Test</H1>");
        string strHtml = "<table style=\"height: 18px; width: 100%; background-color: #03a9f4;\"><tbody><tr style=\"height: 18px;\"><td style=\"color: blue; height: 18px; width: 98.8166%;\" align=\"left\"><span style=\"color: #ffffff;\"> [TemplateName]12</span></td><td style=\"height: 18px; width: 0.986193%;\" align=\"right\"><span style=\"color: #ffffff;\"><img id=\"imgCompanyLogo\" style=\"width: 312px; height: 200px;\" src=\"../images/CompanyLogoPdf.png\" /></span></td></tr></tbody></table>";

        Aspose.Pdf.HtmlFragment headerHtml = new Aspose.Pdf.HtmlFragment(strHtml);
        Aspose.Pdf.HeaderFooter hf;
        pdfDocument.Pages.Add().Paragraphs.Add(fullc);
        foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
        {
            Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)page.PageInfo.Width, (float)page.PageInfo.Height);
            page.PageInfo.Margin = new MarginInfo(0, 1, 0, 0);
            page.Paragraphs.Add(graph);
            Aspose.Pdf.Drawing.Line bottomline = new Aspose.Pdf.Drawing.Line(new float[] { 1, 1, (float)page.PageInfo.Width - 1, 1 });
            Aspose.Pdf.Drawing.Line topline = new Aspose.Pdf.Drawing.Line(new float[] { 1, (float)page.PageInfo.Height - 1, (float)page.PageInfo.Width - 1, (float)page.PageInfo.Height - 1 });
            Aspose.Pdf.Drawing.Line rightline = new Aspose.Pdf.Drawing.Line(new float[] { (float)page.PageInfo.Width - 1, 1, (float)page.PageInfo.Width - 1, (float)page.PageInfo.Height - 1 });
            Aspose.Pdf.Drawing.Line leftline = new Aspose.Pdf.Drawing.Line(new float[] { 1, 1, 1, (float)page.PageInfo.Height - 1 });
            topline.GraphInfo.Color = Color.Red;
            bottomline.GraphInfo.Color = Color.Red;
            rightline.GraphInfo.Color = Color.Red;
            leftline.GraphInfo.Color = Color.Red;

            graph.Shapes.Add(topline);
            graph.Shapes.Add(bottomline);
            graph.Shapes.Add(rightline);
            graph.Shapes.Add(leftline);

            hf = new Aspose.Pdf.HeaderFooter();
            hf.Paragraphs.Add(headerHtml);
            hf.Margin.Top = 2;
            hf.Margin.Left = 2;
            hf.Margin.Right = 2;
            hf.Margin.Bottom = 10;
            page.Header = hf;
        }

The variable fullc will have a long HTML it will be more than 11 pages. I sure aspose will automatically generate pages


#4

@mehaboob

Would you please share your sample HTML string longer than several pages for our reference.