andyhutch77 / MvcRazorToPdf

Create pdf documents within an asp .net mvc project by generating your views as normal but returning a PdfActionResult. This converts regular produced razor/html to pdf documents in the browser using the iTextXmlWorker.
125 stars 105 forks source link

Background image. #23

Closed inf13 closed 9 years ago

inf13 commented 9 years ago

I trying to add a background image for every pdf page. Is it possible? (for example html analogue: body style="background: url(logo.jpg)" )

andyhutch77 commented 9 years ago

I'm not aware of anyway to do this via css but the document and writer have been exposed.

There is an example of how to set it with the java api here:

http://itextpdf.com/sandbox/images/BackgroundImage

Give it a go and let me know how you get on.

andyhutch77 commented 9 years ago

@inf13 How did you get on with this? Any luck?

germanger commented 9 years ago

are simple images (not background images) admitted?, eg: <img src="..." />

Using the XMLWorker demo didn't work: http://demo.itextsupport.com/xmlworker/

HTML Code: <img src="http://static1.squarespace.com/static/532abed3e4b025f227941d11/t/532ce5e3e4b0f59c2979d8c2/1395451365611/" alt="" />

(just a random image)

germanger commented 9 years ago

Ah, to answer myself.. they are admitted but with a local path (eg: "C:\foo.png", which is what Server.MapPath returns). URLs are not admitted nor relative paths...

It would be nice that Base64 was admitted though, because between a local absolute path and a base64 image, <img src="data:....." />, I think the second is more elegant

andyhutch77 commented 9 years ago

@germanger Base64 would be good, if you add it I can include it. :+1: