|
Rank: Newbie Groups: Member
Joined: 1/16/2014 Posts: 7
|
Hi. I am using HtmlToPdf to create a document. Is it possible to change the output area of a page after the conversion has been performed? I would like to search for an html class in the HtmlDocument, find on which page that element has been rendered, and then change that page to landscape.
If it's not possible after the conversion, is it possible by hooking up to HtmlToPdf.Options.BeforeRenderPage or HtmlToPdf.Options.AfterRenderPage? Within these events, is it possible to search the markup from which these pages are being created?
Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, No. You can not change the page dimension during or after the conversion. You can only set it before the conversion. It is possible for you to find out which page an element is rendered on, but it is not possible for you to change the dimension of that page at this point. The closest you can do is transform the page (move, rotate, etc): http://www.essentialobjects.com/doc/4/eo.pdf.pdfpage.transform.aspxHowever that would rotate the whole thing, not just the page. For example, if you rotate a page to landscape, then all text will become vertical. So it may not be what you wanted. If you do have to have different page layout in the same PdfDocument, you will have to call the converter multiple times, each time with different page settings. Each call will produce a separate PdfDocument object. After that you can merge them into a single PdfDocument object by calling PdfDocument.Merge. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2014 Posts: 7
|
Great, I think rotate should do it, because these particular pages will only contain images. Can I do that after the conversion? If not, and I have to do it during BeforeRenderPage or AfterRenderPage, then how do I get the page's html markup from within these event handlers?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, You would do it after the conversion. You do not get the markup, but rather you can "locate" a specific HTML element. The key is the ConvertUrl/ConvertHtml method returns you a HtmlToPdfResult object. The code would be something like this:
Code: C#
PdfDocument doc = new PdfDocument();
//Perform the conversion
HtmlToPdfResult result = HtmlToPdf.ConvertUrl(url, doc);
//Get an HtmlElement object by name. This assume there is an element
//in your input HTML file with id "some_id"
HtmlElement element = result.HtmlDocument.GetElementById("some_id");
//Get the PDF page on which this element is rendered
PdfPage page = element.Location.Page;
You can take a look of the reference section to see all the related objects and other methods/properties they have. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2014 Posts: 7
|
It turns out that rotating does not do what I want, as it only rotates the contents of the page. It doesn't turn the page itself.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Have you try to modify the page's Size property also?
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/16/2014 Posts: 7
|
But you said above that you cannot change a pages dimensions after a conversion.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
What we meant was in term of the contents. I believe you can change the "physical page size" anyway you want. But for most people this is useless unless the contents can be re-layouted accordingly, which is not possible. However in your case if you only have a single image on the page, you might be able to use Page.Transform and Page.Size together to achieve the desired result.
Thanks!
|
|