Skip to content

Commit ed48f2d

Browse files
committed
Html to Pdf converter (3)
1 parent 64db96f commit ed48f2d

5 files changed

Lines changed: 97 additions & 33 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* --------------------------------------------------------------
2+
3+
Hartija Css Print Framework
4+
* Version: 1.0 (Customized)
5+
6+
-------------------------------------------------------------- */
7+
8+
body {
9+
width: 100% !important;
10+
margin: 0 !important;
11+
padding: 0 !important;
12+
line-height: 1.45;
13+
font-family: Garamond,"Times New Roman", serif;
14+
color: #000;
15+
background: none;
16+
font-size: 14pt;
17+
}
18+
19+
/* Headings */
20+
h1, h2, h3, h4, h5, h6 {
21+
page-break-after: avoid;
22+
}
23+
h1 {font-size: 19pt;}
24+
h2 {font-size: 17pt;}
25+
h3 {font-size: 15pt;}
26+
h4, h5, h6{font-size: 14pt;}
27+
28+
29+
p, h2, h3 { orphans: 3; widows: 3; }
30+
31+
code { font: 12pt Courier, monospace; }
32+
blockquote { margin: 1.2em; padding: 1em; font-size: 12pt; }
33+
hr { background-color: #ccc; }
34+
35+
/* Images */
36+
img { float: left; margin: 1em 1.5em 1.5em 0; max-width: 100% !important; }
37+
a img { border: none; }
38+
39+
/* Links */
40+
a:link, a:visited { background: transparent; font-weight: 700; text-decoration: underline; color:#333; }
41+
a:link[href^="http://"]:after, a[href^="http://"]:visited:after { content: " (" attr(href) ") "; font-size: 90%; }
42+
43+
abbr[title]:after { content: " (" attr(title) ")"; }
44+
45+
/* Don't show linked images */
46+
a[href^="http://"] {color: #000; }
47+
a[href$=".jpg"]:after, a[href$=".jpeg"]:after, a[href$=".gif"]:after, a[href$=".png"]:after { content: " (" attr(href) ") "; display:none; }
48+
49+
/* Don't show links that are fragment identifiers, or use the `javascript:` pseudo protocol .. taken from html5boilerplate */
50+
a[href^="#"]:after, a[href^="javascript:"]:after {content: "";}
51+
52+
/* Table */
53+
table { margin: 1px; text-align:left; }
54+
th { border-bottom: 1px solid #333; font-weight: bold; }
55+
td { border-bottom: 1px solid #333; }
56+
th,td { padding: 4px 10px 4px 0; }
57+
tfoot { font-style: italic; }
58+
caption { background: #fff; margin-bottom:2em; text-align:left; }
59+
thead {display: table-header-group;}
60+
img,tr {page-break-inside: avoid;}

src/Presentation/SmartStore.Web/Controllers/OrderController.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -487,37 +487,37 @@ public ActionResult PrintOrderDetails(int id)
487487
return View("Details", model);
488488
}
489489

490-
//[ActionName("pdf")]
491-
//public ActionResult GetPdfInvoice(int id)
492-
//{
493-
// var order = _orderService.GetOrderById(id);
494-
// if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
495-
// return new HttpUnauthorizedResult();
496-
497-
// var model = PrepareOrderDetailsModel(order);
498-
// var fileName = "order-{0}.pdf".FormatWith(order.Id);
499-
500-
// var options = new PdfConvertOptions
501-
// {
502-
// BackgroundDisabled = true,
503-
// Grayscale = false,
504-
// LowQuality = false,
505-
// Margins = new PdfPageMargins { Top = 20, Bottom = 15, Left = 15, Right = 15 },
506-
// Orientation = PdfPagePrientation.Default,
507-
// Size = PdfPageSize.A3,
508-
// UsePrintMediaType = true,
509-
// PageHeader = RepeatablePdfSection.FromUrl("~/Header.html", this.Request),
510-
// PageFooter = RepeatablePdfSection.FromUrl("http://www.google.de", this.Request),
511-
// //UserStylesheetUrl = "http://getbootstrap.com/2.3.2/assets/css/bootstrap.css"
512-
// };
513-
514-
// PdfResultBase result;
515-
516-
// result = new ViewAsPdfResult(_pdfConverter, options) { ViewName = "Details.Print", Model = model/*, FileName = fileName*/ };
517-
// //result = new UrlAsPdfResult("http://blog.icanmakethiswork.io/2012/04/making-pdfs-from-html-in-c-using.html", _pdfConverter, options);
518-
519-
// return result;
520-
//}
490+
[ActionName("pdf2")]
491+
public ActionResult GetPdfInvoice2(int id)
492+
{
493+
var order = _orderService.GetOrderById(id);
494+
if (order == null || order.Deleted || _workContext.CurrentCustomer.Id != order.CustomerId)
495+
return new HttpUnauthorizedResult();
496+
497+
var model = PrepareOrderDetailsModel(order);
498+
var fileName = "order-{0}.pdf".FormatWith(order.Id);
499+
500+
var options = new PdfConvertOptions
501+
{
502+
BackgroundDisabled = true,
503+
Grayscale = false,
504+
LowQuality = false,
505+
Margins = new PdfPageMargins { Top = 20, Bottom = 15, Left = 15, Right = 15 },
506+
Orientation = PdfPagePrientation.Default,
507+
Size = PdfPageSize.A3,
508+
UsePrintMediaType = true,
509+
//PageHeader = RepeatablePdfSection.FromUrl("~/Header.html", this.Request),
510+
//PageFooter = RepeatablePdfSection.FromUrl("http://www.google.de", this.Request),
511+
//UserStylesheetUrl = "http://getbootstrap.com/2.3.2/assets/css/bootstrap.css"
512+
};
513+
514+
PdfResultBase result;
515+
516+
result = new ViewAsPdfResult(_pdfConverter, options) { ViewName = "Details.Print", Model = model/*, FileName = fileName*/ };
517+
//result = new UrlAsPdfResult("http://blog.icanmakethiswork.io/2012/04/making-pdfs-from-html-in-c-using.html", _pdfConverter, options);
518+
519+
return result;
520+
}
521521

522522
[ActionName("pdf")]
523523
public ActionResult GetPdfInvoice(int id)

src/Presentation/SmartStore.Web/SmartStore.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@
956956
<Content Include="Content\Images\smartstore.net-200-black.png" />
957957
<Content Include="Content\Images\smartstore.net-200-white.png" />
958958
<Content Include="Content\install\images\bg.png" />
959+
<Content Include="Content\print.css" />
959960
<Content Include="Content\samples\0000730-apple-iphone-4s-weis.jpg" />
960961
<Content Include="Content\samples\0000740-antonio-vivaldi-der-fruhling-100.jpg" />
961962
<Content Include="Content\samples\0000746_apple_125.jpeg" />

src/Presentation/SmartStore.Web/Views/Shared/_Print2.cshtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
<title>@Html.SmartTitle(true)</title>
1111
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
1212

13+
<link rel="stylesheet" type="text/css" href="~/Content/print.css" />
14+
1315
<style type="text/css">
1416
body {
15-
font-family: Arial, Helvetica, sans-serif;
17+
/*font-family: Arial, Helvetica, sans-serif;
1618
font-size: 14px;
1719
line-height: 20px;
1820
color: #444;
1921
margin: 0;
2022
padding: 20px 0;
21-
border: 0;
23+
border: 0;*/
2224
}
2325
</style>
2426

src/Presentation/SmartStore.Web/Views/Shared/_Root.Head.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
@*This is used so that themes can inject content into the header*@
9797
@Html.Partial("Head")
9898

99+
@Html.MetaAcceptLanguage()
99100
@Html.Partial("_ClientRes")
100101

101102
@Html.SmartCssFiles(this.Url, ResourceLocation.Head)

0 commit comments

Comments
 (0)