|
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.
|
|
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.aspxInside 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.aspxPlease feel free to let us know if you have any more questions. Thanks!
|
|
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?
|
|
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!
|
|
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)
|
|
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!
|
|
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); };
|
|
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.
|
|