public static void MakeWarrantyDocument(Order order) { string path = Environment.CurrentDirectory + "\\Docs"; // Initialize document object Document document = new Document(); // Add page Page page = document.Pages.Add(); // ------------------------------------------------------------- // Add Header var header = new TextFragment("Garantía | Disp. " + order.device_serial_number); header.TextState.Font = FontRepository.FindFont("Arial"); header.TextState.FontSize = 24; header.HorizontalAlignment = HorizontalAlignment.Center; header.Position = new Position(130, 720); page.Paragraphs.Add(header); // Add description var WarrantyContentText = "\n\nFecha de la compra: " + order.purchase_date.ToString("yyyy/MM/dd");; WarrantyContentText += "\n\nFecha de terminación de garantía: " + DateTime.Today.AddMonths(order.device.device_type.warranty_months).ToString("yyyy/MM/dd");; WarrantyContentText += "\n\nCliente que realizó compra: " + order.client.name + " " + order.client.last_name1 + " " + order.client.last_name2; WarrantyContentText += "\n\nTipo de dispositivo: " + order.device.device_type_name; WarrantyContentText += "\n\nMarca: " + order.device.brand; var WarrantyContent = new TextFragment(WarrantyContentText); WarrantyContent.TextState.Font = FontRepository.FindFont("Times New Roman"); WarrantyContent.TextState.FontSize = 14; WarrantyContent.HorizontalAlignment = HorizontalAlignment.Left; page.Paragraphs.Add(WarrantyContent); document.Save(System.IO.Path.Combine(path, "Warranty" + order.bill_number + ".pdf")); }
public static void Run() { // ExStart:AddTextStamp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks(); // Open document Document pdfDocument = new Document(dataDir + "AddTextStamp.pdf"); // Create text stamp TextStamp textStamp = new TextStamp("Sample Stamp"); // Set whether stamp is background textStamp.Background = true; // Set origin textStamp.XIndent = 100; textStamp.YIndent = 100; // Rotate stamp textStamp.Rotate = Rotation.on90; // Set text properties textStamp.TextState.Font = FontRepository.FindFont("Arial"); textStamp.TextState.FontSize = 14.0F; textStamp.TextState.FontStyle = FontStyles.Bold; textStamp.TextState.FontStyle = FontStyles.Italic; textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua); // Add stamp to particular page pdfDocument.Pages[1].AddStamp(textStamp); dataDir = dataDir + "AddTextStamp_out_.pdf"; // Save output document pdfDocument.Save(dataDir); // ExEnd:AddTextStamp Console.WriteLine("\nText stamp added successfully.\nFile saved at " + dataDir); }
public static void UsingTextStamp() { // ExStart:UsingTextStamp // 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(); // Instantiate TextStamp instance with sample text TextStamp stamp = new TextStamp("This is text stamp with character spacing"); // Specify font name for Stamp object stamp.TextState.Font = FontRepository.FindFont("Arial"); // Specify Font size for TextStamp stamp.TextState.FontSize = 12; // Specify character specing as 1f stamp.TextState.CharacterSpacing = 1f; // Set the XIndent for Stamp stamp.XIndent = 100; // Set the YIndent for Stamp stamp.YIndent = 500; // Add textual stamp to page instance stamp.Put(page); dataDir = dataDir + "CharacterSpacingUsingTextStamp_out_.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:UsingTextStamp Console.WriteLine("\nCharacter spacing specified successfully using text stamp.\nFile saved at " + dataDir); }
public static void MakeBillDocument(Order order) { string path = Environment.CurrentDirectory + "\\Docs"; // Initialize document object Document document = new Document(); // Add page Page page = document.Pages.Add(); // -----------------------------------------------------------s-- // Add Header var header = new TextFragment("Factura de compra | Disp. " + order.device_serial_number); header.TextState.Font = FontRepository.FindFont("Arial"); header.TextState.FontSize = 24; header.HorizontalAlignment = HorizontalAlignment.Center; header.Position = new Position(130, 720); page.Paragraphs.Add(header); // Add description var billContentText = "\n\nNumero de factura: " + order.bill_number; billContentText += "\n\nFecha de la compra: " + order.purchase_date.ToString("yyyy/MM/dd"); billContentText += "\n\nTipo de dispositivo: " + order.device.device_type_name; billContentText += "\n\nPrecio: " + order.price; var billContent = new TextFragment(billContentText); billContent.TextState.Font = FontRepository.FindFont("Times New Roman"); billContent.TextState.FontSize = 14; billContent.HorizontalAlignment = HorizontalAlignment.Left; page.Paragraphs.Add(billContent); document.Save(System.IO.Path.Combine(path, "Bill" + order.bill_number + ".pdf")); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks(); //open document Document pdfDocument = new Document(dataDir + "PageNumberStamp.pdf"); //create page number stamp PageNumberStamp pageNumberStamp = new PageNumberStamp(); //whether the stamp is background pageNumberStamp.Background = false; pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count; pageNumberStamp.BottomMargin = 10; pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center; pageNumberStamp.StartingNumber = 1; //set text properties pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial"); pageNumberStamp.TextState.FontSize = 14.0F; pageNumberStamp.TextState.FontStyle = FontStyles.Bold; pageNumberStamp.TextState.FontStyle = FontStyles.Italic; pageNumberStamp.TextState.ForegroundColor = Color.Aqua; //add stamp to particular page pdfDocument.Pages[1].AddStamp(pageNumberStamp); //save output document pdfDocument.Save(dataDir + "PageNumberStamp_out.pdf"); }
public static void Run() { // ExStart:EmbedFontWhileDocCreation // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Instantiate Pdf object by calling its empty constructor Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); // Create a section in the Pdf object Aspose.Pdf.Page page = doc.Pages.Add(); Aspose.Pdf.Text.TextFragment fragment = new Aspose.Pdf.Text.TextFragment(""); Aspose.Pdf.Text.TextSegment segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font."); Aspose.Pdf.Text.TextState ts = new Aspose.Pdf.Text.TextState(); ts.Font = FontRepository.FindFont("Arial"); ts.Font.IsEmbedded = true; segment.TextState = ts; fragment.Segments.Add(segment); page.Paragraphs.Add(fragment); dataDir = dataDir + "EmbedFontWhileDocCreation_out_.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:EmbedFontWhileDocCreation Console.WriteLine("\nFont embedded successfully in a PDF file.\nFile saved at " + dataDir); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); //open document Document pdfDocument = new Document(dataDir + "ReplaceTextPage.pdf"); //create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text"); //accept the absorber for a particular page pdfDocument.Pages[2].Accept(textFragmentAbsorber); //get the extracted text fragments TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; //loop through the fragments foreach (TextFragment textFragment in textFragmentCollection) { //update text and other properties textFragment.Text = "New Phrase"; textFragment.TextState.Font = FontRepository.FindFont("Verdana"); textFragment.TextState.FontSize = 22; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); } pdfDocument.Save(dataDir + "ReplaceTextPage_out.pdf"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document pdfDocument = new Document(dataDir + "input.pdf"); //create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text"); //accept the absorber for all the pages pdfDocument.Pages.Accept(textFragmentAbsorber); //get the extracted text fragments TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; //loop through the fragments foreach (TextFragment textFragment in textFragmentCollection) { //update text and other properties textFragment.Text = "TEXT"; textFragment.TextState.Font = FontRepository.FindFont("Verdana"); textFragment.TextState.FontSize = 22; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); } // Save resulting PDF document. pdfDocument.Save(dataDir + "output.pdf"); // Let user know about the outcome of the processing. System.Console.WriteLine("Text replaced successfully!"); }
public static void Run() { // ExStart:PageNumberStamps // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks(); // Open document Document pdfDocument = new Document(dataDir + "PageNumberStamp.pdf"); // Create page number stamp PageNumberStamp pageNumberStamp = new PageNumberStamp(); // Whether the stamp is background pageNumberStamp.Background = false; pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count; pageNumberStamp.BottomMargin = 10; pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center; pageNumberStamp.StartingNumber = 1; // Set text properties pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial"); pageNumberStamp.TextState.FontSize = 14.0F; pageNumberStamp.TextState.FontStyle = FontStyles.Bold; pageNumberStamp.TextState.FontStyle = FontStyles.Italic; pageNumberStamp.TextState.ForegroundColor = Color.Aqua; // Add stamp to particular page pdfDocument.Pages[1].AddStamp(pageNumberStamp); dataDir = dataDir + "PageNumberStamp_out_.pdf"; // Save output document pdfDocument.Save(dataDir); // ExEnd:PageNumberStamps Console.WriteLine("\nPage number stamp added successfully.\nFile saved at " + dataDir); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document pdfDocument = new Document(dataDir + "input.pdf"); //create text stamp TextStamp textStamp = new TextStamp("Sample Stamp"); //set whether stamp is background textStamp.Background = true; //set origin textStamp.XIndent = 100; textStamp.YIndent = 100; //rotate stamp textStamp.Rotate = Rotation.on90; //set text properties textStamp.TextState.Font = FontRepository.FindFont("Arial"); textStamp.TextState.FontSize = 14.0F; textStamp.TextState.FontStyle = FontStyles.Bold; textStamp.TextState.FontStyle = FontStyles.Italic; textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua); //add stamp to particular page pdfDocument.Pages[1].AddStamp(textStamp); //save output document pdfDocument.Save(dataDir + "output.pdf"); }
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 Run() { // ExStart:ReplaceTextAll // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Open document Document pdfDocument = new Document(dataDir + "ReplaceTextAll.pdf"); // Create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text"); // Accept the absorber for all the pages pdfDocument.Pages.Accept(textFragmentAbsorber); // Get the extracted text fragments TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; // Loop through the fragments foreach (TextFragment textFragment in textFragmentCollection) { // Update text and other properties textFragment.Text = "TEXT"; textFragment.TextState.Font = FontRepository.FindFont("Verdana"); textFragment.TextState.FontSize = 22; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); } dataDir = dataDir + "ReplaceTextAll_out_.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:ReplaceTextAll Console.WriteLine("\nText replaced successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:ReplaceFirstOccurrence // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Open document Document pdfDocument = new Document(dataDir + "ReplaceTextPage.pdf"); // Create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("text"); // Accept the absorber for all the pages pdfDocument.Pages.Accept(textFragmentAbsorber); // Get the extracted text fragments TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; if (textFragmentCollection.Count > 0) { // Get first occurance of text and replace TextFragment textFragment = textFragmentCollection[1]; // Update text and other properties textFragment.Text = "New Phrase"; textFragment.TextState.Font = FontRepository.FindFont("Verdana"); textFragment.TextState.FontSize = 22; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue); dataDir = dataDir + "ReplaceFirstOccurrence_out_.pdf"; pdfDocument.Save(dataDir); Console.WriteLine("\nText replaced successfully.\nFile saved at " + dataDir); } // ExEnd:ReplaceFirstOccurrence }
public static void OTFFont() { // ExStart:OTFFont // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Create new document instance Document pdfDocument = new Document(); // Add page to pages collection of PDF file Aspose.Pdf.Page page = pdfDocument.Pages.Add(); // Create TextFragment instnace with sample text TextFragment fragment = new TextFragment("Sample Text in OTF font"); // Find font inside system font directory // Fragment.TextState.Font = FontRepository.FindFont("HelveticaNeueLT Pro 45 Lt"); // Or you can even specify the path of OTF font in system directory fragment.TextState.Font = FontRepository.OpenFont(dataDir + "space age.otf"); // Specify to emend font inside PDF file, so that its displayed properly, // Even if specific font is not installed/present over target machine fragment.TextState.Font.IsEmbedded = true; // Add TextFragment to paragraphs collection of Page instance page.Paragraphs.Add(fragment); dataDir = dataDir + "OTFFont_out.pdf"; // Save resulting PDF document. pdfDocument.Save(dataDir); // ExEnd:OTFFont Console.WriteLine("\nOTF font used successfully.\nFile saved at " + dataDir); }
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 }
public IEnumerable GetFields(double wpfW, double wpfH) { var pdfForm = new Aspose.Pdf.Facades.Form(PdfDoc); var fl = Fields.Select(f => { var pageW = PdfDoc.Pages[f.PageIndex].Rect.Width; var pageH = PdfDoc.Pages[f.PageIndex].Rect.Height; var scaleX = wpfW / pageW; var scaleY = wpfH / pageH; var font = FontRepository.FindFont(TranslateFontName(f.DefaultAppearance.FontName)); return( page: f.PageIndex , label: f.PartialName , value: f.Value , font: font.DecodedFontName , type: f is CheckboxField ? 1 : 2 , width: f.Rect.Width * scaleX , height: f.Rect.Height * scaleY , x: f.Rect.LLX * scaleX , y: (pageH - f.Rect.URY) * scaleY , index: f.PageIndex ); } ); return(fl); }
public static void Run() { try { // ExStart:RemoveUnusedFonts // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Load source PDF file Document doc = new Document(dataDir + "ReplaceTextPage.pdf"); TextFragmentAbsorber absorber = new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts)); doc.Pages.Accept(absorber); // Iterate through all the TextFragments foreach (TextFragment textFragment in absorber.TextFragments) { textFragment.TextState.Font = FontRepository.FindFont("Arial, Bold"); } dataDir = dataDir + "RemoveUnusedFonts_out_.pdf"; // Save updated document doc.Save(dataDir); // ExEnd:RemoveUnusedFonts Console.WriteLine("\nUnused fonts removed successfully from pdf document.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); } }
public static void Run() { try { // ExStart:RearrangeContentsUsingTextReplacement // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); // Load source PDF file Document doc = new Document(dataDir + "ExtractTextPage.pdf"); // Create TextFragment Absorber object with regular expression TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[TextFragmentAbsorber,companyname,Textbox,50]"); doc.Pages.Accept(textFragmentAbsorber); // Replace each TextFragment foreach (TextFragment textFragment in textFragmentAbsorber.TextFragments) { // Set font of text fragment being replaced textFragment.TextState.Font = FontRepository.FindFont("Arial"); // Set font size textFragment.TextState.FontSize = 12; textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Navy; // Replace the text with larger string than placeholder textFragment.Text = "This is a Larger String for the Testing of this issue"; } dataDir = dataDir + "RearrangeContentsUsingTextReplacement_out_.pdf"; // Save resultant PDF doc.Save(dataDir); // ExEnd:RearrangeContentsUsingTextReplacement Console.WriteLine("\nContents rearranged successfully using text replacement.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); } }
// 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_StampsWatermarks(); // Instantiate Document instance by calling empty constructor Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(); // Create a page in the pdf document Aspose.Pdf.Page page = pdfDocument.Pages.Add(); // Create a Header Section of the PDF file Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter(); // Set the Odd Header for the PDF file page.Header = header; // Set the top margin for the header section header.Margin.Top = 20; // Instantiate a table object Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(); // Add the table in paragraphs collection of the desired section header.Paragraphs.Add(tab1); // Set default cell border using BorderInfo object tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F); // Set with column widths of the table tab1.ColumnWidths = "60 300"; Aspose.Pdf.Image img = new Aspose.Pdf.Image(); img.File = dataDir + "aspose-logo.jpg"; // Create rows in the table and then cells in the rows Aspose.Pdf.Row row1 = tab1.Rows.Add(); row1.Cells.Add("Table in Header Section"); row1.BackgroundColor = Color.Gray; // Set the row span value for first row as 2 tab1.Rows[0].Cells[0].ColSpan = 2; tab1.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor = Color.Cyan; tab1.Rows[0].Cells[0].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica"); // Create rows in the table and then cells in the rows Aspose.Pdf.Row row2 = tab1.Rows.Add(); // Set the background color for Row2 row2.BackgroundColor = Color.White; // Add the cell which holds the image Aspose.Pdf.Cell cell2 = row2.Cells.Add(); // Set the image width to 60 img.FixWidth = 60; // Add the image to the table cell cell2.Paragraphs.Add(img); row2.Cells.Add("Logo is looking fine !"); row2.Cells[1].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica"); // Set the vertical allignment of the text as center alligned row2.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center; row2.Cells[1].Alignment = Aspose.Pdf.HorizontalAlignment.Center; // Save the Pdf file pdfDocument.Save(dataDir + "TableInHeaderFooterSection_out.pdf"); // ExEnd:1 }
public static void Run() { //ExStart: GetWidthOfTextDynamically // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); Aspose.Pdf.Text.Font font = FontRepository.FindFont("Arial"); TextState ts = new TextState(); ts.Font = font; ts.FontSize = 14; if (Math.Abs(font.MeasureString("A", 14) - 9.337) > 0.001) { Console.WriteLine("Unexpected font string measure!"); } if (Math.Abs(ts.MeasureString("z") - 7.0) > 0.001) { Console.WriteLine("Unexpected font string measure!"); } for (char c = 'A'; c <= 'z'; c++) { double fnMeasure = font.MeasureString(c.ToString(), 14); double tsMeasure = ts.MeasureString(c.ToString()); if (Math.Abs(fnMeasure - tsMeasure) > 0.001) { Console.WriteLine("Font and state string measuring doesn't match!"); } } //ExEnd: GetWidthOfTextDynamically }
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 TextFragment AddTesto(string text) { TextFragment tf = new TextFragment(text); tf.TextState.Font = FontRepository.FindFont("Helvetica"); tf.TextState.FontSize = 12; return(tf); }
public void SetDefaultTextStyle(TextState customState = null) { Table.DefaultCellTextState = customState ?? new TextState { FontSize = 12, Font = FontRepository.FindFont("Arial") }; }
private TextFragment AddSottotitolo(string text) { TextFragment tf = new TextFragment(text); tf.TextState.Font = FontRepository.FindFont("Helvetica"); tf.TextState.FontSize = 16; tf.Margin.Bottom = 5; return(tf); }
public static void Run() { // ExStart:SetHTMLStringFormatting HtmlFragment html = new HtmlFragment("some text"); html.TextState = new TextState(); html.TextState.Font = FontRepository.FindFont("Calibri"); // ExEnd:SetHTMLStringFormatting }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync( Microsoft.ApplicationInsights.WindowsCollectors.Metadata | Microsoft.ApplicationInsights.WindowsCollectors.Session); this.InitializeComponent(); this.Suspending += OnSuspending; Repository = new AlphabeticalFontRepository(); }
public DrawSystem(SpriteRepository spriteRepository, SpriteBatch spriteBatch, FontRepository fontRepository, [Hint(typeof(IInputService))] XInputService input) { this.spriteRepository = spriteRepository; this.spriteBatch = spriteBatch; this.fontRepository = fontRepository; this.input = input; }
public PDFGenerator() { _pdfDocument = new Document(); _pdfDocument.PageInfo.Margin.Left = 36; _pdfDocument.PageInfo.Margin.Right = 36; _pdfPage = _pdfDocument.Pages.Add(); _textColor = Color.Black; _backColor = Color.Transparent; _timeNewRomanFont = FontRepository.FindFont("Times New Roman"); _builder = new TextBuilder(_pdfPage); }
public static Font GetFont(string fontName) { try { return(FontRepository.FindFont(fontName)); } catch (FontNotFoundException) { return(FontRepository.FindFont("Arial")); } }