public static void UsingTextBuilderAndFragment() { // ExStart:UsingTextBuilderAndFragment // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Create Document instance Document pdfDocument = new Document(); // Add page to pages collection of Document Page page = pdfDocument.Pages.Add(); // Create TextBuilder instance TextBuilder builder = new TextBuilder(pdfDocument.Pages[1]); // Create text fragment instance with sample contents TextFragment wideFragment = new TextFragment("Text with increased character spacing"); wideFragment.TextState.ApplyChangesFrom(new TextState("Arial", 12)); // Specify character spacing for TextFragment wideFragment.TextState.CharacterSpacing = 2.0f; // Specify the position of TextFragment wideFragment.Position = new Position(100, 650); // Append TextFragment to TextBuilder instance builder.AppendText(wideFragment); dataDir = dataDir + "CharacterSpacingUsingTextBuilderAndFragment_out.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:UsingTextBuilderAndFragment Console.WriteLine("\nCharacter spacing specified successfully using Text builder and fragment.\nFile saved at " + dataDir); }
public static void UsingTextBuilderAndFragment() { // ExStart:UsingTextBuilderAndFragment // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Create Document instance Document pdfDocument = new Document(); // Add page to pages collection of Document Page page = pdfDocument.Pages.Add(); // Create TextBuilder instance TextBuilder builder = new TextBuilder(pdfDocument.Pages[1]); // Create text fragment instance with sample contents TextFragment wideFragment = new TextFragment("Text with increased character spacing"); wideFragment.TextState.ApplyChangesFrom(new TextState("Arial", 12)); // Specify character spacing for TextFragment wideFragment.TextState.CharacterSpacing = 2.0f; // Specify the position of TextFragment wideFragment.Position = new Position(100, 650); // Append TextFragment to TextBuilder instance builder.AppendText(wideFragment); dataDir = dataDir + "CharacterSpacingUsingTextBuilderAndFragment_out_.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:UsingTextBuilderAndFragment Console.WriteLine("\nCharacter spacing specified successfully using Text builder and fragment.\nFile saved at " + dataDir); }
public static void AddUnderlineText() { // ExStart:AddUnderlineText // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Create documentation object Document pdfDocument = new Document(); // Add age page to PDF document pdfDocument.Pages.Add(); // Create TextBuilder for first page TextBuilder tb = new TextBuilder(pdfDocument.Pages[1]); // TextFragment with sample text TextFragment fragment = new TextFragment("Test message"); // Set the font for TextFragment fragment.TextState.Font = FontRepository.FindFont("Arial"); fragment.TextState.FontSize = 10; // Set the formatting of text as Underline fragment.TextState.Underline = true; // Specify the position where TextFragment needs to be placed fragment.Position = new Position(10, 800); // Append TextFragment to PDF file tb.AppendText(fragment); dataDir = dataDir + "AddUnderlineText_out.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:AddUnderlineText Console.WriteLine("\nUnderline text added successfully.\nFile saved at " + dataDir); }
public static void LoadingFontFromStream() { // ExStart:LoadingFontFromStream // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); string fontFile = ""; // Load input PDF file Document doc = new Document(dataDir + "input.pdf"); // Create text builder object for first page of document TextBuilder textBuilder = new TextBuilder(doc.Pages[1]); // Create text fragment with sample string TextFragment textFragment = new TextFragment("Hello world"); if (fontFile != "") { // Load the TrueType font into stream object using (FileStream fontStream = File.OpenRead(fontFile)) { // Set the font name for text string textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF); // Specify the position for Text Fragment textFragment.Position = new Position(10, 10); // Add the text to TextBuilder so that it can be placed over the PDF file textBuilder.AppendText(textFragment); } dataDir = dataDir + "LoadingFontFromStream_out.pdf"; // Save resulting PDF document. doc.Save(dataDir); } // ExEnd:LoadingFontFromStream Console.WriteLine("\nFont from stream loaded successfully.\nFile saved at " + dataDir); }
private string AppendToken(bool leadingSpace, bool trailingSpace) { if (leadingSpace) { _tb.AppendSpace(); } string text = _textProvider.GetText(_tokens.CurrentToken); if (text.IndexOfAny(CharExtensions.LineBreakChars) >= 0) { _tb.AppendPreformattedText(text); } else { _tb.AppendText(text); } HandleBrace(); _tokens.MoveToNextToken(); if (trailingSpace) { _tb.AppendSpace(); } return(text); }
public NameInput(Scene scene, string name, string text, Vector2 position, int width, string oldString) { Scene = scene; OldString = oldString; NewString = oldString; Position = position; Width = width; MenuAreaBasic = new MenuAreaBasic(this, () => Position, 10); SpriteReference textbox = SpriteLoader.Instance.AddSprite("content/ui_box"); var formatting = new TextFormatting() { Bold = false, }; var dialogInstant = new DialogFormattingInstant(); UI = new LabelledUI(textbox, textbox, textBuilder => { textBuilder.AppendText(name, formatting, dialogInstant); }, () => new Point(Width, Height)); Text = new TextBuilder(Width - 16 - 16, Height); Text.StartLine(LineAlignment.Left); Text.AppendText(text, formatting, dialogInstant); Text.EndLine(); Text.StartLine(LineAlignment.Left); //TODO: Text Input Text.EndLine(); Text.EndContainer(); Text.Finish(); }
// FUNCTION TO ADD LOCATION OF BASE FILES public void AddPageLocation(string files) { try { string[] filelist = files.Split("|"); string[] ans = filelist[0].Split(@"\"); var l = ans.Length; string a = ans[l - 1].Remove(ans[l - 1].Length - 4); string resultfilename = a + "_treated.pdf"; string locationdir = ""; for (int i = 0; i < ans.Length - 1; i++) { locationdir = locationdir + ans[i] + @"\"; } int x = 100, y = 600; // The path to the documents directory. string dataDir = locationdir; // Open document Document pdfDocument = new Document(dataDir + resultfilename); pdfDocument.Pages.Insert(1); // Get particular page Page pdfPage = (Page)pdfDocument.Pages[1]; for (int i = 0; i < filelist.Length; i++) { TextFragment textFragment = new TextFragment("PDF locations are:--" + filelist[0]); // Create text fragment textFragment.Position = new Position(x, y); x = x + 10; y = y + 10; // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); } dataDir = dataDir + resultfilename; // Save resulting PDF document. pdfDocument.Save(dataDir); Console.WriteLine("Summary Done"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("SUMMARY FAILED! Run Again With Proper Input"); } }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Create new document object Document pdfDocument = new Document(); // Get particular page Page pdfPage = (Page)pdfDocument.Pages.Add(); // Create text fragment TextFragment textFragment = new TextFragment("main text"); textFragment.Position = new Position(100, 600); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red; // Set StrokingColor property for drawing border (stroking) around text rectangle textFragment.TextState.StrokingColor = Aspose.Pdf.Color.DarkRed; // Set DrawTextRectangleBorder property value to true textFragment.TextState.DrawTextRectangleBorder = true; TextBuilder tb = new TextBuilder(pdfPage); tb.AppendText(textFragment); // Save the document pdfDocument.Save(dataDir + "PDFWithTextBorder_out.pdf"); // ExEnd:1 }
/// <summary> /// Generate a non- PDF/UA compliant PDF for use in demo /// </summary> /// <param name="outputFilePath">Full output path including filename with extension</param> public static void CreateDemoNonCompliantPdfFile(string outputFilePath) { var pdfDoc = new Document(); pdfDoc.Pages.Add(); var pageOne = pdfDoc.Pages[1]; #region Add image int lowerLeftX = 100; int lowerLeftY = 680; int upperRightX = 200; int upperRightY = 780; FileStream imageStream = new FileStream("aspose.png", FileMode.Open); pageOne.Resources.Images.Add(imageStream); pageOne.Contents.Add(new Aspose.Pdf.Operators.GSave()); Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY); Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY }); pageOne.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix)); XImage ximage = pageOne.Resources.Images[pageOne.Resources.Images.Count]; pageOne.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name)); pageOne.Contents.Add(new Aspose.Pdf.Operators.GRestore()); #endregion #region Add text fragments var textFragmentOne = new TextFragment("Some large indigo text for our header."); textFragmentOne.Position = new Position(100, 800); textFragmentOne.TextState.FontSize = 24; textFragmentOne.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragmentOne.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Indigo); var textFragmentTwo = new TextFragment("Some smaller blue text in a non-tagged document."); textFragmentTwo.Position = new Position(100, 660); textFragmentTwo.TextState.FontSize = 12; textFragmentTwo.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragmentTwo.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); var textBuilder = new TextBuilder(pageOne); textBuilder.AppendText(textFragmentOne); textBuilder.AppendText(textFragmentTwo); #endregion pdfDoc.Save(outputFilePath); }
public static void Run() { // ExStart:RotateTextUsingTextFragment string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Initialize document object Document pdfDocument = new Document(); // Get particular page Page pdfPage = (Page)pdfDocument.Pages.Add(); // Create text fragment TextFragment textFragment1 = new TextFragment("main text"); textFragment1.Position = new Position(100, 600); // Set text properties textFragment1.TextState.FontSize = 12; textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman"); // Create rotated text fragment TextFragment textFragment2 = new TextFragment("rotated text"); textFragment2.Position = new Position(200, 600); // Set text properties textFragment2.TextState.FontSize = 12; textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment2.TextState.Rotation = 45; // Create rotated text fragment TextFragment textFragment3 = new TextFragment("rotated text"); textFragment3.Position = new Position(300, 600); // Set text properties textFragment3.TextState.FontSize = 12; textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment3.TextState.Rotation = 90; // create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment1); textBuilder.AppendText(textFragment2); textBuilder.AppendText(textFragment3); // Save document pdfDocument.Save(dataDir + "TextFragmentTests_Rotated1_out.pdf"); // ExEnd:RotateTextUsingTextFragment }
private void FooterSection() { var fragment = new TextFragment(Footer); var len = fragment.TextState.MeasureString(fragment.Text); fragment.Position = new Position(_pdfPage.PageInfo.Width / 2 - len / 2, 20); fragment.Hyperlink = new WebHyperlink(Footer); var builder = new TextBuilder(_pdfPage); builder.AppendText(fragment); }
public static string TestReadGAC(string path) { List <string> l = new List <string>(); Document pdfDocument = new Aspose.Pdf.Document(path); // Get particular page Page pdfPage = (Page)pdfDocument.Pages[1]; // Create text fragment TextFragment textFragment = new TextFragment("I------------------I"); textFragment.Position = new Position(20, 585); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); #region // Create text fragment textFragment = new TextFragment("O------------------O"); // textFragment.Position = new Position(20, 554); textFragment.Position = new Position(20, 556); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); // Create TextBuilder object textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); #endregion var outPutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "testAspose{0}.pdf".FormatWith(DateTime.Now.ToString("HHmmss"))); pdfDocument.Save(outPutPath); return(string.Empty); }
public static void AddStrikeOutText() { try { // ExStart:AddStrikeOutText // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Open document Document pdfDocument = new Document(); // Get particular page Page pdfPage = (Page)pdfDocument.Pages.Add(); // Create text fragment TextFragment textFragment = new TextFragment("main text"); textFragment.Position = new Position(100, 600); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red; // Set StrikeOut property textFragment.TextState.StrikeOut = true; // Mark text as Bold textFragment.TextState.FontStyle = FontStyles.Bold; // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); dataDir = dataDir + "AddStrikeOutText_out.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:AddStrikeOutText Console.WriteLine("\nStrikeOut text added successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { // ExStart:AddText // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Open document Document pdfDocument = new Document(dataDir + "input.pdf"); // Get particular page Page pdfPage = (Page)pdfDocument.Pages[1]; // Create text fragment TextFragment textFragment = new TextFragment("main text"); textFragment.Position = new Position(100, 600); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); dataDir = dataDir + "AddText_out.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:AddText Console.WriteLine("\nText added successfully.\nFile saved at " + dataDir); AddUnderlineText(); AddingBorderAroundAddedText(); AddTextUsingTextParagraph(); AddHyperlinkToTextSegment(); OTFFont(); AddStrikeOutText(); }
private void AppendToken(bool leadingSpace, bool trailingSpace) { if (leadingSpace) { _tb.AppendSpace(); } if (_tokens.CurrentToken.TokenType == RTokenType.Comment && _tokens.Position > 0 && _tokens.IsLineBreakAfter(_textProvider, _tokens.Position - 1)) { _tb.SoftIndent(); } string text = _textProvider.GetText(_tokens.CurrentToken); if (text.IndexOfAny(CharExtensions.LineBreakChars) >= 0) { _tb.AppendPreformattedText(text); } else { _tb.AppendText(text); } if (_tokens.CurrentToken.TokenType == RTokenType.Comment) { // make sure there is a line break between comment // and the next token _tb.SoftLineBreak(); } else { _braceHandler.HandleBrace(); } _tokens.MoveToNextToken(); if (trailingSpace) { _tb.AppendSpace(); } }
public static void TestCreate() { Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(); DocumentInfo docInfo = pdfDocument.Info; docInfo.Author = "HOWE"; docInfo.CreationDate = DateTime.Now; docInfo.Keywords = "Aspose.Pdf, DOM, API"; docInfo.ModDate = DateTime.Now; docInfo.Subject = "PDF Information"; docInfo.Title = "Setting PDF Document Information"; pdfDocument.Pages.Add(); // Get particular page Page pdfPage = (Page)pdfDocument.Pages[1]; // Create text fragment TextFragment textFragment = new TextFragment("main text"); textFragment.Position = new Position(100, 600); // Set text properties textFragment.TextState.FontSize = 12; textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(textFragment); var outPutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "testAspose.pdf"); pdfDocument.Save(outPutPath); }
public static void LoadingFontFromStream() { // ExStart:LoadingFontFromStream // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); string fontFile = ""; // Load input PDF file Document doc = new Document( dataDir + "input.pdf"); // Create text builder object for first page of document TextBuilder textBuilder = new TextBuilder(doc.Pages[1]); // Create text fragment with sample string TextFragment textFragment = new TextFragment("Hello world"); if (fontFile != "") { // Load the TrueType font into stream object using (FileStream fontStream = File.OpenRead(fontFile)) { // Set the font name for text string textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF); // Specify the position for Text Fragment textFragment.Position = new Position(10, 10); // Add the text to TextBuilder so that it can be placed over the PDF file textBuilder.AppendText(textFragment); } dataDir = dataDir + "LoadingFontFromStream_out.pdf"; // Save resulting PDF document. doc.Save(dataDir); } // ExEnd:LoadingFontFromStream Console.WriteLine("\nFont from stream loaded successfully.\nFile saved at " + dataDir); }