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

Database byte[] write image to pdf. #27

Closed MustafaCali closed 9 years ago

MustafaCali commented 9 years ago

How can I write to the database byte [] image to pdf. I tried example:

var base64 = Convert.ToBase64String(item.Resim.ToArray()); var imgsrc = string.Format("data:image/jpeg;base64,{0}", base64);

Models from byte [] data on the type .cshtml img src = @imgsrc did not work assignment. How do I make.

But it did not work.

jefftb82 commented 9 years ago

I have this issue as well. When I render a web page instead of a pdf with the razor markup, the images show up.

jefftb82 commented 9 years ago

Does anyone have any work-arounds?

ivocoumans commented 9 years ago

I have also been trying to get this to work. If I include a static image (saved in the project), it will render in the PDF. However, when dynamically generating or requesting an image, it won't render in the PDF.

I'd appreciate any insights on how to achieve this or modify the code to achieve this.

jefftb82 commented 9 years ago

I ended up not using MvcRazorToPdf and instead just using itextsharp directly to render the pdf

andyhutch77 commented 9 years ago

I am really sorry for not getting around to looking into this. I have been really busy with other commitments. I have only ever used a local path to the image as detailed in the docs. When I get a dev env setup I will try it.

ivocoumans commented 9 years ago

No problem! Thanks a lot for your response, looking forward to the change :)

andyhutch77 commented 9 years ago

I think the only way around this that I know would be to generate the image on the server and supply the path in that format as in here:

  @{
     var imagePath = Server.MapPath("~/Content/Images");
    }
   <img src="@imagePath\avatar.jpg" alt="mug shot" />

https://github.com/andyhutch77/MvcRazorToPdf/blob/master/MvcRazorToPdfExample/Views/Pdf/Index.cshtml

ivocoumans commented 9 years ago

That's what I did to work around it yesterday. I have no idea what kind of impact this will have on the server in a production environment though, so hopefully it'll hold through testing.

andyhutch77 commented 9 years ago

@iv00w Unfortunately as I am using a third party to render the pdf I am limited to their capabilities. However the functionality you have implemented sounds good, and could kind of glue together what is there. I will include it if you submit it. The only downside is that you will probably need to write some clean-up image code with a web worker or task.

RafPe commented 9 years ago

Hey , I got webworker role just to invoke method of returning the PDF and providing it as byte[](or stream) to azure storage. That works flawlessy and really fast

ElanHasson commented 9 years ago

Thanks. On Apr 2, 2015 2:27 PM, "RafPe" notifications@github.com wrote:

Hey , I got webworker role just to invoke method of returning the PDF and providing it as byte http://or%20stream to azure storage. That works flawlessy and really fast

— Reply to this email directly or view it on GitHub https://github.com/andyhutch77/MvcRazorToPdf/issues/27#issuecomment-89001337 .

RafPe commented 9 years ago

This is link to my answer if this helps :) http://stackoverflow.com/questions/26121823/mvcrazortopdf-save-pdf-to-location-or-blob-and-then-download/29387409#29387409

andyhutch77 commented 9 years ago

@RafPe Nice one, up-voted.

RafPe commented 9 years ago

Al tough it is closed already I dived into my code and found that you can do server side processing if you would use one of my Azure Upload methods mentioned in link before (stack.. link above) in conjunction with the following :

AzureStorage._uploadToAzureBlob( ControllerContext.GeneratePdf(objModel, "VIEW_NAME") ) ;

The GeneratePDF method just generates byte[] and this is already easy to be uploaded on Azure. And If I'm correct then using async Task on server would allow you to to this on server side without blocking client.

Hope this helps further :)