|
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
|
|
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!
|
|
Rank: Newbie Groups: Member
Joined: 10/16/2011 Posts: 7
|
Thanks a lot for the quick response. Now it works perfectly:)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
You are very welcome. Let us know if you need anything else.
Thanks!
|
|