Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created February 11, 2022 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/69045d8305ccb1ea335307fd7265e2fb to your computer and use it in GitHub Desktop.
Save bjoerntx/69045d8305ccb1ea335307fd7265e2fb to your computer and use it in GitHub Desktop.
public IActionResult CreatePDF()
{
// new non-UI ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// create a selection object
TXTextControl.Selection selection = new TXTextControl.Selection() {
FontSize = 1000,
Text = "Welcome to Text Control",
Bold = true,
ForeColor = System.Drawing.Color.DarkRed
};
// apply the selection
tx.Selection = selection;
// save the document into a byte array
byte[] document;
tx.Save(out document, TXTextControl.BinaryStreamType.AdobePDF);
// create and return a file
MemoryStream stream = new MemoryStream(document);
stream.Position = 0;
FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");
fileStreamResult.FileDownloadName = "results.pdf";
return fileStreamResult;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment