|
Rank: Newbie Groups: Member
Joined: 12/13/2011 Posts: 7
|
Hello,
I need to insert an image at the end of the pdf content. Can you help me with the calculation formula for that. And is there a way to prevent the image from splitting into a next page if the content ends almost at the bottom of the last page?
Alex
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Do you mean you will have one or more pages of the "main content", then immediately follow the "main content", you have an additional image? In that case the easiest way is to call ConvertHtml/ConvertUrl twice:
Code: C#
PdfDocument doc = new PdfDocument();
//Convert the main content
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(main_content_html, doc);
//This is the key to let the second conversion to continue
//from where the first conversion ends
HtmlToPdf.Options.Follow(result);
//Add the image at the end of the previous conversion
HtmlToPdf.ConvertHtml(additional_image_html, doc);
To avoid the image being splitted into next page, apply "page-break-inside:avoid" on your image element. Note: Make sure you download the latest build from our download page. Earlier build may have problems with the above code. Hope this helps. Please feel free to let us know if you still have questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/13/2011 Posts: 7
|
Thank You, but I actually need to insert the image at the end of the pdf file already created from HTML page and saved on a drive. I have a sdynamic image that is being pulled into the pdf document from the project folder. I am able to get the value of the LastPosition, but do not know which function to usse next.
int lastPosition = Convert.ToInt32(result.LastPosition); doc.Pages[lastPageIndex].Contents.Insert(lastPosition, imageContent2); - is not working for me
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, As soon as you have last position and last page index, the easiest way is still to use HtmlToPdf:
Code: C#
HtmlToPdf.Options.StartPosition = lastPosition;
HtmlToPdf.Options.StartPageIndex = lastPageIndex;
HtmlToPdf.ConvertHtml(
"<img src='file:///c:/images/your_image.gif' />", doc);
You could use Contents.Insert, but the coordination system used by "PdfContent" is different than HTML to PDF. So you have to convert them. Beside that you have to scale the image. So it's much more work to go that way. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/13/2011 Posts: 7
|
Thank you for your help, it solved my bottom image location problem. Now I am chalenged with another issue. I need to insert table (or 6 fields with data) after the first paragraph on the first page( something like a document summory with the data from a database, not from a converted HTML page). How can I calculate an exact coordinates of the starting xy axis and witch EO class to use in this case?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, The ConvertHtml/ConvertUrl function returns an HtmlToPdfResult object. With that object you can find any DOM element and the location of that element. For example:
Code: C#
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(your_html, doc);
HtmlElement e = result.HtmlDocument.GetElementById("element_id");
PdfPageLocation location = e.Location;
Hope this helps. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 12/13/2011 Posts: 7
|
I am actually trying to insert an image into the existing pdf document after the conversion from HTML page. I was able to get correct coordinates from the LastPosition. But when I am using Page.Contents.Insert it inserts the image above the existing text. I need to be able for the existing content to ajust and expand after the image is created. Can you guide me to the correct object in your dll?
Thank You
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Please see this post for more details about the two different coordination system: http://www.essentialobjects.com/forum/postst6265_PDF-Creator--Table-Object.aspxThanks!
|
|