Welcome Guest Search | Active Topics | Sign In | Register

Setting background color for html to pdf conversion Options
Henning
Posted: Tuesday, October 7, 2014 7:56:33 PM
Rank: Member
Groups: Member

Joined: 10/6/2014
Posts: 21
What's the best way to set the background color in the pdf regardless of the color settings in the html? I need to set the color for the whole page - including the area outside the margins - to a specific color.
eo_support
Posted: Tuesday, October 7, 2014 9:34:13 PM
Rank: Administration
Groups: Administration

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

You will need to handle this event:

http://www.essentialobjects.com/doc/4/eo.pdf.htmltopdfoptions.beforerenderpage.aspx

Inside this event handler you can uses the PDF creator interface to fill the page. You can find more information on how to use the PDF creator interface here:

http://www.essentialobjects.com/doc/4/acm/overview.aspx

Please feel free to let us know if you have any more questions.

Thanks!
Henning
Posted: Wednesday, October 8, 2014 8:37:52 AM
Rank: Member
Groups: Member

Joined: 10/6/2014
Posts: 21
Thanks. What Pdf class should be used to render a rectangle with a given color in the complete output area?
eo_support
Posted: Wednesday, October 8, 2014 9:39:06 AM
Rank: Administration
Groups: Administration

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

You can use AcmBlock for that purpose. You will need to read the PDF Creator API and take a look of the samples for "PDF Creator" under the sample application to get an idea how this works. Once you have a basic idea of how it works and if you still have any questions, we will be able to guide you further.

Thanks!
Henning
Posted: Sunday, October 12, 2014 3:36:33 PM
Rank: Member
Groups: Member

Joined: 10/6/2014
Posts: 21
Sorry, but after having read the API documentation I still haven't found a way to do this:
1. Do a basic html to pdf conversion using ConvertHtml
2. Change the output from 1) so that all pages have a fixed background color for the complete size of the pages (sheets)
eo_support
Posted: Sunday, October 12, 2014 9:26:23 PM
Rank: Administration
Groups: Administration

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

I believe our original reply has already answered your question. You need to follow that first. If you have any question or problem following that, you can ask question about that and we can guide you further. There would be no point for us to answer your question at all if you just ignore our reply and ask the same question again. You won't get a different answer just by ignoring our initial answer and posting the same question again. If you believe you have a different question, please explain how your question is different than your original question and we will review your question again.

Thanks!
Teo
Posted: Thursday, December 15, 2016 4:38:14 AM
Rank: Newbie
Groups: Member

Joined: 12/15/2016
Posts: 1
Using ACM Block and BeforeRenderPage didn't work for me as it always rendered the block over the page (except header and footer).

Here is one solution I came up with using the low level API:

HtmlToPdf.Options.AfterRenderPage += delegate (object source, PdfPageEventArgs a)
{
PdfPathContent content = new PdfPathContent();
var rect = new EO.Pdf.Drawing.PdfPathRectSegment(new EO.Pdf.Drawing.PdfRectangle(0, 0, 1000, 1000));
EO.Pdf.Drawing.PdfSubPath subPath = new EO.Pdf.Drawing.PdfSubPath();
subPath.From = new EO.Pdf.Drawing.PdfPoint(1000, 0);
subPath.Segments.Add(rect);
content.Path.SubPaths.Add(subPath);
content.NonStrokingColor = options.BackgroundColor;
content.Action = PdfPathPaintAction.Fill;

a.Page.Contents.Insert(0, content);
};
eo_support
Posted: Thursday, December 15, 2016 10:30:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Teo wrote:
Using ACM Block and BeforeRenderPage didn't work for me as it always rendered the block over the page (except header and footer).

Here is one solution I came up with using the low level API:

HtmlToPdf.Options.AfterRenderPage += delegate (object source, PdfPageEventArgs a)
{
PdfPathContent content = new PdfPathContent();
var rect = new EO.Pdf.Drawing.PdfPathRectSegment(new EO.Pdf.Drawing.PdfRectangle(0, 0, 1000, 1000));
EO.Pdf.Drawing.PdfSubPath subPath = new EO.Pdf.Drawing.PdfSubPath();
subPath.From = new EO.Pdf.Drawing.PdfPoint(1000, 0);
subPath.Segments.Add(rect);
content.Path.SubPaths.Add(subPath);
content.NonStrokingColor = options.BackgroundColor;
content.Action = PdfPathPaintAction.Fill;

a.Page.Contents.Insert(0, content);
};


Thanks for sharing. Yes, both the ACM interface and the low level API is built for these kind of scenarios, where you use the HTML to PDF to generate the main output and then use either ACM/Low Level API for "touch up" purpose.


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.