से पीडीएफ दस्तावेज़ लौटाएं डेटा से एचटीएमएल पेज जेनरेट करने का सबसे अच्छा तरीका क्या है? मेरे पास सभी टेबल और आदि के साथ एक HTML टेम्पलेट है। JqueryTemplate जैसे किसी भी templating का उपयोग नहीं करना चाहते हैं।एएसपीनेट एमवीसी नियंत्रक
उत्तर
बस पीडीएफ सर्वर पक्ष बनाएं और HTML व्यू के बजाय फ़ाइल लौटाएं। मैं पीडीएफ प्रदाता आप किस तरह का उपयोग नहीं करते हैं, लेकिन इस iTextSharp के लिए एक समाधान:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
Session["MySessionVariable"] = "My Session Variable Value assigned in Index";
return View();
}
public ActionResult About()
{
return View();
}
public string RenderViewAsString(string viewName, object model)
{
// create a string writer to receive the HTML code
StringWriter stringWriter = new StringWriter();
// get the view to render
ViewEngineResult viewResult = ViewEngines.Engines.FindView(ControllerContext, viewName, null);
// create a context to render a view based on a model
ViewContext viewContext = new ViewContext(
ControllerContext,
viewResult.View,
new ViewDataDictionary(model),
new TempDataDictionary(),
stringWriter
);
// render the view to a HTML code
viewResult.View.Render(viewContext, stringWriter);
// return the HTML code
return stringWriter.ToString();
}
[HttpPost]
public ActionResult ConvertThisPageToPdf()
{
// get the HTML code of this view
string htmlToConvert = RenderViewAsString("Index", null);
// the base URL to resolve relative images and css
String thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
String baseUrl = thisPageUrl.Substring(0, thisPageUrl.Length - "Home/ConvertThisPageToPdf".Length);
// instantiate the HiQPdf HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// hide the button in the created PDF
htmlToPdfConverter.HiddenHtmlElements = new string[] { "#convertThisPageButtonDiv" };
// render the HTML code as PDF in memory
byte[] pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlToConvert, baseUrl);
// send the PDF file to browser
FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
fileResult.FileDownloadName = "ThisMvcViewToPdf.pdf";
return fileResult;
}
[HttpPost]
public ActionResult ConvertAboutPageToPdf()
{
// get the About view HTML code
string htmlToConvert = RenderViewAsString("About", null);
// the base URL to resolve relative images and css
String thisPageUrl = this.ControllerContext.HttpContext.Request.Url.AbsoluteUri;
String baseUrl = thisPageUrl.Substring(0, thisPageUrl.Length - "Home/ConvertAboutPageToPdf".Length);
// instantiate the HiQPdf HTML to PDF converter
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
// render the HTML code as PDF in memory
byte[] pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlToConvert, baseUrl);
// send the PDF file to browser
FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
fileResult.FileDownloadName = "AboutMvcViewToPdf.pdf";
return fileResult;
}
}
के स्रोत:
ठीक है तुमने मुझे याद किया। हमें शुरू से करना चाहिए। आपका असली मामला क्या है? आप क्या करना चाहते हैं? कंट्रोलर से एचटीएमएल पेज पर नियंत्रक –
hiqpdf html to pdf converter, एक व्यावसायिक उत्पाद का उपयोग इस दृष्टिकोण की कोशिश करो यह नमूना कोड: How to convert HTML to PDF using HiQPDF
के बिना किसी भी प्रकार का डेटा भेजता है, मैं 3 दिनों के लिए पीडीएफ फ़ाइल दिखाने की खोज कर रहा था। लेकिन यह समाधान बेहतर है। धन्यवाद – MustafaP
- 1. एएसपीनेट एमवीसी नियंत्रक - कन्स्ट्रक्टर उपयोग
- 2. एएसपीनेट एमवीसी नियंत्रक दृश्य वापस नहीं करेगा
- 3. एएसपीनेट एमवीसी 2 नियंत्रक कैसे तत्काल हैं?
- 4. एएसपीनेट वेबएपीआई बनाम एएसपीनेट एमवीसी नियंत्रक का प्रदर्शन JSON emmiting?
- 5. एएसपीनेट एमवीसी
- 6. एएसपीनेट एमवीसी
- 7. एएसपीनेट एमवीसी
- 8. एएसपीनेट एमवीसी
- 9. एएसपीनेट एमवीसी
- 10. एएसपीनेट एमवीसी
- 11. एएसपीनेट एमवीसी
- 12. एएसपीनेट एमवीसी
- 13. एएसपीनेट एमवीसी
- 14. मैं एएसपीनेट एमवीसी एप्लिकेशन
- 15. एएसपीनेट एमवीसी
- 16. एएसपीनेट एमवीसी
- 17. एएसपीनेट एमवीसी
- 18. एएसपीनेट एमवीसी
- 19. एएसपीनेट एमवीसी
- 20. एएसपीनेट एमवीसी
- 21. एएसपीनेट एमवीसी
- 22. एएसपीनेट एमवीसी
- 23. एएसपीनेट एमवीसी
- 24. एएसपीनेट एमवीसी
- 25. एएसपीनेट एमवीसी
- 26. एएसपीनेट एमवीसी
- 27. एएसपीनेट एमवीसी
- 28. एएसपीनेट एमवीसी
- 29. एएसपीनेट एमवीसी
- 30. एएसपीनेट एमवीसी
आप एमवीसी synrax रेज़र में निर्माण का उपयोग क्यों नहीं करना चाहते हैं? या आपको इसे क्लाइंटसाइड करने की ज़रूरत है? –
आपको इसे क्लाइंट साइड करने की आवश्यकता क्यों है? क्यों पीडीएफ सर्वर पक्ष उत्पन्न नहीं करते हैं और बाइट्स के रूप में तैयार पीडीएफ वापस आते हैं? –