TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Yashir Khan
NA
26
5k
How to convert HTML Div to PDF in Asp.Net MVC with position?
Jun 16 2020 11:29 PM
I am trying to convert HTML Div to PDF in Asp.Net MVC. I have tried with iTextSharp and iText7 but the result is not as per my expectation. Div contains many images as base64 also after image there is some div which I have set with position over those image tags. I want PDF as shown in the below image.
However it's showing pdf like below :
Also I have HTML code is like below :
<div id=
"mainDiv"
style=
"margin-top:-2.5%"
>
<div
class
=
"droppable ui-droppable"
style=
"margin-left:20%;"
>
<div>
<img src=
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...Base64 String"
>
</div>
<div
class
=
"ui-visual-focus textboxDraggable ui-draggable ui-draggable-handle ui-draggable-dragging ui-resizable"
style=
"width: 291px; display: inline-block; position: absolute; z-index: 10; left: 469px; top: 245.438px; height: 26px;; font-family:Arial; font-size:14;"
data-type=
"textbox"
id=
"textbox_1"
data-
class
=
"temp"
onclick=
"clickMe(this)"
data-name=
"FirstName"
>
Testing
</div>
<div
class
=
"ui-visual-focus textboxDraggable ui-draggable ui-draggable-handle ui-draggable-dragging ui-resizable"
style=
"width: 281px; display: inline-block; z-index: 10; position: absolute; left: 470px; top: 325.797px; height: 33px;; font-family:Arial; font-size:14;"
data-type=
"textbox"
id=
"textbox_2"
data-
class
=
"temp"
onclick=
"clickMe(this)"
data-name=
"LastName"
>
Testing Demo
</div>
</div>
</div>
And in controller side, I am passing div as string. And in the controller side my code is like below :
[HttpPost, ValidateInput(
false
)]
public
FileResult HtmlToPdf(
string
GridHtml)
{
var workStream =
new
MemoryStream();
using
(var pdfWriter =
new
PdfWriter(workStream))
{
pdfWriter.SetCloseStream(
false
);
using
(var document = HtmlConverter.ConvertToDocument(GridHtml, pdfWriter))
{}
}
workStream.Position = 0;
return
new
FileStreamResult(workStream,
"application/pdf"
);
}
So please guide me that how can I generate PDF from HTML Div which looks same as displayed in the browser. PDF should display a base64 image and also need to display all other div's text and value at the proper position. Please guide me to convert HTML Div to PDF as expected.
So draggable div is not placing on pdf with proper position. Which we need to achieve.
Reply
Answers (
3
)
Can not load local resources
Registration,Login using ASP.NET CORE 3.1