(एचटीएमएल) एक स्ट्रिंग के रूप में प्रदान दृश्य कैप्चर करें और इसे पारित पीडीएफ निर्माता जो एक बहुत है Winnovative को अच्छा उपकरण जो जटिल स्वरूपण को संरक्षित करता है। यहाँ
पर कब्जा कर लिया एचटीएमएल से
string test="\r\n\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" >\r\n<head>\r\n <link rel=\"Stylesheet\" href=\"../../Content/style.css\" type=\"text/css\" />\r\n <title>Cover Page</title>\r\n <style type=\"text/css\">\r\n html, body\r\n {\r\n\t font-family: Arial, Helvetica, sans-serif;\r\n\t font-size: 13pt;\r\n\t padding: 0px;\r\n\t margin: 0px;\r\n\t background-color: #FFFFFF;\r\n\t color: black;\r\n\t width: 680px;\r\n }\r\n </style>\r\n</head>\r\n<body>\r\n <div>\r\n Ssotest Ssotest, \r\n </div> \r\n</body>\r\n</html>\r\n"
FileStreamResponseContext response = new FileStreamResponseContext();
Response .clear();
Document doc = new Document();
doc.DocumentInformation.CreationDate = DateTime.Now;
doc.DocumentInformation.Title = "Test Plan";
doc.DocumentInformation.Subject = "Test Plan";
doc.CompressionLevel = CompressionLevel.NormalCompression;
doc.Margins = new Margins(0, 0, 0, 0);
doc.Security.CanPrint = true;
doc.ViewerPreferences.HideToolbar = false;
doc.ViewerPreferences.FitWindow = false;
string baseUrl = String.Format("http://localhost{0}/", Request.Url.Port == 80?"":":" + Request.Url.Port.ToString());
PdfPage docTestPlan = doc.AddPage(PageSize.Letter, new Margins(0, 0, 0, 0), PageOrientation.Portrait);
// passing the string test returned from the string writer
HtmlToPdfElement htmlToPdf = new HtmlToPdfElement(test, baseUrl);
htmlToPdf.FitWidth = false;
docTestPlan.AddElement(htmlToPdf);
/******************************************
* put doc in a memory stream for return */
response.FileDataStream = new MemoryStream();
doc.Save(response.FileDataStream);
doc.Close();
response.FileDataStream.Position = 0;
return new FileStreamResult(response.FileDataStream, "application/pdf");
If you need to capture the controller action follow my post here.[http://stackoverflow.com/questions/5553674/capturing-html-to-string-in-mvc2-0][1]
पीडीएफ बनाने के लिए आप Winnovative पीडीएफ निर्माता की आधिकारिक वेबसाइट से नमूना कोड प्राप्त कर सकते हैं कोड है।
"कृपया इस समस्या को हल करने में मेरी मदद करें" - किस समस्या को हल करने में, बिल्कुल? –
@Tom जटिल एचटीएमएल से या तो फ्लाई पर या सहेजे गए एचटीएमएल फाइलों से पीडीएफ बनाने के लिए जो सीएसएस –
के माध्यम से परिभाषित सभी प्रारूपण को संरक्षित रखना चाहिए, यह संभवतः आपके द्वारा किए गए प्रयासों को सूचीबद्ध करने का एक अच्छा विचार होगा ताकि अन्य लोग उत्तर पोस्ट न करें सामान जो आप पहले से ही खारिज कर चुके हैं। – Buildstarted