1
- Extremely easy way to create Pdf files from ASP.NET Core.
1
+ Extremely easy way to create Pdf files from ASP.NET Core
2
2
=========================================================
3
3
4
- Usage:
4
+ New Features
5
+ ------
6
+
7
+ * Support new event. ` OnBuildFileSuccess() `
8
+
9
+ ``` csharp
10
+ public ActionResult TestInlie ()
11
+ {
12
+ return new ActionAsPdf (" Index" , new { name = " Friends" })
13
+ {
14
+ // FileName = "Test.pdf",
15
+ ContentDisposition = ContentDisposition .Inline ,
16
+ OnBuildFileSuccess = async (bytes , context , fileName ) =>
17
+ {
18
+ // some code done.
19
+ return true ;
20
+
21
+ // example.
22
+ if (string .IsNullOrEmpty (fileName ))
23
+ fileName = $" {Guid .NewGuid ()}.pdf" ;
24
+
25
+ var container = CloudStorageAccount
26
+ // Please set your value.
27
+ // If it's null, it will result in an ArgumentNullException().
28
+ .Parse (connectionString :null )
29
+ .CreateCloudBlobClient ()
30
+ // Please set your value.
31
+ // If it's null, it will result in an ArgumentNullException().
32
+ .GetContainerReference (containerName :null );
33
+
34
+ try
35
+ {
36
+ var blockBlob = container .GetBlockBlobReference (fileName );
37
+ blockBlob .Properties .ContentType = " application/pdf" ;
38
+ await blockBlob .UploadFromByteArrayAsync (bytes , 0 , bytes .Length );
39
+ }
40
+ catch (Exception e )
41
+ {
42
+ // logging.
43
+ return false ; // fire InvalidOperationException()
44
+ }
45
+
46
+ return true ;
47
+ },
48
+ };
49
+ }
50
+ ```
51
+
52
+ Usage
5
53
------
6
54
7
55
``` csharp
@@ -17,14 +65,17 @@ public ActionResult Index(string name)
17
65
return View ();
18
66
}
19
67
```
68
+
20
69
ViewAsPdf now available. It enables you to render a view as pdf in just one move, thanks to scoorf
70
+
21
71
``` csharp
22
72
public ActionResult TestViewWithModel (string id )
23
73
{
24
74
var model = new TestViewModel {DocTitle = id , DocContent = " This is a test" };
25
75
return new ViewAsPdf (model );
26
76
}
27
77
```
78
+
28
79
Also available a RouteAsPdf, UrlAsPdf and ViewAsPdf ActionResult.
29
80
30
81
It generates Pdf also from authorized actions (web forms authentication).
0 commit comments