-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ApiCreatePdf | ||
{ | ||
public class DocumentData | ||
{ | ||
public string MainContentText { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using GemBox.Document; | ||
|
||
namespace ApiCreatePdf; | ||
|
||
public class DocumentService | ||
{ | ||
public Stream GeneratePdf(string id) | ||
{ | ||
var documentData = GetDocumentData(id); | ||
|
||
var pdf = new MemoryStream(); | ||
|
||
// If using the Professional version, put your serial key below. | ||
ComponentInfo.SetLicense("FREE-LIMITED-KEY"); | ||
|
||
var document = new DocumentModel(); | ||
|
||
var section = new Section(document); | ||
document.Sections.Add(section); | ||
|
||
var paragraph = new Paragraph(document); | ||
section.Blocks.Add(paragraph); | ||
|
||
var run = new Run(document, documentData.MainContentText); | ||
paragraph.Inlines.Add(run); | ||
|
||
document.Save(pdf, SaveOptions.PdfDefault); | ||
|
||
return pdf; | ||
} | ||
|
||
private DocumentData GetDocumentData(string id) | ||
{ | ||
return new DocumentData | ||
{ | ||
MainContentText = $"PDF created for id: {id}" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters