![]() FontSize = 12 // Add fragment to paragraph FindFont ( "Times New Roman" ) fragment1. TextFragment fragment1 = new TextFragment ( "the quick brown fox jumps over the lazy dog" ) fragment1. Rectangle ( 100, 300, 200, 700 ) // Specify word wraping mode SubsequentLinesIndent = 20 // Specify the location to add TextParagraph TextParagraph paragraph = new TextParagraph () // Set subsequent lines indent Add () TextBuilder builder = new TextBuilder ( page ) // Create text paragraph The following code snippet shows you how to add text in PDF document using TextParagraph class.ĭocument doc = new Document () // Add page to pages collection of Document object TextFragment textFragment = new TextFragment ( "Hello world" ) if ( fontFile != "" ) Add Text using TextParagraph Pages ) // Create text fragment with sample string TextBuilder textBuilder = new TextBuilder ( doc. GetDataDir_AsposePdf_Text () string fontFile = "" // Load input PDF fileĭocument doc = new Document ( dataDir "input.pdf" ) // Create text builder object for first page of document The following code snippet shows how to load Font from Stream object when adding text to PDF document. Save ( dataDir ) Loading Font from Stream AppendText ( textFragment ) dataDir = dataDir "AddText_out.pdf" // Save resulting PDF document. TextBuilder textBuilder = new TextBuilder ( pdfPage ) // Append the text fragment to the PDF page FindFont ( "TimesNewRoman" ) textFragment. Position = new Position ( 100, 600 ) // Set text properties TextFragment textFragment = new TextFragment ( "main text" ) textFragment. GetDataDir_AsposePdf_Text () // Open documentĭocument pdfDocument = new Document ( dataDir "input.pdf" ) // Get particular page For complete examples and data files, please go to The following code snippet shows you how to add text in an existing PDF file. Call the Document object’s Save method and save the output PDF file.The TextBuilder object created from that particular page – to which you want to add the text – allows you to add the TextFragment object to the page using the AppendText method. Create a TextFragment object with the input text along with other text properties.Get the particular page to which you want to add the text.Open the input PDF using the Document object.Specify character Spacing when adding Text.Remove the line if your code requires an instant file write pattern. This is not needed, but it can be a good idea to give your application a little breathing space, especially if there are periods where nothing is written. Nothice that my code introduces a Thread.Sleep(100) statement. and call the WriteLine() function from any thread without Now you can add the class using constructor injection Somewhere in the startup.cs or the Main.cs file While (_textToWrite.TryDequeue(out string textLine)) Using (StreamWriter w = File.AppendText("c:\\myfile.txt")) / The public method where a thread can ask for a line in the background and do the actual file writing Private CancellationTokenSource _source = new CancellationTokenSource() Private static ConcurrentQueue _textToWrite = new ConcurrentQueue() ![]() This allows the shared resource to be access from one thread only (the task running in the background) and everyone else to deliver their payload to a thread-safe queue.
0 Comments
Leave a Reply. |