Welcome Guest Search | Active Topics | Sign In | Register

How to create a border around PDF pages Options
MSAT
Posted: Sunday, October 16, 2011 8:25:38 AM
Rank: Newbie
Groups: Member

Joined: 10/16/2011
Posts: 7
Hello,

I am evaluating HTML to PDF convertor. I have checked most of the features and the product seems to be extremely good in terms of both fuctionality and performance, compared to other products.

However even after trying for a while, I am unable to put borders around the content on individual PDF pages. All I could understand from documentation was that I need to use PDF creator to achieve the same.

I would appreciate if you could provide me with a sample code or explanation to achieve that. Thanks in advance.

MSat team
eo_support
Posted: Sunday, October 16, 2011 8:54:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The basic idea is you do "multiple runs". For example, you can do something like this:

Code: C#
//Convert the main contents
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl("www.google.com", doc);

//Now add borders to each page with the "PDF Creator" interface
foreach (PdfPage page in doc.Pages)
{
    //The default HTML to PDF margins is 1 inch on all sides.
    //Since the box needs to contain all the main contents,
    //So here we create an AcmRender with 0.5 inch margin
    //on all sides
    AcmRender render = new AcmRender(
        page, 0, new AcmPageLayout(new AcmPadding(0.5f)));

    //Create an AcmBlock with border
    AcmBlock block = new AcmBlock();
    block.Style.Border = new AcmBorder(0.01f);
    block.Style.Width = 7.5f;
    block.Style.Height = 9.5f;

    //Render the block on the page
    render.Render(block);
}

//Save the result
doc.Save("result.pdf");


You can also call HTML to PDF on the second stage like this:
Code: C#
foreach (PdfPage page in doc.Pages)
{
    HtmlToPdf.ConvertHtml(
        "<div style='width:700px;height:900px;border:solid 1px black;'></div>", 
        page);   //Note here you pass the PdfPage, not PdfDocument object
}


However the preferred method is to use PDF Creator interface because for simple output such as a box, PDF creator interface is much faster since it doesn't have to go through HTML parser and renderer.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
MSAT
Posted: Sunday, October 16, 2011 10:26:17 AM
Rank: Newbie
Groups: Member

Joined: 10/16/2011
Posts: 7
Thanks a lot for the quick response. Now it works perfectly:)
eo_support
Posted: Sunday, October 16, 2011 10:31:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
You are very welcome. Let us know if you need anything else.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.