private void button1_Click(object sender, EventArgs e) { String input = @"..\..\..\..\..\..\Data\SearchReplaceTemplate.pdf"; PdfDocument doc = new PdfDocument(); // Read a pdf file doc.LoadFromFile(input); // Get the first page of pdf file PdfPageBase page = doc.Pages[0]; // Create PdfTextFindCollection object to find all the matched phrases PdfTextFindCollection collection = page.FindText("e-iceblue", TextFindParameter.IgnoreCase); // hyperlink url String url = "http://www.e-iceblue.com"; foreach (PdfTextFind find in collection.Finds) { // Create a PdfUriAnnotation object to add hyperlink for the searched text PdfUriAnnotation uri = new PdfUriAnnotation(find.Bounds); uri.Uri = url; uri.Border = new PdfAnnotationBorder(1f); uri.Color = Color.Blue; page.AnnotationsWidget.Add(uri); } String result = "SearchTextAndAddHyperlink_out.pdf"; //Save the document doc.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
private void method_18(List <Dictionary <string, RectangleF> > A_0) { if (!this.method_1().DisableLink) { for (int i = 0; i < A_0.Count; i++) { foreach (KeyValuePair <string, RectangleF> pair in A_0[i]) { RectangleF ef = pair.Value; string key = pair.Key; if (!key.Equals(string.Empty)) { PdfUriAnnotation annotation = new PdfUriAnnotation(ef); annotation.set_Uri(key); annotation.get_Border().set_Width(0f); if (this.pdfPageBase_0 is PdfNewPage) { (this.pdfPageBase_0 as PdfNewPage).get_Annotations().Add(annotation); } else { (this.pdfPageBase_0 as PdfPageWidget).get_AnnotationsWidget().Add(annotation); } } } } } }
public void PdfTemplateInfo(object currentCell, object row) { Syncfusion.Pdf.Grid.PdfGridCell range = (Syncfusion.Pdf.Grid.PdfGridCell)currentCell; object templatevalue; foreach (var ds in row.GetType().GetProperties()) { if (range.Value.ToString().Contains(ds.Name)) { templatevalue = row.GetType().GetProperty(ds.Name).GetValue(row, null); var regex = new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")", RegexOptions.IgnoreCase); var urls = regex.Matches(range.Value.ToString()).OfType <Match>().Select(m => m.Groups["href"].Value).SingleOrDefault(); RectangleF rectangle = new RectangleF(10, 40, 30, 30); PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, urls); uriAnnotation.Text = templatevalue.ToString(); range.Value = uriAnnotation; } } }
protected void EmployeesGrid_ServerPdfColumnTemplateInfo(object arg1, object arg2) { Syncfusion.Pdf.Grid.PdfGridCell range = (Syncfusion.Pdf.Grid.PdfGridCell)arg1; object templatevalue; range.Value = Uri.UnescapeDataString(range.Value.ToString()); foreach (var ds in arg2.GetType().GetProperties()) { if (range.Value.ToString().Contains(ds.Name)) { templatevalue = arg2.GetType().GetProperty(ds.Name).GetValue(arg2, null); var regex = new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")", RegexOptions.IgnoreCase); var urls = regex.Matches(range.Value.ToString()).OfType <Match>().Select(m => m.Groups["href"].Value).SingleOrDefault(); RectangleF rectangle = new RectangleF(10, 40, 30, 30); PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, urls); uriAnnotation.Text = templatevalue.ToString(); range.Value = uriAnnotation; } } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void GeneratePDF_Click(object sender, RoutedEventArgs e) { Stream image1 = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.AutoTag.jpg"); Stream image2 = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.autotagSmall.jpg"); PdfColor blackColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 0)); #region content string string toc = "\r\n What can I do with C#? ..................................................................................................................................... 3 \r\n \r\n What is .NET? .................................................................................................................................................... 3 \r\n \r\n Writing, Running, and Deploying a C# Program .............................................................................................. 3 \r\n \r\n Starting a New Program..................................................................................................................................... 3"; string Csharp = "Welcome to C# Succinctly. True to the Succinctly series concept, this book is very focused on a single topic: the C# programming language. I might briefly mention some technologies that you can write with C# or explain how a feature fits into those technologies, but the whole of this book is about helping you become familiar with C# syntax. \r\n \r\n In this chapter, Ill start with some introductory information and then jump straight into a simple C# program."; string whatToD0 = "C# is a general purpose, object-oriented, component-based programming language. As a general purpose language, you have a number of ways to apply C# to accomplish many different tasks. You can build web applications with ASP.NET, desktop applications with Windows Presentation Foundation (WPF), or build mobile applications for Windows Phone. Other applications include code that runs in the cloud via Windows Azure, and iOS, Android, and Windows Phone support with the Xamarin platform. There might be times when you need a different language, like C or C++, to communicate with hardware or real-time systems. However, from a general programming perspective, you can do a lot with C#."; string dotnet = "The runtime is more formally named the Common Language Runtime (CLR). Programming languages that target the CLR compile to an Intermediate Language (IL). The CLR itself is a virtual machine that runs IL and provides many services such as memory management, garbage collection, exception management, security, and more.\r\n \r\n The Framework Class Library (FCL) is a set of reusable code that provides both general services and technology-specific platforms. The general services include essential types such as collections, cryptography, networking, and more. In addition to general classes, the FCL includes technology-specific platforms like ASP.NET, WPF, web services, and more. The value the FCL offers is to have common components available for reuse, saving time and money without needing to write that code yourself. \r\n \r\n There is a huge ecosystem of open-source and commercial software that relies on and supports .NET. If you visit CodePlex, GitHub, or any other open-source code repository site, you will see a multitude of projects written in C#. Commercial offerings include tools and services that help you build code, manage systems, and offer applications. Syncfusion is part of this ecosystem, offering reusable components for many of the .NET technologies I have mentioned."; string prog = "The previous section described plenty of great things you can do with C#, but most of them are so detailed that they require their own book. To stay focused on the C# programming language, the code in this book will be for the console application. A console application runs on the command line, which you will learn about in this section. You can write your code with any editor, but this book uses Visual Studio."; #endregion //Create a new PDF document. PdfDocument document = new PdfDocument(); //Auto Tag the document document.AutoTag = true; document.DocumentInformation.Title = "AutoTag"; #region page1 //Add a page to the document. PdfPage page1 = document.Pages.Add(); //Load the image from the disk. PdfBitmap image = new PdfBitmap(image1); //Draw the image page1.Graphics.DrawImage(image, 0, 0, page1.GetClientSize().Width, page1.GetClientSize().Height - 20); #endregion #region page2 PdfPage page2 = document.Pages.Add(); PdfFont fontnormal = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); PdfFont fontTitle = new PdfStandardFont(PdfFontFamily.TimesRoman, 22, PdfFontStyle.Bold); PdfFont fontHead = new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold); PdfFont fontHead2 = new PdfStandardFont(PdfFontFamily.TimesRoman, 16, PdfFontStyle.Bold); page2.Graphics.DrawString("Table of Contents", fontTitle, PdfBrushes.Black, new PointF(300, 0)); page2.Graphics.DrawLine(new PdfPen(PdfBrushes.Black, 0.5f), new PointF(0, 40), new PointF(page2.GetClientSize().Width, 40)); page2.Graphics.DrawString("Chapter 1 Introducing C# and .NET .............................................................................................................. 3 \r\n ", fontHead, PdfBrushes.Black, new PointF(0, 60)); page2.Graphics.DrawString(toc, fontnormal, PdfBrushes.Black, new PointF(0, 80)); #endregion #region page3 PdfPage page3 = document.Pages.Add(); page3.Graphics.DrawString("C# Succinctly", new PdfStandardFont(PdfFontFamily.TimesRoman, 32, PdfFontStyle.Bold), PdfBrushes.Black, new PointF(160, 0)); page3.Graphics.DrawLine(PdfPens.Black, new PointF(0, 40), new PointF(page3.GetClientSize().Width, 40)); page3.Graphics.DrawString("Chapter 1 Introducing C# and .NET", fontTitle, PdfBrushes.Black, new PointF(160, 60)); PdfTextElement element1 = new PdfTextElement(Csharp, fontnormal); element1.Brush = new PdfSolidBrush(blackColor); element1.Draw(page3, new RectangleF(0, 100, page3.GetClientSize().Width, 80)); page3.Graphics.DrawString("What can I do with C#?", fontHead2, PdfBrushes.Black, new PointF(0, 180)); PdfTextElement element2 = new PdfTextElement(whatToD0, fontnormal); element2.Brush = new PdfSolidBrush(blackColor); element2.Draw(page3, new RectangleF(0, 210, page3.GetClientSize().Width, 80)); page3.Graphics.DrawString("What is .Net", fontHead2, PdfBrushes.Black, new PointF(0, 300)); PdfTextElement element3 = new PdfTextElement(dotnet, fontnormal); element3.Brush = new PdfSolidBrush(blackColor); element3.Draw(page3, new RectangleF(0, 330, page3.GetClientSize().Width, 180)); page3.Graphics.DrawString("Writing, Running, and Deploying a C# Program", fontHead2, PdfBrushes.Black, new PointF(0, 520)); PdfTextElement element4 = new PdfTextElement(prog, fontnormal); element4.Brush = new PdfSolidBrush(blackColor); element4.Draw(page3, new RectangleF(0, 550, page3.GetClientSize().Width, 60)); PdfBitmap img = new PdfBitmap(image2); page3.Graphics.DrawImage(img, new PointF(0, 630)); page3.Graphics.DrawString("Note: The code samples in this book can be downloaded at", fontnormal, PdfBrushes.DarkBlue, new PointF(20, 630)); page3.Graphics.DrawString("https://bitbucket.org/syncfusiontech/c-succinctly", fontnormal, PdfBrushes.Blue, new PointF(20, 640)); SizeF linkSize = fontnormal.MeasureString("https://bitbucket.org/syncfusiontech/c-succinctly"); RectangleF rectangle = new RectangleF(20, 640, linkSize.Width, linkSize.Height); //Creates a new Uri Annotation PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "https://bitbucket.org/syncfusiontech/c-succinctly"); uriAnnotation.Color = new PdfColor(255, 255, 255); //Adds this annotation to a new page page3.Annotations.Add(uriAnnotation); #endregion //Save the document and dispose it. MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); document.Close(true); Save(stream, "AutotagSample.pdf"); }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float y = 10; float x = 0; PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12)); String label = "Simple Link: "; PdfStringFormat format = new PdfStringFormat(); format.MeasureTrailingSpaces = true; page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format); x = font.MeasureString(label, format).Width; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12, FontStyle.Underline)); String url1 = "http://www.e-iceblue.com"; page.Canvas.DrawString(url1, font1, PdfBrushes.Blue, x, y); y = y + font1.MeasureString(url1).Height; label = "Web Link: "; page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format); x = font.MeasureString(label, format).Width; String text = "e-iceblue"; PdfTextWebLink link2 = new PdfTextWebLink(); link2.Text = text; link2.Url = url1; link2.Font = font1; link2.Brush = PdfBrushes.Blue; link2.DrawTextWebLink(page.Canvas, new PointF(x, y)); y = y + font1.MeasureString(text).Height; label = "URI Annonationa: "; page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format); x = font.MeasureString(label, format).Width; text = "Google"; PointF location = new PointF(x, y); SizeF size = font1.MeasureString(text); RectangleF linkBounds = new RectangleF(location, size); PdfUriAnnotation link3 = new PdfUriAnnotation(linkBounds); link3.Border = new PdfAnnotationBorder(0); link3.Uri = "http://www.google.com"; (page as PdfNewPage).Annotations.Add(link3); page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y); y = y + size.Height; label = "URI Annonationa Action: "; page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format); x = font.MeasureString(label, format).Width; text = "JavaScript Action (Click Me)"; location = new PointF(x, y); size = font1.MeasureString(text); linkBounds = new RectangleF(location, size); PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds); link4.Border = new PdfAnnotationBorder(0.75f); link4.Color = Color.LightGray; //script String script = "app.alert({" + " cMsg: \"Hello.\"," + " nIcon: 3," + " cTitle: \"JavaScript Action\"" + "});"; PdfJavaScriptAction action = new PdfJavaScriptAction(script); link4.Action = action; (page as PdfNewPage).Annotations.Add(link4); page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y); y = y + size.Height; //Save pdf file. doc.SaveToFile("Link.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("Link.pdf"); }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); //Set margins PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float y = 100; float x = 10; PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 14)); String label = "Simple Text Link: "; PdfStringFormat format = new PdfStringFormat(); format.MeasureTrailingSpaces = true; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 14, FontStyle.Underline)); String url1 = "http://www.e-iceblue.com"; page.Canvas.DrawString(url1, font1, PdfBrushes.CadetBlue, x, y); y = y + font1.MeasureString(url1).Height + 25; label = "Web Link: "; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; String text = "E-iceblue home"; PdfTextWebLink link2 = new PdfTextWebLink(); link2.Text = text; link2.Url = url1; link2.Font = font1; link2.Brush = PdfBrushes.CadetBlue; link2.DrawTextWebLink(page.Canvas, new PointF(x, y)); y = y + font1.MeasureString(text).Height + 30; label = "URI Annonation: "; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; text = "Google"; PointF location = new PointF(x, y); SizeF size = font1.MeasureString(text); RectangleF linkBounds = new RectangleF(location, size); PdfUriAnnotation link3 = new PdfUriAnnotation(linkBounds); link3.Border = new PdfAnnotationBorder(0); link3.Uri = "http://www.google.com"; (page as PdfNewPage).Annotations.Add(link3); page.Canvas.DrawString(text, font1, PdfBrushes.CadetBlue, x, y); y = y + size.Height + 30; label = "URI Annonation Action: "; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; text = "JavaScript Action (Click Me)"; location = new PointF(x - 2, y - 2); size = font1.MeasureString(text); size = new SizeF(size.Width + 5, size.Height + 5); linkBounds = new RectangleF(location, size); PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds); link4.Border = new PdfAnnotationBorder(0.75f); link4.Color = Color.CadetBlue; //Script String script = "app.alert({" + " cMsg: \"Hello.\"," + " nIcon: 3," + " cTitle: \"JavaScript Action\"" + "});"; PdfJavaScriptAction action = new PdfJavaScriptAction(script); link4.Action = action; (page as PdfNewPage).Annotations.Add(link4); page.Canvas.DrawString(text, font1, PdfBrushes.CadetBlue, x, y); y = y + size.Height + 30; label = "Need Help: "; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; text = "Go to forum to ask questions"; link2 = new PdfTextWebLink(); link2.Text = text; link2.Url = "https://www.e-iceblue.com/forum/components-f5.html"; link2.Font = font1; link2.Brush = PdfBrushes.CadetBlue; link2.DrawTextWebLink(page.Canvas, new PointF(x, y)); y = y + font1.MeasureString(text).Height + 30; label = "Contct us: "; page.Canvas.DrawString(label, font, PdfBrushes.Orange, 0, y, format); x = font.MeasureString(label, format).Width; text = "Send an email"; link2 = new PdfTextWebLink(); link2.Text = text; link2.Url = "mailto:[email protected]"; link2.Font = font1; link2.Brush = PdfBrushes.CadetBlue; link2.DrawTextWebLink(page.Canvas, new PointF(x, y)); y = y + font1.MeasureString(text).Height + 30; //Save pdf file. doc.SaveToFile("Link.pdf"); doc.Close(); //Launch the file. PDFDocumentViewer("Link.pdf"); }