diff --git a/Actions/Add-GoTo-action-to-the-PDF-document/.NET/Add-GoTo-action-to-the-PDF-document/Program.cs b/Actions/Add-GoTo-action-to-the-PDF-document/.NET/Add-GoTo-action-to-the-PDF-document/Program.cs index 35bedbeb..977b838d 100644 --- a/Actions/Add-GoTo-action-to-the-PDF-document/.NET/Add-GoTo-action-to-the-PDF-document/Program.cs +++ b/Actions/Add-GoTo-action-to-the-PDF-document/.NET/Add-GoTo-action-to-the-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document. -PdfDocument document = new PdfDocument(); - -//Add first page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add first page. + PdfPage page = document.Pages.Add(); -//Add second page. -PdfPage secondPage = document.Pages.Add(); + //Add second page. + PdfPage secondPage = document.Pages.Add(); -//Set the goto action. -PdfGoToAction gotoAction = new PdfGoToAction(secondPage); + //Set the goto action. + PdfGoToAction gotoAction = new PdfGoToAction(secondPage); -//Set destination location. -gotoAction.Destination = new PdfDestination(secondPage, new PointF(0, 100)); + //Set destination location. + gotoAction.Destination = new PdfDestination(secondPage, new PointF(0, 100)); -//Add the action to the document. -document.Actions.AfterOpen = gotoAction; + //Add the action to the document. + document.Actions.AfterOpen = gotoAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Actions/Add-JavaScript-action-to-the-PDF-document/.NET/Add-JavaScript-action-to-the-PDF-document/Program.cs b/Actions/Add-JavaScript-action-to-the-PDF-document/.NET/Add-JavaScript-action-to-the-PDF-document/Program.cs index e6fe484a..3a7cc1b8 100644 --- a/Actions/Add-JavaScript-action-to-the-PDF-document/.NET/Add-JavaScript-action-to-the-PDF-document/Program.cs +++ b/Actions/Add-JavaScript-action-to-the-PDF-document/.NET/Add-JavaScript-action-to-the-PDF-document/Program.cs @@ -1,27 +1,19 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create JavaScript action. -PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); + //Create JavaScript action. + PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); -//Add the JavaScript action. -document.Actions.AfterOpen = scriptAction; + //Add the JavaScript action. + document.Actions.AfterOpen = scriptAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Actions/Add-URI-action-to-the-PDF-document/.NET/Add-URI-action-to-the-PDF-document/Program.cs b/Actions/Add-URI-action-to-the-PDF-document/.NET/Add-URI-action-to-the-PDF-document/Program.cs index af4a6455..8f07f473 100644 --- a/Actions/Add-URI-action-to-the-PDF-document/.NET/Add-URI-action-to-the-PDF-document/Program.cs +++ b/Actions/Add-URI-action-to-the-PDF-document/.NET/Add-URI-action-to-the-PDF-document/Program.cs @@ -1,23 +1,15 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document with PDF/A standard. -PdfDocument document = new PdfDocument(); - -//Create a uri action. -PdfUriAction uriAction = new PdfUriAction("http://www.google.com"); - -//Add the action to the document. -document.Actions.AfterOpen = uriAction; - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Create a uri action. + PdfUriAction uriAction = new PdfUriAction("http://www.google.com"); + + //Add the action to the document. + document.Actions.AfterOpen = uriAction; -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Add-action-to-the-PDF-document/.NET/Add-action-to-the-PDF-document/Program.cs b/Actions/Add-action-to-the-PDF-document/.NET/Add-action-to-the-PDF-document/Program.cs index 7934bc61..ba9e1d1f 100644 --- a/Actions/Add-action-to-the-PDF-document/.NET/Add-action-to-the-PDF-document/Program.cs +++ b/Actions/Add-action-to-the-PDF-document/.NET/Add-action-to-the-PDF-document/Program.cs @@ -1,21 +1,13 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create and add new launch action to the document. -PdfLaunchAction action = new PdfLaunchAction(Path.GetFullPath(@"Data/logo.png")); -document.Actions.AfterOpen = action; - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Create and add new launch action to the document. + PdfLaunchAction action = new PdfLaunchAction(Path.GetFullPath(@"Data/logo.png")); + document.Actions.AfterOpen = action; -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Add-actions-to-the-existing-PDF-document/.NET/Add-actions-to-the-existing-PDF-document/Program.cs b/Actions/Add-actions-to-the-existing-PDF-document/.NET/Add-actions-to-the-existing-PDF-document/Program.cs index a379c4b5..efe4137b 100644 --- a/Actions/Add-actions-to-the-existing-PDF-document/.NET/Add-actions-to-the-existing-PDF-document/Program.cs +++ b/Actions/Add-actions-to-the-existing-PDF-document/.NET/Add-actions-to-the-existing-PDF-document/Program.cs @@ -1,26 +1,16 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from the existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ -//Create JavaScript action. -PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); + //Create JavaScript action. + PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); -//Add the JavaScript action. -loadedDocument.Actions.AfterOpen = scriptAction; + //Add the JavaScript action. + loadedDocument.Actions.AfterOpen = scriptAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Actions/Add-lauch-action-to-PDF-document/.NET/Add-lauch-action-to-PDF-document/Program.cs b/Actions/Add-lauch-action-to-PDF-document/.NET/Add-lauch-action-to-PDF-document/Program.cs index 23d2d944..7d06e638 100644 --- a/Actions/Add-lauch-action-to-PDF-document/.NET/Add-lauch-action-to-PDF-document/Program.cs +++ b/Actions/Add-lauch-action-to-PDF-document/.NET/Add-lauch-action-to-PDF-document/Program.cs @@ -1,21 +1,13 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create and add new launch Action to the document. -PdfLaunchAction action = new PdfLaunchAction(Path.GetFullPath(@"Data/logo.png")); -document.Actions.AfterOpen = action; - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Create and add new launch Action to the document. + PdfLaunchAction action = new PdfLaunchAction(Path.GetFullPath(@"Data/logo.png")); + document.Actions.AfterOpen = action; -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Actions/Add-named-action-to-PDF-document/.NET/Add-named-action-to-PDF-document/Program.cs b/Actions/Add-named-action-to-PDF-document/.NET/Add-named-action-to-PDF-document/Program.cs index abde033f..b9dc95a2 100644 --- a/Actions/Add-named-action-to-PDF-document/.NET/Add-named-action-to-PDF-document/Program.cs +++ b/Actions/Add-named-action-to-PDF-document/.NET/Add-named-action-to-PDF-document/Program.cs @@ -1,28 +1,20 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document. -PdfDocument document = new PdfDocument(); - -//Add pages to PDF document. -document.Pages.Add(); -document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add pages to PDF document. + document.Pages.Add(); + document.Pages.Add(); -//Create a named action. -PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.LastPage); + //Create a named action. + PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.LastPage); -//Add the named action. -document.Actions.AfterOpen = namedAction; + //Add the named action. + document.Actions.AfterOpen = namedAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Actions/Add-submit-action-to-the-PDF-document/.NET/Add-submit-action-to-the-PDF-document/Program.cs b/Actions/Add-submit-action-to-the-PDF-document/.NET/Add-submit-action-to-the-PDF-document/Program.cs index bc7b7ce8..da2bbbd8 100644 --- a/Actions/Add-submit-action-to-the-PDF-document/.NET/Add-submit-action-to-the-PDF-document/Program.cs +++ b/Actions/Add-submit-action-to-the-PDF-document/.NET/Add-submit-action-to-the-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a PDF document. -PdfDocument document = new PdfDocument(); - -//Add a new page. -PdfPage page = document.Pages.Add(); - -//Create a Button field. -PdfButtonField submitButton = new PdfButtonField(page, "Submit data"); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page. + PdfPage page = document.Pages.Add(); -//Set the properties to the button field. -submitButton.Bounds = new RectangleF(100, 60, 50, 20); -submitButton.ToolTip = "Submit"; -document.Form.Fields.Add(submitButton); + //Create a Button field. + PdfButtonField submitButton = new PdfButtonField(page, "Submit data"); -// Create a submit action. It submit the data of the form fields to the mentioned URL. -PdfSubmitAction submitAction = new PdfSubmitAction("http://www.syncfusionforms.com/Submit.aspx"); -submitAction.DataFormat = SubmitDataFormat.Html; -submitButton.Actions.GotFocus = submitAction; + //Set the properties to the button field. + submitButton.Bounds = new RectangleF(100, 60, 50, 20); + submitButton.ToolTip = "Submit"; + document.Form.Fields.Add(submitButton); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + // Create a submit action. It submit the data of the form fields to the mentioned URL. + PdfSubmitAction submitAction = new PdfSubmitAction("http://www.syncfusionforms.com/Submit.aspx"); + submitAction.DataFormat = SubmitDataFormat.Html; + submitButton.Actions.GotFocus = submitAction; -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Add-the-sound-action-to-PDF-document/.NET/Add-the-sound-action-to-PDF-document/Program.cs b/Actions/Add-the-sound-action-to-PDF-document/.NET/Add-the-sound-action-to-PDF-document/Program.cs index 106dc951..30acfbb8 100644 --- a/Actions/Add-the-sound-action-to-PDF-document/.NET/Add-the-sound-action-to-PDF-document/Program.cs +++ b/Actions/Add-the-sound-action-to-PDF-document/.NET/Add-the-sound-action-to-PDF-document/Program.cs @@ -1,33 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); - -//Get stream from the sound file. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Startup.wav"), FileMode.Open, FileAccess.Read); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create a sound action. -PdfSoundAction soundAction = new PdfSoundAction(fileStream); -soundAction.Sound.Bits = 16; -soundAction.Sound.Channels = PdfSoundChannels.Stereo; -soundAction.Sound.Encoding = PdfSoundEncoding.Signed; -soundAction.Volume = 0.9f; + //Get stream from the sound file. + FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Startup.wav"), FileMode.Open, FileAccess.Read); -//Set the sound action. -document.Actions.AfterOpen = soundAction; + //Create a sound action. + PdfSoundAction soundAction = new PdfSoundAction(fileStream); + soundAction.Sound.Bits = 16; + soundAction.Sound.Channels = PdfSoundChannels.Stereo; + soundAction.Sound.Encoding = PdfSoundEncoding.Signed; + soundAction.Volume = 0.9f; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Set the sound action. + document.Actions.AfterOpen = soundAction; -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Adding-Document-Level JavaScript-Actions/.NET/Adding-Document-Level JavaScript-Actions/Program.cs b/Actions/Adding-Document-Level JavaScript-Actions/.NET/Adding-Document-Level JavaScript-Actions/Program.cs index f8126e65..a1000d62 100644 --- a/Actions/Adding-Document-Level JavaScript-Actions/.NET/Adding-Document-Level JavaScript-Actions/Program.cs +++ b/Actions/Adding-Document-Level JavaScript-Actions/.NET/Adding-Document-Level JavaScript-Actions/Program.cs @@ -1,25 +1,21 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf; -// Create a new PDF document instance. -PdfDocument document = new PdfDocument(); - -// Retrieve the JavaScript collection from the document. -PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + // Retrieve the JavaScript collection from the document. + PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts; -// Define a new JavaScript action that displays an alert with the message "Hello World!!!". -PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); + // Define a new JavaScript action that displays an alert with the message "Hello World!!!". + PdfJavaScriptAction javaScriptAction = new PdfJavaScriptAction("app.alert(\"Hello World!!!\")"); -// Set the name of the JavaScript action. -javaScriptAction.Name = "Test"; + // Set the name of the JavaScript action. + javaScriptAction.Name = "Test"; -// Add the JavaScript action to the document's JavaScript collection. -javaScriptCollection.Add(javaScriptAction); + // Add the JavaScript action to the document's JavaScript collection. + javaScriptCollection.Add(javaScriptAction); -// Save the PDF document using a file stream. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) -{ - document.Save(fileStream); -} -// Close the document to release resources. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Adding-an-action-to-the-bookmark-in-the-PDF-document/.NET/Adding-an-action-to-the-bookmark-in-the-PDF-document/Program.cs b/Actions/Adding-an-action-to-the-bookmark-in-the-PDF-document/.NET/Adding-an-action-to-the-bookmark-in-the-PDF-document/Program.cs index 7acbae2e..704cf5a7 100644 --- a/Actions/Adding-an-action-to-the-bookmark-in-the-PDF-document/.NET/Adding-an-action-to-the-bookmark-in-the-PDF-document/Program.cs +++ b/Actions/Adding-an-action-to-the-bookmark-in-the-PDF-document/.NET/Adding-an-action-to-the-bookmark-in-the-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create document bookmarks. -PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); + //Create document bookmarks. + PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); -//Set the text style and color. -bookmark.TextStyle = PdfTextStyle.Bold; -bookmark.Color = Color.Red; + //Set the text style and color. + bookmark.TextStyle = PdfTextStyle.Bold; + bookmark.Color = Color.Red; -//Create a Uri action. -PdfUriAction uriAction = new PdfUriAction("http://www.google.com"); + //Create a Uri action. + PdfUriAction uriAction = new PdfUriAction("http://www.google.com"); -//Set the Uri action. -bookmark.Action = uriAction; + //Set the Uri action. + bookmark.Action = uriAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Actions/Adding-an-action-to-the-form-fields-in-PDF-document/.NET/Adding-an-action-to-the-form-fields-in-PDF-document/Program.cs b/Actions/Adding-an-action-to-the-form-fields-in-PDF-document/.NET/Adding-an-action-to-the-form-fields-in-PDF-document/Program.cs index 1ed4c6d6..7184f7f0 100644 --- a/Actions/Adding-an-action-to-the-form-fields-in-PDF-document/.NET/Adding-an-action-to-the-form-fields-in-PDF-document/Program.cs +++ b/Actions/Adding-an-action-to-the-form-fields-in-PDF-document/.NET/Adding-an-action-to-the-form-fields-in-PDF-document/Program.cs @@ -1,37 +1,29 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Create a new PdfButtonField. -PdfButtonField submitButton = new PdfButtonField(page, "submitButton"); -submitButton.Bounds = new RectangleF(25, 160, 100, 20); -submitButton.Text = "Apply"; -submitButton.BackColor = new PdfColor(181, 191, 203); +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Create a new PdfJavaScriptAction. -PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"You are looking at form fields action of PDF document\")"); + //Create a new PdfButtonField. + PdfButtonField submitButton = new PdfButtonField(page, "submitButton"); + submitButton.Bounds = new RectangleF(25, 160, 100, 20); + submitButton.Text = "Apply"; + submitButton.BackColor = new PdfColor(181, 191, 203); -//Set the scriptAction to submitButton. -submitButton.Actions.MouseDown = scriptAction; + //Create a new PdfJavaScriptAction. + PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("app.alert(\"You are looking at form fields action of PDF document\")"); -//Add the submit button to the new document.. -document.Form.Fields.Add(submitButton); + //Set the scriptAction to submitButton. + submitButton.Actions.MouseDown = scriptAction; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add the submit button to the new document.. + document.Form.Fields.Add(submitButton); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Actions/Remove-Document-Level-JavaScript-Actions/.NET/Remove-Document-Level-JavaScript-Actions/Program.cs b/Actions/Remove-Document-Level-JavaScript-Actions/.NET/Remove-Document-Level-JavaScript-Actions/Program.cs index 23c14f97..9d49d022 100644 --- a/Actions/Remove-Document-Level-JavaScript-Actions/.NET/Remove-Document-Level-JavaScript-Actions/Program.cs +++ b/Actions/Remove-Document-Level-JavaScript-Actions/.NET/Remove-Document-Level-JavaScript-Actions/Program.cs @@ -1,11 +1,9 @@ - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -//Load an existing PDF document using a file stream -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument document = new PdfLoadedDocument(inputStream)) +//Load an existing PDF document +using (PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { //Retrieve the JavaScript collection from the document PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts; @@ -16,9 +14,6 @@ //Remove the selected JavaScript action from the collection javaScriptCollection.Remove(javaScriptAction); - //Save the modified document using a file stream - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - document.Save(outputStream); - } + //Save the modified document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Actions/Reset-form-fields-in-the-PDF-document/.NET/Reset-form-fields-in-the-PDF-document/Program.cs b/Actions/Reset-form-fields-in-the-PDF-document/.NET/Reset-form-fields-in-the-PDF-document/Program.cs index 8a569c80..47bf1927 100644 --- a/Actions/Reset-form-fields-in-the-PDF-document/.NET/Reset-form-fields-in-the-PDF-document/Program.cs +++ b/Actions/Reset-form-fields-in-the-PDF-document/.NET/Reset-form-fields-in-the-PDF-document/Program.cs @@ -1,43 +1,36 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Create a PDF document -PdfDocument document = new PdfDocument(); -//Add a new page -PdfPage page = document.Pages.Add(); - -//Create a Text box field -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); -//Set properties to the textbox -textBoxField.BorderColor = new PdfColor(Color.Gray); -textBoxField.BorderStyle = PdfBorderStyle.Beveled; -textBoxField.Bounds = new RectangleF(80, 0, 100, 20); -textBoxField.Text = "First Name"; - -//Add the form field to the document -document.Form.Fields.Add(textBoxField); - -//Create a Button field. -PdfButtonField clearButton = new PdfButtonField(page, "Clear"); -clearButton.Bounds = new RectangleF(100, 60, 50, 20); -clearButton.ToolTip = "Clear"; -//Add button field to the form -document.Form.Fields.Add(clearButton); - -//Create an instance of reset action -PdfResetAction resetAction = new PdfResetAction(); -clearButton.Actions.GotFocus = resetAction; - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Add a new page + PdfPage page = document.Pages.Add(); + + //Create a Text box field + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); + //Set properties to the textbox + textBoxField.BorderColor = new PdfColor(Color.Gray); + textBoxField.BorderStyle = PdfBorderStyle.Beveled; + textBoxField.Bounds = new RectangleF(80, 0, 100, 20); + textBoxField.Text = "First Name"; + + //Add the form field to the document + document.Form.Fields.Add(textBoxField); + + //Create a Button field. + PdfButtonField clearButton = new PdfButtonField(page, "Clear"); + clearButton.Bounds = new RectangleF(100, 60, 50, 20); + clearButton.ToolTip = "Clear"; + //Add button field to the form + document.Form.Fields.Add(clearButton); + + //Create an instance of reset action + PdfResetAction resetAction = new PdfResetAction(); + clearButton.Actions.GotFocus = resetAction; + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Actions/Retrieve-Document-Level-JavaScript-Actions/.NET/Retrieve-Document-Level-JavaScript-Actions/Program.cs b/Actions/Retrieve-Document-Level-JavaScript-Actions/.NET/Retrieve-Document-Level-JavaScript-Actions/Program.cs index 076e4dae..07bad27b 100644 --- a/Actions/Retrieve-Document-Level-JavaScript-Actions/.NET/Retrieve-Document-Level-JavaScript-Actions/Program.cs +++ b/Actions/Retrieve-Document-Level-JavaScript-Actions/.NET/Retrieve-Document-Level-JavaScript-Actions/Program.cs @@ -2,9 +2,8 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Load an existing PDF document using a file stream -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument document = new PdfLoadedDocument(fileStream)) +//Load an existing PDF document +using (PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { //Retrieve the JavaScript collection from the loaded document PdfDocumentJavaScriptCollection javaScriptCollection = document.DocumentJavaScripts; diff --git a/Annotation/Add-URI-annotation-in-a-PDF-document/.NET/Add-URI-annotation-in-a-PDF-document/Program.cs b/Annotation/Add-URI-annotation-in-a-PDF-document/.NET/Add-URI-annotation-in-a-PDF-document/Program.cs index 2c8a3f87..b0138c25 100644 --- a/Annotation/Add-URI-annotation-in-a-PDF-document/.NET/Add-URI-annotation-in-a-PDF-document/Program.cs +++ b/Annotation/Add-URI-annotation-in-a-PDF-document/.NET/Add-URI-annotation-in-a-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Creates a new rectangle. -RectangleF rectangle = new RectangleF(10, 40, 30, 30); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a new Uri Annotation. -PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "http://www.google.com"); + //Creates a new rectangle. + RectangleF rectangle = new RectangleF(10, 40, 30, 30); -//Sets Text to uriAnnotation. -uriAnnotation.Text = "Uri Annotation"; + //Creates a new Uri Annotation. + PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "http://www.google.com"); -//Adds this annotation to a new page. -page.Annotations.Add(uriAnnotation); + //Sets Text to uriAnnotation. + uriAnnotation.Text = "Uri Annotation"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Adds this annotation to a new page. + page.Annotations.Add(uriAnnotation); -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +}; diff --git a/Annotation/Add-a-3D-annotation-in-PDF-document/.NET/Add-a-3D-annotation-in-PDF-document/Program.cs b/Annotation/Add-a-3D-annotation-in-PDF-document/.NET/Add-a-3D-annotation-in-PDF-document/Program.cs index 0686becb..82835d2e 100644 --- a/Annotation/Add-a-3D-annotation-in-PDF-document/.NET/Add-a-3D-annotation-in-PDF-document/Program.cs +++ b/Annotation/Add-a-3D-annotation-in-PDF-document/.NET/Add-a-3D-annotation-in-PDF-document/Program.cs @@ -1,36 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Get stream from the U3D file. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/threeLevelHierarchy.u3d"), FileMode.Open, FileAccess.Read); + //Get stream from the U3D file. + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/threeLevelHierarchy.u3d"), FileMode.Open, FileAccess.Read); -//Creates a new pdf 3d annotation. -Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream); + //Creates a new pdf 3d annotation. + Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream); -//Handles the activation of the 3d annotation. -Pdf3DActivation activation = new Pdf3DActivation(); -activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation; -activation.ShowToolbar = true; -pdf3dAnnotation.Activation = activation; + //Handles the activation of the 3d annotation. + Pdf3DActivation activation = new Pdf3DActivation(); + activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation; + activation.ShowToolbar = true; + pdf3dAnnotation.Activation = activation; -//Adds annotation to page -page.Annotations.Add(pdf3dAnnotation); + //Adds annotation to page + page.Annotations.Add(pdf3dAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-a-circle-measurement-annotation-to-the-PDF-document/.NET/Add-a-circle-measurement-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-a-circle-measurement-annotation-to-the-PDF-document/.NET/Add-a-circle-measurement-annotation-to-the-PDF-document/Program.cs index f321d3e1..72d018f4 100644 --- a/Annotation/Add-a-circle-measurement-annotation-to-the-PDF-document/.NET/Add-a-circle-measurement-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-a-circle-measurement-annotation-to-the-PDF-document/.NET/Add-a-circle-measurement-annotation-to-the-PDF-document/Program.cs @@ -1,44 +1,36 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -Syncfusion.Drawing.RectangleF rect = new Syncfusion.Drawing.RectangleF(10, 100, 100, 100); + Syncfusion.Drawing.RectangleF rect = new Syncfusion.Drawing.RectangleF(10, 100, 100, 100); -//Creates the circle measurement annotation. -PdfCircleMeasurementAnnotation circleMeasureAnnotation = new PdfCircleMeasurementAnnotation(rect); + //Creates the circle measurement annotation. + PdfCircleMeasurementAnnotation circleMeasureAnnotation = new PdfCircleMeasurementAnnotation(rect); -//Assign author to the circle measurement annotation. -circleMeasureAnnotation.Author = "Syncfusion"; + //Assign author to the circle measurement annotation. + circleMeasureAnnotation.Author = "Syncfusion"; -//Assign subject to the circle measurement annotation. -circleMeasureAnnotation.Subject = "Circle measurement annotation"; + //Assign subject to the circle measurement annotation. + circleMeasureAnnotation.Subject = "Circle measurement annotation"; -//Assign color to the square measurement annotation. -circleMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); + //Assign color to the square measurement annotation. + circleMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); -//Assign measurement unit to the circle measurement annotation. -circleMeasureAnnotation.Unit = PdfMeasurementUnit.Centimeter; + //Assign measurement unit to the circle measurement annotation. + circleMeasureAnnotation.Unit = PdfMeasurementUnit.Centimeter; -//Sets the measurementType to the circle measurement annotation. -circleMeasureAnnotation.MeasurementType = PdfCircleMeasurementType.Diameter; + //Sets the measurementType to the circle measurement annotation. + circleMeasureAnnotation.MeasurementType = PdfCircleMeasurementType.Diameter; -//Adds the circle measurement annotation to a page. -page.Annotations.Add(circleMeasureAnnotation); + //Adds the circle measurement annotation to a page. + page.Annotations.Add(circleMeasureAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/.NET/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/Program.cs b/Annotation/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/.NET/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/Program.cs index 309d6114..803584eb 100644 --- a/Annotation/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/.NET/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/Program.cs +++ b/Annotation/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/.NET/Add-a-cloud-border-styled-polygon-annotation-in-the-PDF/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; diff --git a/Annotation/Add-a-document-link-annotation-in-PDF-document/.NET/Add-a-document-link-annotation-in-PDF-document/Program.cs b/Annotation/Add-a-document-link-annotation-in-PDF-document/.NET/Add-a-document-link-annotation-in-PDF-document/Program.cs index aea0d0ec..10183c20 100644 --- a/Annotation/Add-a-document-link-annotation-in-PDF-document/.NET/Add-a-document-link-annotation-in-PDF-document/Program.cs +++ b/Annotation/Add-a-document-link-annotation-in-PDF-document/.NET/Add-a-document-link-annotation-in-PDF-document/Program.cs @@ -1,42 +1,35 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a page. -PdfPage page2 = document.Pages.Add(); + //Creates a page. + PdfPage page2 = document.Pages.Add(); -//Creates a new rectangle. -RectangleF docLinkAnnotationRectangle = new RectangleF(10, 40, 30, 30); + //Creates a new rectangle. + RectangleF docLinkAnnotationRectangle = new RectangleF(10, 40, 30, 30); -//Creates a new document link annotation. -PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationRectangle); -documentLinkAnnotation.AnnotationFlags = PdfAnnotationFlags.NoRotate; -documentLinkAnnotation.Text = "Document link annotation"; -documentLinkAnnotation.Color = new PdfColor(Color.Navy); + //Creates a new document link annotation. + PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationRectangle); + documentLinkAnnotation.AnnotationFlags = PdfAnnotationFlags.NoRotate; + documentLinkAnnotation.Text = "Document link annotation"; + documentLinkAnnotation.Color = new PdfColor(Color.Navy); -//Sets the destination. -documentLinkAnnotation.Destination = new PdfDestination(page2); -documentLinkAnnotation.Destination.Location = new PointF(10, 0); -documentLinkAnnotation.Destination.Zoom = 5; + //Sets the destination. + documentLinkAnnotation.Destination = new PdfDestination(page2); + documentLinkAnnotation.Destination.Location = new PointF(10, 0); + documentLinkAnnotation.Destination.Zoom = 5; -//Adds this annotation to a new page. -page.Annotations.Add(documentLinkAnnotation); + //Adds this annotation to a new page. + page.Annotations.Add(documentLinkAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); diff --git a/Annotation/Add-a-free-text-annotation-in-the-PDF-document/.NET/Add-a-free-text-annotation-in-the-PDF-document/Program.cs b/Annotation/Add-a-free-text-annotation-in-the-PDF-document/.NET/Add-a-free-text-annotation-in-the-PDF-document/Program.cs index 85345dd9..3c2009ee 100644 --- a/Annotation/Add-a-free-text-annotation-in-the-PDF-document/.NET/Add-a-free-text-annotation-in-the-PDF-document/Program.cs +++ b/Annotation/Add-a-free-text-annotation-in-the-PDF-document/.NET/Add-a-free-text-annotation-in-the-PDF-document/Program.cs @@ -1,42 +1,34 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new pdf document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Creates PDF free text annotation. -PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(50, 100, 100, 50)); - -//Sets properties to the annotation. -freeText.MarkupText = "Free Text with Callout"; -freeText.TextMarkupColor = new PdfColor(Color.Black); -freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); -freeText.Color = new PdfColor(Color.Yellow); -freeText.BorderColor = new PdfColor(Color.Red); -freeText.Border = new PdfAnnotationBorder(.5f); -freeText.LineEndingStyle = PdfLineEndingStyle.OpenArrow; -freeText.AnnotationFlags = PdfAnnotationFlags.Default; -freeText.Text = "Free Text"; -freeText.Opacity = 0.5f; -PointF[] points = { new PointF(100, 450), new PointF(100, 200), new PointF(100, 150) }; -freeText.CalloutLines = points; - -//Adds the annotation to page. -page.Annotations.Add(freeText); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} - -//Close the document. -document.Close(true); \ No newline at end of file + //Creates a new page. + PdfPage page = document.Pages.Add(); + + //Creates PDF free text annotation. + PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(50, 100, 100, 50)); + + //Sets properties to the annotation. + freeText.MarkupText = "Free Text with Callout"; + freeText.TextMarkupColor = new PdfColor(Color.Black); + freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); + freeText.Color = new PdfColor(Color.Yellow); + freeText.BorderColor = new PdfColor(Color.Red); + freeText.Border = new PdfAnnotationBorder(.5f); + freeText.LineEndingStyle = PdfLineEndingStyle.OpenArrow; + freeText.AnnotationFlags = PdfAnnotationFlags.Default; + freeText.Text = "Free Text"; + freeText.Opacity = 0.5f; + PointF[] points = { new PointF(100, 450), new PointF(100, 200), new PointF(100, 150) }; + freeText.CalloutLines = points; + + //Adds the annotation to page. + page.Annotations.Add(freeText); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-a-line-measurement-annotation-to-the-PDF-document/.NET/Add-a-line-measurement-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-a-line-measurement-annotation-to-the-PDF-document/.NET/Add-a-line-measurement-annotation-to-the-PDF-document/Program.cs index 9ace62e6..3dd59bfe 100644 --- a/Annotation/Add-a-line-measurement-annotation-to-the-PDF-document/.NET/Add-a-line-measurement-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-a-line-measurement-annotation-to-the-PDF-document/.NET/Add-a-line-measurement-annotation-to-the-PDF-document/Program.cs @@ -1,51 +1,43 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); -//Specifies the line end points. -int[] points = new int[] { 100, 750, 500, 750 }; + //Specifies the line end points. + int[] points = new int[] { 100, 750, 500, 750 }; -//Creates the line measurement annotation. -PdfLineMeasurementAnnotation lineMeasureAnnotation = new PdfLineMeasurementAnnotation(points); + //Creates the line measurement annotation. + PdfLineMeasurementAnnotation lineMeasureAnnotation = new PdfLineMeasurementAnnotation(points); -//Assign author to the line measurement annotation. -lineMeasureAnnotation.Author = "Syncfusion"; + //Assign author to the line measurement annotation. + lineMeasureAnnotation.Author = "Syncfusion"; -//Assign subject to the line measurement annotation. -lineMeasureAnnotation.Subject = "LineAnnotation"; + //Assign subject to the line measurement annotation. + lineMeasureAnnotation.Subject = "LineAnnotation"; -//Assign unit to the line measurement annotation. -lineMeasureAnnotation.Unit = PdfMeasurementUnit.Inch; + //Assign unit to the line measurement annotation. + lineMeasureAnnotation.Unit = PdfMeasurementUnit.Inch; -//Assign borderWidth to the line measurement annotation. -lineMeasureAnnotation.lineBorder.BorderWidth = 2; + //Assign borderWidth to the line measurement annotation. + lineMeasureAnnotation.lineBorder.BorderWidth = 2; -//Assign font to the line measurement annotation. -lineMeasureAnnotation.Font = font; + //Assign font to the line measurement annotation. + lineMeasureAnnotation.Font = font; -//Assign color to the line measurement annotation. -lineMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); + //Assign color to the line measurement annotation. + lineMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); -//Adds the line measurement annotation to a new page. -page.Annotations.Add(lineMeasureAnnotation); + //Adds the line measurement annotation to a new page. + page.Annotations.Add(lineMeasureAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs index 0f5e2e2b..ad2d230d 100644 --- a/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs +++ b/Annotation/Add-a-popup-annotation-to-an-existing-PDF-document/.NET/Add-a-popup-annotation-to-an-existing-PDF-document/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Create FileStream object to read the input PDF file -using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Load the PDF document from the input stream - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream)) - { - //Get the first page of the PDF document - PdfPageBase loadedPage = loadedDocument.Pages[0]; - //Create a new popup annotation - PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment"); - //Set the icon for the popup annotation - popupAnnotation.Icon = PdfPopupIcon.Comment; - //Set the color for the popup annotation - popupAnnotation.Color = new PdfColor(Color.Yellow); - //Add the annotation to the page - loadedPage.Annotations.Add(popupAnnotation); - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - } -} \ No newline at end of file + + //Get the first page of the PDF document + PdfPageBase loadedPage = loadedDocument.Pages[0]; + //Create a new popup annotation + PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(100, 100, 20, 20), "Comment"); + //Set the icon for the popup annotation + popupAnnotation.Icon = PdfPopupIcon.Comment; + //Set the color for the popup annotation + popupAnnotation.Color = new PdfColor(Color.Yellow); + //Add the annotation to the page + loadedPage.Annotations.Add(popupAnnotation); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Annotation/Add-a-popup-annotation-to-the-PDF-document/.NET/Add-a-popup-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-a-popup-annotation-to-the-PDF-document/.NET/Add-a-popup-annotation-to-the-PDF-document/Program.cs index dd9b1ae9..7cc9d747 100644 --- a/Annotation/Add-a-popup-annotation-to-the-PDF-document/.NET/Add-a-popup-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-a-popup-annotation-to-the-PDF-document/.NET/Add-a-popup-annotation-to-the-PDF-document/Program.cs @@ -1,36 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Creates a rectangle. -RectangleF rectangle = new RectangleF(10, 40, 30, 30); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a new popup annotation. -PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rectangle, "Test popup annotation"); -popupAnnotation.Border.Width = 4; -popupAnnotation.Border.HorizontalRadius = 20; -popupAnnotation.Border.VerticalRadius = 30; + //Creates a rectangle. + RectangleF rectangle = new RectangleF(10, 40, 30, 30); -//Sets the pdf popup icon. -popupAnnotation.Icon = PdfPopupIcon.NewParagraph; + //Creates a new popup annotation. + PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rectangle, "Test popup annotation"); + popupAnnotation.Border.Width = 4; + popupAnnotation.Border.HorizontalRadius = 20; + popupAnnotation.Border.VerticalRadius = 30; -//Adds this annotation to the created page. -page.Annotations.Add(popupAnnotation); + //Sets the pdf popup icon. + popupAnnotation.Icon = PdfPopupIcon.NewParagraph; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Adds this annotation to the created page. + page.Annotations.Add(popupAnnotation); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-a-review-status-in-a-newly-created-PDF-annotation/.NET/Add-a-review-status-in-a-newly-created-PDF-annotation/Program.cs b/Annotation/Add-a-review-status-in-a-newly-created-PDF-annotation/.NET/Add-a-review-status-in-a-newly-created-PDF-annotation/Program.cs index 0cf26f83..7b83ff85 100644 --- a/Annotation/Add-a-review-status-in-a-newly-created-PDF-annotation/.NET/Add-a-review-status-in-a-newly-created-PDF-annotation/Program.cs +++ b/Annotation/Add-a-review-status-in-a-newly-created-PDF-annotation/.NET/Add-a-review-status-in-a-newly-created-PDF-annotation/Program.cs @@ -1,51 +1,43 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); - -//Create new rectangle annotation. -PdfRectangleAnnotation rectangleAnnotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 100, 50), "Rectangle Annotation"); +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Set properties to rectangle annotation. -rectangleAnnotation.Author = "Syncfusion"; -rectangleAnnotation.Border.BorderWidth = 1; -rectangleAnnotation.Color = Color.Red; -rectangleAnnotation.ModifiedDate = DateTime.Now; + //Create new rectangle annotation. + PdfRectangleAnnotation rectangleAnnotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 100, 50), "Rectangle Annotation"); -//Create a new review annotation. -PdfPopupAnnotation review = new PdfPopupAnnotation(); + //Set properties to rectangle annotation. + rectangleAnnotation.Author = "Syncfusion"; + rectangleAnnotation.Border.BorderWidth = 1; + rectangleAnnotation.Color = Color.Red; + rectangleAnnotation.ModifiedDate = DateTime.Now; -//Set author. -review.Author = "John"; + //Create a new review annotation. + PdfPopupAnnotation review = new PdfPopupAnnotation(); -//Set review state model. -review.StateModel = PdfAnnotationStateModel.Review; + //Set author. + review.Author = "John"; -//Set review state. -review.State = PdfAnnotationState.Accepted; + //Set review state model. + review.StateModel = PdfAnnotationStateModel.Review; -//Set modification date. -review.ModifiedDate = DateTime.Now; + //Set review state. + review.State = PdfAnnotationState.Accepted; -//Add the review to the annotation. -rectangleAnnotation.ReviewHistory.Add(review); + //Set modification date. + review.ModifiedDate = DateTime.Now; -//Add the annotation to the PDF page. -page.Annotations.Add(rectangleAnnotation); + //Add the review to the annotation. + rectangleAnnotation.ReviewHistory.Add(review); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add the annotation to the PDF page. + page.Annotations.Add(rectangleAnnotation); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-a-sound-annotation-in-a-PDF-document/.NET/Add-a-sound-annotation-in-a-PDF-document/Program.cs b/Annotation/Add-a-sound-annotation-in-a-PDF-document/.NET/Add-a-sound-annotation-in-a-PDF-document/Program.cs index 5002ac3d..904792b2 100644 --- a/Annotation/Add-a-sound-annotation-in-a-PDF-document/.NET/Add-a-sound-annotation-in-a-PDF-document/Program.cs +++ b/Annotation/Add-a-sound-annotation-in-a-PDF-document/.NET/Add-a-sound-annotation-in-a-PDF-document/Program.cs @@ -1,40 +1,32 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a new rectangle. -RectangleF rectangle = new RectangleF(10, 40, 30, 30); + //Creates a new rectangle. + RectangleF rectangle = new RectangleF(10, 40, 30, 30); -//Creates a new sound annotation. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sound.wav"), FileMode.Open, FileAccess.Read); -PdfSoundAnnotation soundAnnotation = new PdfSoundAnnotation(rectangle, inputStream); -soundAnnotation.Sound.Encoding = PdfSoundEncoding.Signed; -soundAnnotation.Sound.Channels = PdfSoundChannels.Stereo; -soundAnnotation.Sound.Bits = 16; -soundAnnotation.Color = new PdfColor(Color.Red); + //Creates a new sound annotation. + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Sound.wav"), FileMode.Open, FileAccess.Read); + PdfSoundAnnotation soundAnnotation = new PdfSoundAnnotation(rectangle, inputStream); + soundAnnotation.Sound.Encoding = PdfSoundEncoding.Signed; + soundAnnotation.Sound.Channels = PdfSoundChannels.Stereo; + soundAnnotation.Sound.Bits = 16; + soundAnnotation.Color = new PdfColor(Color.Red); -//Sets the pdf sound icon. -soundAnnotation.Icon = PdfSoundIcon.Speaker; + //Sets the pdf sound icon. + soundAnnotation.Icon = PdfSoundIcon.Speaker; -//Adds this annotation to a new page. -page.Annotations.Add(soundAnnotation); + //Adds this annotation to a new page. + page.Annotations.Add(soundAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Annotation/Add-a-square-measurement-annotation-to-PDF-document/.NET/Add-a-square-measurement-annotation-to-PDF-document/Program.cs b/Annotation/Add-a-square-measurement-annotation-to-PDF-document/.NET/Add-a-square-measurement-annotation-to-PDF-document/Program.cs index 049b4a60..231b19bf 100644 --- a/Annotation/Add-a-square-measurement-annotation-to-PDF-document/.NET/Add-a-square-measurement-annotation-to-PDF-document/Program.cs +++ b/Annotation/Add-a-square-measurement-annotation-to-PDF-document/.NET/Add-a-square-measurement-annotation-to-PDF-document/Program.cs @@ -1,41 +1,33 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -Syncfusion.Drawing.RectangleF rect = new Syncfusion.Drawing.RectangleF(10, 100, 100, 100); + Syncfusion.Drawing.RectangleF rect = new Syncfusion.Drawing.RectangleF(10, 100, 100, 100); -//Creates the square measurement annotation. -PdfSquareMeasurementAnnotation squareMeasureAnnotation = new PdfSquareMeasurementAnnotation(rect); + //Creates the square measurement annotation. + PdfSquareMeasurementAnnotation squareMeasureAnnotation = new PdfSquareMeasurementAnnotation(rect); -//Assign author to the square measurement annotation. -squareMeasureAnnotation.Author = "Syncfusion"; + //Assign author to the square measurement annotation. + squareMeasureAnnotation.Author = "Syncfusion"; -//Assign subject to the square measurement annotation. -squareMeasureAnnotation.Subject = "Square measurement annotation"; + //Assign subject to the square measurement annotation. + squareMeasureAnnotation.Subject = "Square measurement annotation"; -//Assign color to the square measurement annotation. -squareMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); + //Assign color to the square measurement annotation. + squareMeasureAnnotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); -//Assign measurement unit to the square measurement annotation. -squareMeasureAnnotation.Unit = PdfMeasurementUnit.Centimeter; + //Assign measurement unit to the square measurement annotation. + squareMeasureAnnotation.Unit = PdfMeasurementUnit.Centimeter; -//Adds the square measurement annotation to a page. -page.Annotations.Add(squareMeasureAnnotation); + //Adds the square measurement annotation to a page. + page.Annotations.Add(squareMeasureAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-angle-measurement-annotation-to-PDF-document/.NET-Framework/Add-angle-measurement-annotation-to-PDF-document/Program.cs b/Annotation/Add-angle-measurement-annotation-to-PDF-document/.NET-Framework/Add-angle-measurement-annotation-to-PDF-document/Program.cs index 05ff1ebc..09835d57 100644 --- a/Annotation/Add-angle-measurement-annotation-to-PDF-document/.NET-Framework/Add-angle-measurement-annotation-to-PDF-document/Program.cs +++ b/Annotation/Add-angle-measurement-annotation-to-PDF-document/.NET-Framework/Add-angle-measurement-annotation-to-PDF-document/Program.cs @@ -41,9 +41,6 @@ static void Main(string[] args) //Close the document. document.Close(true); - - //This will open the PDF file so, the result will be seen in default PDF viewer. - Process.Start("AngleMeasurementAnnotation.pdf"); } } } diff --git a/Annotation/Add-cloud-border-styled-circle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-circle-annotation-in-the-PDF/Program.cs b/Annotation/Add-cloud-border-styled-circle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-circle-annotation-in-the-PDF/Program.cs index 1d2b12de..0441c276 100644 --- a/Annotation/Add-cloud-border-styled-circle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-circle-annotation-in-the-PDF/Program.cs +++ b/Annotation/Add-cloud-border-styled-circle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-circle-annotation-in-the-PDF/Program.cs @@ -1,41 +1,34 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document -PdfDocument document = new PdfDocument(); -//Add a new page -PdfPage page = document.Pages.Add(); -//Create a new circle annotation -PdfCircleAnnotation annotation = new PdfCircleAnnotation(new RectangleF(0, 0, 200, 200), "Circle"); -//Assign the border width -annotation.Border.BorderWidth = 1; -//Assign the color -annotation.Color = Color.Red; -//Assign the InnerColor -annotation.InnerColor = Color.Blue; -//Create a new PdfBorderEffect class -PdfBorderEffect bordereffect = new PdfBorderEffect(); -//Assign the intensity value -bordereffect.Intensity = 2; -//Assign the cloud style -bordereffect.Style = PdfBorderEffectStyle.Cloudy; -//Assign the BorderEffect to the annotation -annotation.BorderEffect = bordereffect; -//Set appearance for the annotation -annotation.SetAppearance(true); -//Adds the annotation to the page -page.Annotations.Add(annotation); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add a new page + PdfPage page = document.Pages.Add(); + //Create a new circle annotation + PdfCircleAnnotation annotation = new PdfCircleAnnotation(new RectangleF(0, 0, 200, 200), "Circle"); + //Assign the border width + annotation.Border.BorderWidth = 1; + //Assign the color + annotation.Color = Color.Red; + //Assign the InnerColor + annotation.InnerColor = Color.Blue; + //Create a new PdfBorderEffect class + PdfBorderEffect bordereffect = new PdfBorderEffect(); + //Assign the intensity value + bordereffect.Intensity = 2; + //Assign the cloud style + bordereffect.Style = PdfBorderEffectStyle.Cloudy; + //Assign the BorderEffect to the annotation + annotation.BorderEffect = bordereffect; + //Set appearance for the annotation + annotation.SetAppearance(true); + //Adds the annotation to the page + page.Annotations.Add(annotation); -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Annotation/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/.NET/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/Program.cs b/Annotation/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/.NET/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/Program.cs index 26d651ba..10d42269 100644 --- a/Annotation/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/.NET/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/Program.cs +++ b/Annotation/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/.NET/Add-cloud-border-styled-ellipse-annotation-in-the-PDF/Program.cs @@ -1,40 +1,33 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document -PdfDocument document = new PdfDocument(); -//Add a new page -PdfPage page = document.Pages.Add(); -// create a new ellipse annotation -PdfEllipseAnnotation annotation = new PdfEllipseAnnotation(new RectangleF(0, 0, 200, 100), "Ellipse"); -//Assign the border width -annotation.Border.BorderWidth = 1; -//Assign the color -annotation.Color = Color.Red; -//Assign the InnerColor -annotation.InnerColor = Color.Blue; -//Create a new PdfBorderEffect class -PdfBorderEffect bordereffect = new PdfBorderEffect(); -//Assign the intensity value -bordereffect.Intensity = 2; -//Assign the cloud style -bordereffect.Style = PdfBorderEffectStyle.Cloudy; -//Assign the BorderEffect -annotation.BorderEffect = bordereffect; -//Set appearance for the annotation. -annotation.SetAppearance(true); -// Adds the annotation to the page. -page.Annotations.Add(annotation); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add a new page + PdfPage page = document.Pages.Add(); + // create a new ellipse annotation + PdfEllipseAnnotation annotation = new PdfEllipseAnnotation(new RectangleF(0, 0, 200, 100), "Ellipse"); + //Assign the border width + annotation.Border.BorderWidth = 1; + //Assign the color + annotation.Color = Color.Red; + //Assign the InnerColor + annotation.InnerColor = Color.Blue; + //Create a new PdfBorderEffect class + PdfBorderEffect bordereffect = new PdfBorderEffect(); + //Assign the intensity value + bordereffect.Intensity = 2; + //Assign the cloud style + bordereffect.Style = PdfBorderEffectStyle.Cloudy; + //Assign the BorderEffect + annotation.BorderEffect = bordereffect; + //Set appearance for the annotation. + annotation.SetAppearance(true); + // Adds the annotation to the page. + page.Annotations.Add(annotation); -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Annotation/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/Program.cs b/Annotation/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/Program.cs index 8b8c1182..53dfea2b 100644 --- a/Annotation/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/Program.cs +++ b/Annotation/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/.NET/Add-cloud-border-styled-rectangle-annotation-in-the-PDF/Program.cs @@ -1,49 +1,40 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Create a rectangle annotation. -PdfRectangleAnnotation annotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 200, 100), "rectangle"); + //Create a rectangle annotation. + PdfRectangleAnnotation annotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 200, 100), "rectangle"); -//Assign the borderWidth value. -annotation.Border.BorderWidth = 1; + //Assign the borderWidth value. + annotation.Border.BorderWidth = 1; -//Assign the color. -annotation.Color = Color.Red; + //Assign the color. + annotation.Color = Color.Red; -//Assign the InnerColor. -annotation.InnerColor = Color.Blue; + //Assign the InnerColor. + annotation.InnerColor = Color.Blue; -//Create a new PdfBorderEffect class. -PdfBorderEffect bordereffect = new PdfBorderEffect(); + //Create a new PdfBorderEffect class. + PdfBorderEffect bordereffect = new PdfBorderEffect(); -//Assign the intensity value. -bordereffect.Intensity = 2; + //Assign the intensity value. + bordereffect.Intensity = 2; -//Assign the cloud style. -bordereffect.Style = PdfBorderEffectStyle.Cloudy; + //Assign the cloud style. + bordereffect.Style = PdfBorderEffectStyle.Cloudy; -//Assign the BorderEffect. -annotation.BorderEffect = bordereffect; + //Assign the BorderEffect. + annotation.BorderEffect = bordereffect; -//Adds the annotation to the page. -page.Annotations.Add(annotation); + //Adds the annotation to the page. + page.Annotations.Add(annotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); - diff --git a/Annotation/Add-comments-to-the-PDF-annotation/.NET/Add-comments-to-the-PDF-annotation/Program.cs b/Annotation/Add-comments-to-the-PDF-annotation/.NET/Add-comments-to-the-PDF-annotation/Program.cs index 21c5bb15..0c980097 100644 --- a/Annotation/Add-comments-to-the-PDF-annotation/.NET/Add-comments-to-the-PDF-annotation/Program.cs +++ b/Annotation/Add-comments-to-the-PDF-annotation/.NET/Add-comments-to-the-PDF-annotation/Program.cs @@ -1,51 +1,43 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); - -//Create new rectangle annotation. -PdfRectangleAnnotation rectangleAnnotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 100, 50), "Rectangle Annotation"); +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Set the properties to rectangle annotation. -rectangleAnnotation.Author = "Syncfusion"; -rectangleAnnotation.Border.BorderWidth = 1; -rectangleAnnotation.Color = Color.Red; -rectangleAnnotation.ModifiedDate = DateTime.Now; + //Create new rectangle annotation. + PdfRectangleAnnotation rectangleAnnotation = new PdfRectangleAnnotation(new RectangleF(0, 0, 100, 50), "Rectangle Annotation"); -//Create a new comment annotation. -PdfPopupAnnotation comment = new PdfPopupAnnotation(); + //Set the properties to rectangle annotation. + rectangleAnnotation.Author = "Syncfusion"; + rectangleAnnotation.Border.BorderWidth = 1; + rectangleAnnotation.Color = Color.Red; + rectangleAnnotation.ModifiedDate = DateTime.Now; -//Set author to comment annotation. -comment.Author = "John"; + //Create a new comment annotation. + PdfPopupAnnotation comment = new PdfPopupAnnotation(); -//Set Text to comment annotation. -comment.Text = "This is first comment"; + //Set author to comment annotation. + comment.Author = "John"; -//Set modification date. -comment.ModifiedDate = DateTime.Now; + //Set Text to comment annotation. + comment.Text = "This is first comment"; -//Set subject. -comment.Subject = "Annotation Comments"; + //Set modification date. + comment.ModifiedDate = DateTime.Now; -//Add the comment to the annotation. -rectangleAnnotation.Comments.Add(comment); + //Set subject. + comment.Subject = "Annotation Comments"; -//Add the annotation to the PDF page. -page.Annotations.Add(rectangleAnnotation); + //Add the comment to the annotation. + rectangleAnnotation.Comments.Add(comment); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add the annotation to the PDF page. + page.Annotations.Add(rectangleAnnotation); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-comments-to-the-existing-PDF-annotation/.NET/Add-comments-to-the-existing-PDF-annotation/Program.cs b/Annotation/Add-comments-to-the-existing-PDF-annotation/.NET/Add-comments-to-the-existing-PDF-annotation/Program.cs index 06606fe8..25a3412c 100644 --- a/Annotation/Add-comments-to-the-existing-PDF-annotation/.NET/Add-comments-to-the-existing-PDF-annotation/Program.cs +++ b/Annotation/Add-comments-to-the-existing-PDF-annotation/.NET/Add-comments-to-the-existing-PDF-annotation/Program.cs @@ -1,48 +1,37 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the existing annotations. -PdfLoadedAnnotationCollection annots = lpage.Annotations; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; + //Get the existing annotations. + PdfLoadedAnnotationCollection annots = lpage.Annotations; -//Create a new comment annotation. -PdfPopupAnnotation comment = new PdfPopupAnnotation(); + //Get the existing rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; -//Set author. -comment.Author = "John"; + //Create a new comment annotation. + PdfPopupAnnotation comment = new PdfPopupAnnotation(); -//Set Text. -comment.Text = "This is first comment"; + //Set author. + comment.Author = "John"; -//Set modification date. -comment.ModifiedDate = DateTime.Now; + //Set Text. + comment.Text = "This is first comment"; -//Set subject. -comment.Subject = "Annotation Comments"; + //Set modification date. + comment.ModifiedDate = DateTime.Now; -//Add the comments to the annotation. -loadedRectangleAnnotation.Comments.Add(comment); + //Set subject. + comment.Subject = "Annotation Comments"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Add the comments to the annotation. + loadedRectangleAnnotation.Comments.Add(comment); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-custom-stamp-in-an-existing-PDF-document/.NET/Add-custom-stamp-in-an-existing-PDF-document/Program.cs b/Annotation/Add-custom-stamp-in-an-existing-PDF-document/.NET/Add-custom-stamp-in-an-existing-PDF-document/Program.cs index db6884b9..e23e1475 100644 --- a/Annotation/Add-custom-stamp-in-an-existing-PDF-document/.NET/Add-custom-stamp-in-an-existing-PDF-document/Program.cs +++ b/Annotation/Add-custom-stamp-in-an-existing-PDF-document/.NET/Add-custom-stamp-in-an-existing-PDF-document/Program.cs @@ -1,56 +1,45 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; using Add_custom_stamp_in_an_existing_PDF_document; -//Get stream from an existing PDF document. -FileStream inputStream = new FileStream(Path.GetFullPath("Data/Input.pdf"), FileMode.Open); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page from loaded PDF document -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page from loaded PDF document + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a new pdf rubber stamp annotation. -RectangleF rectangleF = new RectangleF(350, 20, 200, 80); -PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangleF); + //Create a new pdf rubber stamp annotation. + RectangleF rectangleF = new RectangleF(350, 20, 200, 80); + PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangleF); -//Custom stamp the rubber stamp annotation. -PdfSolidBrush brush = new PdfSolidBrush(new PdfColor(Color.FromArgb(255, 173, 216, 230))); + //Custom stamp the rubber stamp annotation. + PdfSolidBrush brush = new PdfSolidBrush(new PdfColor(Color.FromArgb(255, 173, 216, 230))); -//Create object for RoundRect class to call RoundRect method. -RoundRect sub = new RoundRect(); + //Create object for RoundRect class to call RoundRect method. + RoundRect sub = new RoundRect(); -//Get the path for rounded rectangle. -PdfPath path = sub.RoundedRect(new RectangleF(0, 0, 200, 80), 20); + //Get the path for rounded rectangle. + PdfPath path = sub.RoundedRect(new RectangleF(0, 0, 200, 80), 20); -//Draw path in the rubber stamp annotation. -rubberStampAnnotation.Appearance.Normal.Graphics.DrawPath(brush, path); + //Draw path in the rubber stamp annotation. + rubberStampAnnotation.Appearance.Normal.Graphics.DrawPath(brush, path); -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); -//Add text in rubber stamp annotation. -rubberStampAnnotation.Appearance.Normal.Graphics.DrawString("DD/2018/1234567890", font, PdfBrushes.Black, new PointF(10, 20)); -rubberStampAnnotation.Appearance.Normal.Graphics.DrawString(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), font, PdfBrushes.Black, new PointF(10, 40)); + //Add text in rubber stamp annotation. + rubberStampAnnotation.Appearance.Normal.Graphics.DrawString("DD/2018/1234567890", font, PdfBrushes.Black, new PointF(10, 20)); + rubberStampAnnotation.Appearance.Normal.Graphics.DrawString(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"), font, PdfBrushes.Black, new PointF(10, 40)); -//Set the content of annotation. -rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; + //Set the content of annotation. + rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; -//Add annotation to the page. -loadedPage.Annotations.Add(rubberStampAnnotation); + //Add annotation to the page. + loadedPage.Annotations.Add(rubberStampAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Add-file-attachment-annotation-in-a-PDF-document/.NET/Add-file-attachment-annotation-in-a-PDF-document/Program.cs b/Annotation/Add-file-attachment-annotation-in-a-PDF-document/.NET/Add-file-attachment-annotation-in-a-PDF-document/Program.cs index 880655d3..f4232a8f 100644 --- a/Annotation/Add-file-attachment-annotation-in-a-PDF-document/.NET/Add-file-attachment-annotation-in-a-PDF-document/Program.cs +++ b/Annotation/Add-file-attachment-annotation-in-a-PDF-document/.NET/Add-file-attachment-annotation-in-a-PDF-document/Program.cs @@ -1,36 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF Document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a new rectangle. -RectangleF attachmentRectangle = new RectangleF(10, 40, 30, 30); + //Creates a new rectangle. + RectangleF attachmentRectangle = new RectangleF(10, 40, 30, 30); -//Load the PDF document. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/logo.png"), FileMode.Open, FileAccess.Read); + //Load the PDF document. + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/logo.png"), FileMode.Open, FileAccess.Read); -//Creates a new attachment annotation. -PdfAttachmentAnnotation attachmentAnnotation = new PdfAttachmentAnnotation(attachmentRectangle, @"logo.png", inputStream); + //Creates a new attachment annotation. + PdfAttachmentAnnotation attachmentAnnotation = new PdfAttachmentAnnotation(attachmentRectangle, @"logo.png", inputStream); -//Sets the attachment icon to attachment annotation. -attachmentAnnotation.Icon = PdfAttachmentIcon.PushPin; + //Sets the attachment icon to attachment annotation. + attachmentAnnotation.Icon = PdfAttachmentIcon.PushPin; -//Adds this annotation to a new page. -page.Annotations.Add(attachmentAnnotation); + //Adds this annotation to a new page. + page.Annotations.Add(attachmentAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-file-link-annotation-in-PDF/.NET-Framework/Add-file-link-annotation-in-PDF/Program.cs b/Annotation/Add-file-link-annotation-in-PDF/.NET-Framework/Add-file-link-annotation-in-PDF/Program.cs index de009901..9e4f1509 100644 --- a/Annotation/Add-file-link-annotation-in-PDF/.NET-Framework/Add-file-link-annotation-in-PDF/Program.cs +++ b/Annotation/Add-file-link-annotation-in-PDF/.NET-Framework/Add-file-link-annotation-in-PDF/Program.cs @@ -34,9 +34,6 @@ static void Main(string[] args) //Close the document. document.Close(true); - - //This will open the PDF file so, the result will be seen in default PDF viewer - Process.Start("FileLinkAnnotation.pdf"); } } } diff --git a/Annotation/Add-ink-annotation-to-the-PDF-document/.NET/Add-ink-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-ink-annotation-to-the-PDF-document/.NET/Add-ink-annotation-to-the-PDF-document/Program.cs index ea035194..a8333515 100644 --- a/Annotation/Add-ink-annotation-to-the-PDF-document/.NET/Add-ink-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-ink-annotation-to-the-PDF-document/.NET/Add-ink-annotation-to-the-PDF-document/Program.cs @@ -1,36 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Create the line points. -List linePoints = new List { 40, 300, 60, 100, 40, 50, 40, 300 }; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -RectangleF rectangle = new RectangleF(0, 0, 300, 400); + //Create the line points. + List linePoints = new List { 40, 300, 60, 100, 40, 50, 40, 300 }; -//Creates a new ink annotation. -PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); + RectangleF rectangle = new RectangleF(0, 0, 300, 400); -//Set the color of ink annotation. -inkAnnotation.Color = new PdfColor(Color.Red); + //Creates a new ink annotation. + PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); -//Adds annotation to the page. -page.Annotations.Add(inkAnnotation); + //Set the color of ink annotation. + inkAnnotation.Color = new PdfColor(Color.Red); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Adds annotation to the page. + page.Annotations.Add(inkAnnotation); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-line-annotation-to-the-PDF-document/.NET/Add-line-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-line-annotation-to-the-PDF-document/.NET/Add-line-annotation-to-the-PDF-document/Program.cs index fba11dc4..68cae97c 100644 --- a/Annotation/Add-line-annotation-to-the-PDF-document/.NET/Add-line-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-line-annotation-to-the-PDF-document/.NET/Add-line-annotation-to-the-PDF-document/Program.cs @@ -1,55 +1,47 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Specifies the line end points. -int[] points = new int[] { 80, 420, 150, 420 }; + //Specifies the line end points. + int[] points = new int[] { 80, 420, 150, 420 }; -//Creates a new line annotation. -PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annotation"); + //Creates a new line annotation. + PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annotation"); -//Creates pdf line border. -LineBorder lineBorder = new LineBorder(); -lineBorder.BorderStyle = PdfBorderStyle.Solid; -lineBorder.BorderWidth = 1; -lineAnnotation.lineBorder = lineBorder; -lineAnnotation.LineIntent = PdfLineIntent.LineDimension; + //Creates pdf line border. + LineBorder lineBorder = new LineBorder(); + lineBorder.BorderStyle = PdfBorderStyle.Solid; + lineBorder.BorderWidth = 1; + lineAnnotation.lineBorder = lineBorder; + lineAnnotation.LineIntent = PdfLineIntent.LineDimension; -//Assigns the line ending style. -lineAnnotation.BeginLineStyle = PdfLineEndingStyle.Butt; -lineAnnotation.EndLineStyle = PdfLineEndingStyle.Diamond; -lineAnnotation.AnnotationFlags = PdfAnnotationFlags.Default; + //Assigns the line ending style. + lineAnnotation.BeginLineStyle = PdfLineEndingStyle.Butt; + lineAnnotation.EndLineStyle = PdfLineEndingStyle.Diamond; + lineAnnotation.AnnotationFlags = PdfAnnotationFlags.Default; -//Assigns the line color. -lineAnnotation.InnerLineColor = new PdfColor(Color.Green); -lineAnnotation.BackColor = new PdfColor(Color.Green); + //Assigns the line color. + lineAnnotation.InnerLineColor = new PdfColor(Color.Green); + lineAnnotation.BackColor = new PdfColor(Color.Green); -//Assigns the leader line. -lineAnnotation.LeaderLineExt = 0; -lineAnnotation.LeaderLine = 0; + //Assigns the leader line. + lineAnnotation.LeaderLineExt = 0; + lineAnnotation.LeaderLine = 0; -//Assigns the Line caption type. -lineAnnotation.LineCaption = true; -lineAnnotation.CaptionType = PdfLineCaptionType.Inline; + //Assigns the Line caption type. + lineAnnotation.LineCaption = true; + lineAnnotation.CaptionType = PdfLineCaptionType.Inline; -//Adds this annotation to a new page. -page.Annotations.Add(lineAnnotation); + //Adds this annotation to a new page. + page.Annotations.Add(lineAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-popup-annotation-in-a-PDF-document/.NET/Add-popup-annotation-in-a-PDF-document/Program.cs b/Annotation/Add-popup-annotation-in-a-PDF-document/.NET/Add-popup-annotation-in-a-PDF-document/Program.cs index 93260ee1..9cb2667f 100644 --- a/Annotation/Add-popup-annotation-in-a-PDF-document/.NET/Add-popup-annotation-in-a-PDF-document/Program.cs +++ b/Annotation/Add-popup-annotation-in-a-PDF-document/.NET/Add-popup-annotation-in-a-PDF-document/Program.cs @@ -1,37 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new PDF page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a new PDF page. + PdfPage page = document.Pages.Add(); -//Creates a new rectangle. -RectangleF rectangle = new RectangleF(10, 40, 30, 30); + //Creates a new rectangle. + RectangleF rectangle = new RectangleF(10, 40, 30, 30); -//Creates a new popup annotation with some properties. -PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rectangle, "Test popup annotation"); -popupAnnotation.Border.Width = 4; -popupAnnotation.Border.HorizontalRadius = 20; -popupAnnotation.Border.VerticalRadius = 30; + //Creates a new popup annotation with some properties. + PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rectangle, "Test popup annotation"); + popupAnnotation.Border.Width = 4; + popupAnnotation.Border.HorizontalRadius = 20; + popupAnnotation.Border.VerticalRadius = 30; -//Sets the PDF popup icon. -popupAnnotation.Icon = PdfPopupIcon.NewParagraph; + //Sets the PDF popup icon. + popupAnnotation.Icon = PdfPopupIcon.NewParagraph; -//Adds this annotation to a new page. -page.Annotations.Add(popupAnnotation); + //Adds this annotation to a new page. + page.Annotations.Add(popupAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); - diff --git a/Annotation/Add-rich-media-annotation-to-PDF-document/.NET/Add-rich-media-annotation-to-PDF-document/Program.cs b/Annotation/Add-rich-media-annotation-to-PDF-document/.NET/Add-rich-media-annotation-to-PDF-document/Program.cs index 86afe78f..f8050cbf 100644 --- a/Annotation/Add-rich-media-annotation-to-PDF-document/.NET/Add-rich-media-annotation-to-PDF-document/Program.cs +++ b/Annotation/Add-rich-media-annotation-to-PDF-document/.NET/Add-rich-media-annotation-to-PDF-document/Program.cs @@ -1,43 +1,33 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document from stream. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create the PDF richmedia annotation. -PdfRichMediaAnnotation richMediaAnnotation = new PdfRichMediaAnnotation(new RectangleF(0, 0, 200, 100)); + //Create the PDF richmedia annotation. + PdfRichMediaAnnotation richMediaAnnotation = new PdfRichMediaAnnotation(new RectangleF(0, 0, 200, 100)); -//Set properties to the annotation. -richMediaAnnotation.ActivationMode = PdfRichMediaActivationMode.Click; -richMediaAnnotation.PresentationStyle = PdfRichMediaPresentationStyle.Windowed; + //Set properties to the annotation. + richMediaAnnotation.ActivationMode = PdfRichMediaActivationMode.Click; + richMediaAnnotation.PresentationStyle = PdfRichMediaPresentationStyle.Windowed; -//Set the richmedia content. -FileStream fileStream = new FileStream(Path.GetFullPath("Data/Sample_Video.mp4"), FileMode.Open, FileAccess.Read); -PdfRichMediaContent content = new PdfRichMediaContent("video", fileStream, "mp4"); -richMediaAnnotation.Content = content; + //Set the richmedia content. + FileStream fileStream = new FileStream(Path.GetFullPath("Data/Sample_Video.mp4"), FileMode.Open, FileAccess.Read); + PdfRichMediaContent content = new PdfRichMediaContent("video", fileStream, "mp4"); + richMediaAnnotation.Content = content; -//Create the appearance of the richmedia. -richMediaAnnotation.Appearance.Normal.Graphics.DrawString("Click here to play video...", new PdfStandardFont(PdfFontFamily.Helvetica, 15), PdfBrushes.Blue, new RectangleF(0, 0, 200, 100), new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)); + //Create the appearance of the richmedia. + richMediaAnnotation.Appearance.Normal.Graphics.DrawString("Click here to play video...", new PdfStandardFont(PdfFontFamily.Helvetica, 15), PdfBrushes.Blue, new RectangleF(0, 0, 200, 100), new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)); -//Add the annotation to the page. -loadedPage.Annotations.Add(richMediaAnnotation); + //Add the annotation to the page. + loadedPage.Annotations.Add(richMediaAnnotation); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); \ No newline at end of file diff --git a/Annotation/Add-rubberstamp-annotation-to-the-PDF-document/.NET/Add-rubberstamp-annotation-to-the-PDF-document/Program.cs b/Annotation/Add-rubberstamp-annotation-to-the-PDF-document/.NET/Add-rubberstamp-annotation-to-the-PDF-document/Program.cs index e4b4171a..c7baaa6f 100644 --- a/Annotation/Add-rubberstamp-annotation-to-the-PDF-document/.NET/Add-rubberstamp-annotation-to-the-PDF-document/Program.cs +++ b/Annotation/Add-rubberstamp-annotation-to-the-PDF-document/.NET/Add-rubberstamp-annotation-to-the-PDF-document/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Creates a new pdf rubber stamp annotation. -RectangleF rectangle = new RectangleF(40, 60, 80, 20); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Create rubber stamp annotation with some properties. -PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Text Rubber Stamp Annotation"); -rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Draft; -rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; + //Creates a new pdf rubber stamp annotation. + RectangleF rectangle = new RectangleF(40, 60, 80, 20); -//Adds annotation to the page. -page.Annotations.Add(rubberStampAnnotation); + //Create rubber stamp annotation with some properties. + PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Text Rubber Stamp Annotation"); + rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Draft; + rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Adds annotation to the page. + page.Annotations.Add(rubberStampAnnotation); -//Close the document. -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/.NET/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/Program.cs b/Annotation/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/.NET/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/Program.cs index e4d3dfab..38282d4e 100644 --- a/Annotation/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/.NET/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/Program.cs +++ b/Annotation/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/.NET/Add-the-JavaScript-script-to-the-3D-annotation-in-a-PDF/Program.cs @@ -1,33 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Get stream from the U3D file. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/threeLevelHierarchy.u3d"), FileMode.Open, FileAccess.Read); + //Get stream from the U3D file. + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/threeLevelHierarchy.u3d"), FileMode.Open, FileAccess.Read); -//Creates a new PDF 3D annotation. -Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream); + //Creates a new PDF 3D annotation. + Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream); -//Assign JavaScript script. -pdf3dAnnotation.OnInstantiate = "host.getURL(\"http://www.google.com\")"; + //Assign JavaScript script. + pdf3dAnnotation.OnInstantiate = "host.getURL(\"http://www.google.com\")"; -//Adds annotation to page. -page.Annotations.Add(pdf3dAnnotation); + //Adds annotation to page. + page.Annotations.Add(pdf3dAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Add-the-review-status-to-the-existing-PDF-annotation/.NET/Add-the-review-status-to-the-existing-PDF-annotation/Program.cs b/Annotation/Add-the-review-status-to-the-existing-PDF-annotation/.NET/Add-the-review-status-to-the-existing-PDF-annotation/Program.cs index 259ff282..a9aee293 100644 --- a/Annotation/Add-the-review-status-to-the-existing-PDF-annotation/.NET/Add-the-review-status-to-the-existing-PDF-annotation/Program.cs +++ b/Annotation/Add-the-review-status-to-the-existing-PDF-annotation/.NET/Add-the-review-status-to-the-existing-PDF-annotation/Program.cs @@ -1,48 +1,37 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing annotations. -PdfLoadedAnnotationCollection annots = lpage.Annotations; + //Get the existing annotations. + PdfLoadedAnnotationCollection annots = lpage.Annotations; -//Get the existing rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; + //Get the existing rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; -//Create a new review annotation. -PdfPopupAnnotation review = new PdfPopupAnnotation(); + //Create a new review annotation. + PdfPopupAnnotation review = new PdfPopupAnnotation(); -//Set author. -review.Author = "John"; + //Set author. + review.Author = "John"; -//Set review state model. -review.StateModel = PdfAnnotationStateModel.Review; + //Set review state model. + review.StateModel = PdfAnnotationStateModel.Review; -//Set review state. -review.State = PdfAnnotationState.Accepted; + //Set review state. + review.State = PdfAnnotationState.Accepted; -//Set modification date. -review.ModifiedDate = DateTime.Now; + //Set modification date. + review.ModifiedDate = DateTime.Now; -//Add the review to the annotation. -loadedRectangleAnnotation.ReviewHistory.Add(review); + //Add the review to the annotation. + loadedRectangleAnnotation.ReviewHistory.Add(review); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Add-watermark-annotation-in-the-PDF-document/.NET/Add-watermark-annotation-in-the-PDF-document/Program.cs b/Annotation/Add-watermark-annotation-in-the-PDF-document/.NET/Add-watermark-annotation-in-the-PDF-document/Program.cs index 836d78dd..7673362e 100644 --- a/Annotation/Add-watermark-annotation-in-the-PDF-document/.NET/Add-watermark-annotation-in-the-PDF-document/Program.cs +++ b/Annotation/Add-watermark-annotation-in-the-PDF-document/.NET/Add-watermark-annotation-in-the-PDF-document/Program.cs @@ -1,37 +1,27 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Creates PDF watermark annotation. -PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(new RectangleF(50, 50, 400, 100)); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Sets properties to the annotation. -watermark.Opacity = 0.5f; + //Creates PDF watermark annotation. + PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(new RectangleF(50, 50, 400, 100)); -//Create the appearance of watermark. -watermark.Appearance.Normal.Graphics.DrawString("Watermark Text", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Red, new RectangleF(0, 0, 200, 50), new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)); + //Sets properties to the annotation. + watermark.Opacity = 0.5f; -//Adds the annotation to page. -loadedPage.Annotations.Add(watermark); + //Create the appearance of watermark. + watermark.Appearance.Normal.Graphics.DrawString("Watermark Text", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Red, new RectangleF(0, 0, 200, 50), new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputFileStream); -} + //Adds the annotation to page. + loadedPage.Annotations.Add(watermark); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Adding-quad-points-to-existing-redaction-annotations/.NET/Adding-quad-points-to-existing-redaction-annotations/Program.cs b/Annotation/Adding-quad-points-to-existing-redaction-annotations/.NET/Adding-quad-points-to-existing-redaction-annotations/Program.cs index af65881b..0a5eb9f9 100644 --- a/Annotation/Adding-quad-points-to-existing-redaction-annotations/.NET/Adding-quad-points-to-existing-redaction-annotations/Program.cs +++ b/Annotation/Adding-quad-points-to-existing-redaction-annotations/.NET/Adding-quad-points-to-existing-redaction-annotations/Program.cs @@ -3,42 +3,32 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -// Load the existing PDF document using FileStream -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the PDF document from the input stream - using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream)) - { - //Load the existing PdfLoadedRedactionAnnotation - PdfLoadedRedactionAnnotation annot = ldoc.Pages[0].Annotations[0] as PdfLoadedRedactionAnnotation; + //Load the existing PdfLoadedRedactionAnnotation + PdfLoadedRedactionAnnotation annot = loadedDocument.Pages[0].Annotations[0] as PdfLoadedRedactionAnnotation; - //set the bounds - List bounds = new List(); - bounds.Add(new RectangleF(100, 100, 50, 20)); - bounds.Add(new RectangleF(200, 150, 60, 25)); - annot.BoundsCollection = bounds; + //set the bounds + List bounds = new List(); + bounds.Add(new RectangleF(100, 100, 50, 20)); + bounds.Add(new RectangleF(200, 150, 60, 25)); + annot.BoundsCollection = bounds; - //set the inner color - annot.InnerColor = Color.Black; - //set the border color - annot.BorderColor = Color.Green; - //set the text color - annot.TextColor = Color.Yellow; - //set the font - annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); - //set overlay text - annot.OverlayText = "Redact"; - //set text alignment - annot.TextAlignment = PdfTextAlignment.Center; - annot.RepeatText = true; + //set the inner color + annot.InnerColor = Color.Black; + //set the border color + annot.BorderColor = Color.Green; + //set the text color + annot.TextColor = Color.Yellow; + //set the font + annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); + //set overlay text + annot.OverlayText = "Redact"; + //set text alignment + annot.TextAlignment = PdfTextAlignment.Center; + annot.RepeatText = true; - // Save the modified document using a new FileStream - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - // Save changes to a new PDF file - ldoc.Save(outputStream); - } - // Close the document and release resources - ldoc.Close(true); - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } diff --git a/Annotation/Adding-transparency-for-annotations/.NET/Adding-transparency-for-annotations/Program.cs b/Annotation/Adding-transparency-for-annotations/.NET/Adding-transparency-for-annotations/Program.cs index a6cf200d..3086e65a 100644 --- a/Annotation/Adding-transparency-for-annotations/.NET/Adding-transparency-for-annotations/Program.cs +++ b/Annotation/Adding-transparency-for-annotations/.NET/Adding-transparency-for-annotations/Program.cs @@ -3,31 +3,27 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Add a new page. -PdfPage page = document.Pages.Add(); -//Create a new rectangle -RectangleF textAnnotationBounds = new RectangleF(10, 40, 100, 30); -//Create a new free text annotation. -PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(textAnnotationBounds); -//Set the text and font -textAnnotation.MarkupText = "Text Annotation"; -textAnnotation.Font = new PdfStandardFont(PdfFontFamily.Courier, 10); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page. + PdfPage page = document.Pages.Add(); + //Create a new rectangle + RectangleF textAnnotationBounds = new RectangleF(10, 40, 100, 30); + //Create a new free text annotation. + PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(textAnnotationBounds); + //Set the text and font + textAnnotation.MarkupText = "Text Annotation"; + textAnnotation.Font = new PdfStandardFont(PdfFontFamily.Courier, 10); -//Set transparency -textAnnotation.Opacity = 0.5F; + //Set transparency + textAnnotation.Opacity = 0.5F; -//Set the line caption type. -textAnnotation.AnnotationIntent = PdfAnnotationIntent.FreeTextCallout; -//Add this annotation to the PDF page. -page.Annotations.Add(textAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Set the line caption type. + textAnnotation.AnnotationIntent = PdfAnnotationIntent.FreeTextCallout; + //Add this annotation to the PDF page. + page.Annotations.Add(textAnnotation); -//Close the document -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Exporting-Newly-Added-Annotations-FDF-File/.NET/Exporting-Newly-Added-Annotations-FDF-File/Program.cs b/Annotation/Exporting-Newly-Added-Annotations-FDF-File/.NET/Exporting-Newly-Added-Annotations-FDF-File/Program.cs index 69bb4408..3f462b0f 100644 --- a/Annotation/Exporting-Newly-Added-Annotations-FDF-File/.NET/Exporting-Newly-Added-Annotations-FDF-File/Program.cs +++ b/Annotation/Exporting-Newly-Added-Annotations-FDF-File/.NET/Exporting-Newly-Added-Annotations-FDF-File/Program.cs @@ -4,9 +4,8 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Load the PDF document from a file stream -using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { //Create a PDF free text annotation PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(10, 0, 50, 50)); @@ -20,11 +19,8 @@ freeText.Border = new PdfAnnotationBorder(0.5f); //Set border thickness //Add the annotation to the first page of the PDF - pdfLoadedDocument.Pages[0].Annotations.Add(freeText); + loadedDocument.Pages[0].Annotations.Add(freeText); - //Export annotations to the FDF format and save to a file using a file stream - using (FileStream fdfFileStream = new FileStream(Path.GetFullPath(@"Output/Output.fdf"), FileMode.Create, FileAccess.Write)) - { - pdfLoadedDocument.ExportAnnotations(fdfFileStream, AnnotationDataFormat.Fdf); - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Annotation/Exporting-Newly-Added-Annotations-JSON-File/.NET/Exporting-Newly-Added-Annotations-JSON-File/Program.cs b/Annotation/Exporting-Newly-Added-Annotations-JSON-File/.NET/Exporting-Newly-Added-Annotations-JSON-File/Program.cs index edd0cb08..b1bfdc9b 100644 --- a/Annotation/Exporting-Newly-Added-Annotations-JSON-File/.NET/Exporting-Newly-Added-Annotations-JSON-File/Program.cs +++ b/Annotation/Exporting-Newly-Added-Annotations-JSON-File/.NET/Exporting-Newly-Added-Annotations-JSON-File/Program.cs @@ -3,9 +3,8 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Load the PDF document from a file stream -using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { //Create a PDF free text annotation PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(10, 0, 50, 50)); @@ -19,11 +18,8 @@ freeText.Border = new PdfAnnotationBorder(0.5f); //Set border thickness //Add the annotation to the first page of the PDF - pdfLoadedDocument.Pages[0].Annotations.Add(freeText); + loadedDocument.Pages[0].Annotations.Add(freeText); - //Export annotations to the JSON format and save to a file using a file stream - using (FileStream jsonFileStream = new FileStream(Path.GetFullPath(@"Output/Output.json"), FileMode.Create, FileAccess.Write)) - { - pdfLoadedDocument.ExportAnnotations(jsonFileStream, AnnotationDataFormat.Json); - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Annotation/Exporting-Newly-Added-Annotations-XFDF-File/.NET/Exporting-Newly-Added-Annotations-XFDF-File/Program.cs b/Annotation/Exporting-Newly-Added-Annotations-XFDF-File/.NET/Exporting-Newly-Added-Annotations-XFDF-File/Program.cs index b1dcf47f..b1bfdc9b 100644 --- a/Annotation/Exporting-Newly-Added-Annotations-XFDF-File/.NET/Exporting-Newly-Added-Annotations-XFDF-File/Program.cs +++ b/Annotation/Exporting-Newly-Added-Annotations-XFDF-File/.NET/Exporting-Newly-Added-Annotations-XFDF-File/Program.cs @@ -3,9 +3,8 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Load the PDF document from a file stream -using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(docStream)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { //Create a PDF free text annotation PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(10, 0, 50, 50)); @@ -19,11 +18,8 @@ freeText.Border = new PdfAnnotationBorder(0.5f); //Set border thickness //Add the annotation to the first page of the PDF - pdfLoadedDocument.Pages[0].Annotations.Add(freeText); + loadedDocument.Pages[0].Annotations.Add(freeText); - //Export annotations to the XFDF format and save to a file using a file stream - using (FileStream xfdfFileStream = new FileStream(Path.GetFullPath(@"Output/Output.xfdf"), FileMode.Create, FileAccess.Write)) - { - pdfLoadedDocument.ExportAnnotations(xfdfFileStream, AnnotationDataFormat.XFdf); - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Annotation/Exporting-annotation-to-FDF-file-from-PDF-document/.NET/Exporting-annotation-to-FDF-file-from-PDF-document/Program.cs b/Annotation/Exporting-annotation-to-FDF-file-from-PDF-document/.NET/Exporting-annotation-to-FDF-file-from-PDF-document/Program.cs index 4efcab6a..b1a5a6a1 100644 --- a/Annotation/Exporting-annotation-to-FDF-file-from-PDF-document/.NET/Exporting-annotation-to-FDF-file-from-PDF-document/Program.cs +++ b/Annotation/Exporting-annotation-to-FDF-file-from-PDF-document/.NET/Exporting-annotation-to-FDF-file-from-PDF-document/Program.cs @@ -1,30 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Export annotation data from FDF stream. -Stream fdfStream = new MemoryStream(); - -//Export annotation to FDF file from PDF document. -loadedDocument.ExportAnnotations(fdfStream, AnnotationDataFormat.Fdf); +using Syncfusion.Pdf.Parsing; +//Loads the document +PdfLoadedDocument lDoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); +//Export annotation data to XFDF file +lDoc.ExportAnnotations("Annotations.xfdf", AnnotationDataFormat.fdf); //Close the document -loadedDocument.Close(true); - -fdfStream.Position = 0; - -//Create file stream. -FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.fdf"), FileMode.Create, FileAccess.ReadWrite); - -//Copy the memory stream to file stream. -fdfStream.CopyTo(outputFileStream); - -//dispose the streams. -fdfStream.Dispose(); -outputFileStream.Dispose(); \ No newline at end of file +lDoc.Close(true); \ No newline at end of file diff --git a/Annotation/Exporting-annotations-to-JSON-file-from-PDF-document/.NET/Exporting-annotations-to-JSON-file-from-PDF-document/Program.cs b/Annotation/Exporting-annotations-to-JSON-file-from-PDF-document/.NET/Exporting-annotations-to-JSON-file-from-PDF-document/Program.cs index a7c3edc5..19b66cd8 100644 --- a/Annotation/Exporting-annotations-to-JSON-file-from-PDF-document/.NET/Exporting-annotations-to-JSON-file-from-PDF-document/Program.cs +++ b/Annotation/Exporting-annotations-to-JSON-file-from-PDF-document/.NET/Exporting-annotations-to-JSON-file-from-PDF-document/Program.cs @@ -1,30 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Export the annotation data from the JSON stream. -Stream jsonStream = new MemoryStream(); - -//Export annotations to JSON file from PDF document. -loadedDocument.ExportAnnotations(jsonStream, AnnotationDataFormat.Json); - -//Close the document. -loadedDocument.Close(true); - -jsonStream.Position = 0; - -//Create file stream. -FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.json"), FileMode.Create, FileAccess.ReadWrite); - -//Copy the memory stream to file stream. -jsonStream.CopyTo(outputFileStream); - -//Dispose the stream. -jsonStream.Dispose(); -outputFileStream.Dispose(); \ No newline at end of file +using Syncfusion.Pdf.Parsing; + +//Loads the document +PdfLoadedDocument lDoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); +//Export the annotation data to the JSON file +lDoc.ExportAnnotations("Annotations.Json", AnnotationDataFormat.Json); +//Close the document +lDoc.Close(true); \ No newline at end of file diff --git a/Annotation/Exporting-annotations-to-XFDF-file-from-PDF-document/.NET/Exporting-annotations-to-XFDF-file-from-PDF-document/Program.cs b/Annotation/Exporting-annotations-to-XFDF-file-from-PDF-document/.NET/Exporting-annotations-to-XFDF-file-from-PDF-document/Program.cs index 964a8b61..d744e1e7 100644 --- a/Annotation/Exporting-annotations-to-XFDF-file-from-PDF-document/.NET/Exporting-annotations-to-XFDF-file-from-PDF-document/Program.cs +++ b/Annotation/Exporting-annotations-to-XFDF-file-from-PDF-document/.NET/Exporting-annotations-to-XFDF-file-from-PDF-document/Program.cs @@ -1,30 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument lDoc = new PdfLoadedDocument(docStream); - -//Export annotation data from XFDF stream. -Stream xfdfStream = new MemoryStream(); - -//Export annotations to XFDF file from PDF document. -lDoc.ExportAnnotations(xfdfStream, AnnotationDataFormat.XFdf); +using Syncfusion.Pdf.Parsing; +//Loads the document +PdfLoadedDocument lDoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); +//Export annotation data to XFDF file +lDoc.ExportAnnotations("Annotations.xfdf", AnnotationDataFormat.XFdf); //Close the document -lDoc.Close(true); - -xfdfStream.Position = 0; - -//Create file stream. -FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.xfdf"), FileMode.Create, FileAccess.ReadWrite); - -//Copy memory stream to file stream. -xfdfStream.CopyTo(outputFileStream); - -//Dispose the streams. -xfdfStream.Dispose(); -outputFileStream.Dispose(); \ No newline at end of file +lDoc.Close(true); \ No newline at end of file diff --git a/Annotation/Flatten-popup-annotation-in-the-PDF-document/.NET/Flatten-popup-annotation-in-the-PDF-document/Program.cs b/Annotation/Flatten-popup-annotation-in-the-PDF-document/.NET/Flatten-popup-annotation-in-the-PDF-document/Program.cs index 2fc9b5be..b885dcc7 100644 --- a/Annotation/Flatten-popup-annotation-in-the-PDF-document/.NET/Flatten-popup-annotation-in-the-PDF-document/Program.cs +++ b/Annotation/Flatten-popup-annotation-in-the-PDF-document/.NET/Flatten-popup-annotation-in-the-PDF-document/Program.cs @@ -1,37 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get all the pages. -foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - foreach (PdfLoadedAnnotation annotation in loadedPage.Annotations) + //Get all the pages. + foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) { - if (annotation is PdfLoadedPopupAnnotation) + foreach (PdfLoadedAnnotation annotation in loadedPage.Annotations) { - //Enable the flatten annotation. - annotation.Flatten = true; + if (annotation is PdfLoadedPopupAnnotation) + { + //Enable the flatten annotation. + annotation.Flatten = true; - //Enable flatten for the pop-up window annotation. - annotation.FlattenPopUps = true; + //Enable flatten for the pop-up window annotation. + annotation.FlattenPopUps = true; + } } } -} - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Flatten-specific-types-of-annotations/.NET/Flatten-specific-types-of-annotations/Program.cs b/Annotation/Flatten-specific-types-of-annotations/.NET/Flatten-specific-types-of-annotations/Program.cs index 7e69cb47..6cd37dbd 100644 --- a/Annotation/Flatten-specific-types-of-annotations/.NET/Flatten-specific-types-of-annotations/Program.cs +++ b/Annotation/Flatten-specific-types-of-annotations/.NET/Flatten-specific-types-of-annotations/Program.cs @@ -1,25 +1,18 @@ using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Load the PDF document using a file stream -using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Load the existing PDF document - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream)) + //Specify the annotation types to flatten + PdfLoadedAnnotationType[] pdfLoadedAnnotationTypes = new PdfLoadedAnnotationType[] { - //Specify the annotation types to flatten - PdfLoadedAnnotationType[] pdfLoadedAnnotationTypes = new PdfLoadedAnnotationType[] - { PdfLoadedAnnotationType.PolygonAnnotation - }; + }; - //Flatten the selected annotations - loadedDocument.FlattenAnnotations(pdfLoadedAnnotationTypes); + //Flatten the selected annotations + loadedDocument.FlattenAnnotations(pdfLoadedAnnotationTypes); - //Save the flattened document using a file stream - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - loadedDocument.Save(outputStream); - } - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Annotation/Flatten-the-annotations-in-an-existing-PDF-document/.NET/Flatten-the-annotations-in-an-existing-PDF-document/Program.cs b/Annotation/Flatten-the-annotations-in-an-existing-PDF-document/.NET/Flatten-the-annotations-in-an-existing-PDF-document/Program.cs index 5286484f..04fbb513 100644 --- a/Annotation/Flatten-the-annotations-in-an-existing-PDF-document/.NET/Flatten-the-annotations-in-an-existing-PDF-document/Program.cs +++ b/Annotation/Flatten-the-annotations-in-an-existing-PDF-document/.NET/Flatten-the-annotations-in-an-existing-PDF-document/Program.cs @@ -1,27 +1,16 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get all the pages -foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) -{ - //Flatten all the annotations in the page - loadedPage.Annotations.Flatten = true; -} - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Get all the pages + foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) + { + //Flatten all the annotations in the page + loadedPage.Annotations.Flatten = true; + } -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Flatten-the-specific-annotaiton-in-the-PDF-document/.NET/Flatten-the-specific-annotaiton-in-the-PDF-document/Program.cs b/Annotation/Flatten-the-specific-annotaiton-in-the-PDF-document/.NET/Flatten-the-specific-annotaiton-in-the-PDF-document/Program.cs index c8d8aa91..dc558707 100644 --- a/Annotation/Flatten-the-specific-annotaiton-in-the-PDF-document/.NET/Flatten-the-specific-annotaiton-in-the-PDF-document/Program.cs +++ b/Annotation/Flatten-the-specific-annotaiton-in-the-PDF-document/.NET/Flatten-the-specific-annotaiton-in-the-PDF-document/Program.cs @@ -1,36 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get all the pages -foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Flatten all the annotations in the page - foreach (PdfLoadedAnnotation annotation in loadedPage.Annotations) + //Get all the pages + foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) { - //Check for the circle annotation - if (annotation is PdfLoadedCircleAnnotation) + //Flatten all the annotations in the page + foreach (PdfLoadedAnnotation annotation in loadedPage.Annotations) { - //Flatten the circle annotation - annotation.Flatten = true; + //Check for the circle annotation + if (annotation is PdfLoadedCircleAnnotation) + { + //Flatten the circle annotation + annotation.Flatten = true; + } } } -} -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Flattening-annotations-with-popups-in-PDF/.NET/Flattening-annotations-with-popups-in-PDF/Program.cs b/Annotation/Flattening-annotations-with-popups-in-PDF/.NET/Flattening-annotations-with-popups-in-PDF/Program.cs index 8208c4c2..f5a38dbc 100644 --- a/Annotation/Flattening-annotations-with-popups-in-PDF/.NET/Flattening-annotations-with-popups-in-PDF/Program.cs +++ b/Annotation/Flattening-annotations-with-popups-in-PDF/.NET/Flattening-annotations-with-popups-in-PDF/Program.cs @@ -1,21 +1,11 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Flatten all the annotations without popups in the document. -loadedDocument.FlattenAnnotations(true); - -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - loadedDocument.Save(outputFileStream); -} + //Flatten all the annotations without popups in the document. + loadedDocument.FlattenAnnotations(true); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Flattening-annotations-without-calling-save-method/.NET/Flattening-annotations-without-calling-save-method/Program.cs b/Annotation/Flattening-annotations-without-calling-save-method/.NET/Flattening-annotations-without-calling-save-method/Program.cs index 167e6a3d..c2597da4 100644 --- a/Annotation/Flattening-annotations-without-calling-save-method/.NET/Flattening-annotations-without-calling-save-method/Program.cs +++ b/Annotation/Flattening-annotations-without-calling-save-method/.NET/Flattening-annotations-without-calling-save-method/Program.cs @@ -1,21 +1,11 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Flatten all the annotations without popups in the document. -loadedDocument.FlattenAnnotations(); - -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - loadedDocument.Save(outputFileStream); -} + //Flatten all the annotations without popups in the document. + loadedDocument.FlattenAnnotations(); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Get-annotation-creation-date-from-PDF/.NET/Get-annotation-creation-date-from-pdf/Program.cs b/Annotation/Get-annotation-creation-date-from-PDF/.NET/Get-annotation-creation-date-from-pdf/Program.cs index cb4965b8..2567a4ab 100644 --- a/Annotation/Get-annotation-creation-date-from-PDF/.NET/Get-annotation-creation-date-from-pdf/Program.cs +++ b/Annotation/Get-annotation-creation-date-from-PDF/.NET/Get-annotation-creation-date-from-pdf/Program.cs @@ -2,21 +2,18 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -// Load the PDF document -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - using (PdfLoadedDocument document = new PdfLoadedDocument(inputStream)) - { + //Get the first page from the document + PdfLoadedPage firstPage = loadedDocument.Pages[0] as PdfLoadedPage; - //Get the first page from the document - PdfLoadedPage firstPage = document.Pages[0] as PdfLoadedPage; + //Get the annotation on that page + PdfLoadedAnnotation annotation = firstPage.Annotations[0] as PdfLoadedAnnotation; - //Get the annotation on that page - PdfLoadedAnnotation annotation = firstPage.Annotations[0] as PdfLoadedAnnotation; + //Get the annotation creation date. + DateTime creationDate = annotation.CreationDate; - //Get the annotation creation date. - DateTime creationDate = annotation.CreationDate; + Console.WriteLine("Annotation Creation Date: " + creationDate); - Console.WriteLine("Annotation Creation Date: " + creationDate); - } } diff --git a/Annotation/Get-annotation-type-from-pdf/.NET/Get-annotation-type-from-pdf/Program.cs b/Annotation/Get-annotation-type-from-pdf/.NET/Get-annotation-type-from-pdf/Program.cs index 7ccb4106..512c07af 100644 --- a/Annotation/Get-annotation-type-from-pdf/.NET/Get-annotation-type-from-pdf/Program.cs +++ b/Annotation/Get-annotation-type-from-pdf/.NET/Get-annotation-type-from-pdf/Program.cs @@ -2,22 +2,19 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -// Load the PDF document using a file stream -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - using (PdfLoadedDocument document = new PdfLoadedDocument(inputStream)) + //Get the pages of the PDF file + for (int i = 0; i < loadedDocument.PageCount; i++) { - //Get the pages of the PDF file - for (int i = 0; i < document.PageCount; i++) - { - Console.WriteLine("Page Number: " + i); - PdfLoadedPage page = document.Pages[i] as PdfLoadedPage; + Console.WriteLine("Page Number: " + i); + PdfLoadedPage page = loadedDocument.Pages[i] as PdfLoadedPage; - //Get the annotation type. - foreach (PdfLoadedAnnotation annotation in page.Annotations) - { - Console.WriteLine("Annotation Type: " + annotation.Type.ToString()); - } + //Get the annotation type. + foreach (PdfLoadedAnnotation annotation in page.Annotations) + { + Console.WriteLine("Annotation Type: " + annotation.Type.ToString()); } } } \ No newline at end of file diff --git a/Annotation/Get-the-ink-list-points-from-the-existing-PDF-document/.NET/Get-the-ink-list-points-from-the-existing-PDF-document/Program.cs b/Annotation/Get-the-ink-list-points-from-the-existing-PDF-document/.NET/Get-the-ink-list-points-from-the-existing-PDF-document/Program.cs index 29c7fbfe..6f36eb2a 100644 --- a/Annotation/Get-the-ink-list-points-from-the-existing-PDF-document/.NET/Get-the-ink-list-points-from-the-existing-PDF-document/Program.cs +++ b/Annotation/Get-the-ink-list-points-from-the-existing-PDF-document/.NET/Get-the-ink-list-points-from-the-existing-PDF-document/Program.cs @@ -1,33 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Gets the first page from the document. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - -//Gets the annotation collection. -PdfLoadedAnnotationCollection annotations = page.Annotations; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Gets the first ink annotation. -PdfLoadedInkAnnotation inkAnnotation = annotations[0] as PdfLoadedInkAnnotation; + //Gets the annotation collection. + PdfLoadedAnnotationCollection annotations = page.Annotations; -//Gets the ink points collection. -List> points = inkAnnotation.InkPointsCollection; + //Gets the first ink annotation. + PdfLoadedInkAnnotation inkAnnotation = annotations[0] as PdfLoadedInkAnnotation; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Gets the ink points collection. + List> points = inkAnnotation.InkPointsCollection; -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Get-value-from-PDF-annotation/.NET/Get-value-from-PDF-annotation/Program.cs b/Annotation/Get-value-from-PDF-annotation/.NET/Get-value-from-PDF-annotation/Program.cs index cd08b105..ce8994d8 100644 --- a/Annotation/Get-value-from-PDF-annotation/.NET/Get-value-from-PDF-annotation/Program.cs +++ b/Annotation/Get-value-from-PDF-annotation/.NET/Get-value-from-PDF-annotation/Program.cs @@ -2,30 +2,24 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -// Load the existing PDF document using FileStream -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the PDF document from the input stream - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream)) + // Access the first page of the document + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; + // Get the collection of annotations from the page + PdfLoadedAnnotationCollection annotations = page.Annotations; + + // Check if at least one annotation exists and it's a popup annotation + if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation) { - // Access the first page of the document - PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - // Get the collection of annotations from the page - PdfLoadedAnnotationCollection annotations = page.Annotations; + // Get the custom value from the annotation + List customValue = annotation.GetValues("custom"); - // Check if at least one annotation exists and it's a popup annotation - if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation) + foreach (string value in customValue) { - // Get the custom value from the annotation - List customValue = annotation.GetValues("custom"); - - foreach (string value in customValue) - { - // Print the custom value to the console - Console.WriteLine("Custom value from annotation: " + value); - } + // Print the custom value to the console + Console.WriteLine("Custom value from annotation: " + value); } - // Close the document and release resources - loadedDocument.Close(true); } } diff --git a/Annotation/Highlight-text-in-the-newly-created-PDF-document/.NET/Highlight-text-in-the-newly-created-PDF-document/Program.cs b/Annotation/Highlight-text-in-the-newly-created-PDF-document/.NET/Highlight-text-in-the-newly-created-PDF-document/Program.cs index fa5ff2b8..dde38d30 100644 --- a/Annotation/Highlight-text-in-the-newly-created-PDF-document/.NET/Highlight-text-in-the-newly-created-PDF-document/Program.cs +++ b/Annotation/Highlight-text-in-the-newly-created-PDF-document/.NET/Highlight-text-in-the-newly-created-PDF-document/Program.cs @@ -1,54 +1,46 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); - -//Get stream from the font file. -FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read); +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Create PDF font. -PdfFont pdfFont = new PdfTrueTypeFont(fontStream, 14); + //Get stream from the font file. + FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read); -//Create a new PDF brush. -PdfBrush pdfBrush = new PdfSolidBrush(Color.Black); + //Create PDF font. + PdfFont pdfFont = new PdfTrueTypeFont(fontStream, 14); -//Draw text in the new page. -page.Graphics.DrawString("Text Markup Annotation Demo", pdfFont, pdfBrush, new PointF(150, 10)); + //Create a new PDF brush. + PdfBrush pdfBrush = new PdfSolidBrush(Color.Black); -//Set markup text. -string markupText = "Text Markup"; + //Draw text in the new page. + page.Graphics.DrawString("Text Markup Annotation Demo", pdfFont, pdfBrush, new PointF(150, 10)); -//Get the size of the given string. -SizeF size = pdfFont.MeasureString(markupText); + //Set markup text. + string markupText = "Text Markup"; -//Draw text in the page. -RectangleF rectangle = new RectangleF(175, 40, size.Width, size.Height); -page.Graphics.DrawString(markupText, pdfFont, pdfBrush, rectangle); + //Get the size of the given string. + SizeF size = pdfFont.MeasureString(markupText); -//Create a PDF text markup annotation. -PdfTextMarkupAnnotation markupAnnotation = new PdfTextMarkupAnnotation("Markup annotation", "Markup annotation with highlight style", markupText, new PointF(175, 40), pdfFont); + //Draw text in the page. + RectangleF rectangle = new RectangleF(175, 40, size.Width, size.Height); + page.Graphics.DrawString(markupText, pdfFont, pdfBrush, rectangle); -//Set the properties of text markup annotation. -markupAnnotation.TextMarkupColor = new PdfColor(Color.BlueViolet); -markupAnnotation.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight; + //Create a PDF text markup annotation. + PdfTextMarkupAnnotation markupAnnotation = new PdfTextMarkupAnnotation("Markup annotation", "Markup annotation with highlight style", markupText, new PointF(175, 40), pdfFont); -//Add this annotation to a new page. -page.Annotations.Add(markupAnnotation); + //Set the properties of text markup annotation. + markupAnnotation.TextMarkupColor = new PdfColor(Color.BlueViolet); + markupAnnotation.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Add this annotation to a new page. + page.Annotations.Add(markupAnnotation); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Importing-annotations-from-FDF-file-to-PDF-document/.NET/Importing-annotations-from-FDF-file-to-PDF-document/Program.cs b/Annotation/Importing-annotations-from-FDF-file-to-PDF-document/.NET/Importing-annotations-from-FDF-file-to-PDF-document/Program.cs index 0b40f523..e4a7ddae 100644 --- a/Annotation/Importing-annotations-from-FDF-file-to-PDF-document/.NET/Importing-annotations-from-FDF-file-to-PDF-document/Program.cs +++ b/Annotation/Importing-annotations-from-FDF-file-to-PDF-document/.NET/Importing-annotations-from-FDF-file-to-PDF-document/Program.cs @@ -1,25 +1,12 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Import annotation data from FDF stream. -FileStream fdfStream = new FileStream(Path.GetFullPath(@"Data/Annotations.fdf"), FileMode.Open, FileAccess.Read); - -//Import annotations from FDF file to PDF document. -loadedDocument.ImportAnnotations(fdfStream, AnnotationDataFormat.Fdf); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Import annotation data from FDF stream + FileStream fdfStream = new FileStream("Annotations.fdf", FileMode.Open, FileAccess.Read); + loadedDocument.ImportAnnotations(fdfStream, AnnotationDataFormat.Fdf); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Annotation/Importing-annotations-from-JSON-file-to-PDF-document/.NET/Importing-annotations-from-JSON-file-to-PDF-document/Program.cs b/Annotation/Importing-annotations-from-JSON-file-to-PDF-document/.NET/Importing-annotations-from-JSON-file-to-PDF-document/Program.cs index 6b9f415d..2ed1c48b 100644 --- a/Annotation/Importing-annotations-from-JSON-file-to-PDF-document/.NET/Importing-annotations-from-JSON-file-to-PDF-document/Program.cs +++ b/Annotation/Importing-annotations-from-JSON-file-to-PDF-document/.NET/Importing-annotations-from-JSON-file-to-PDF-document/Program.cs @@ -1,25 +1,12 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get stream from the JSON file. -FileStream jsonStream = new FileStream(Path.GetFullPath(@"Data/Annotations.Json"), FileMode.Open, FileAccess.Read); - -//Import annotations from JSON file to PDF document. -loadedDocument.ImportAnnotations(jsonStream, AnnotationDataFormat.Json); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Import annotation data from FDF stream + FileStream jsonStream = new FileStream("Annotations.Json", FileMode.Open, FileAccess.Read); + loadedDocument.ImportAnnotations(jsonStream, AnnotationDataFormat.Json); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Importing-annotations-from-XFDF-file-to-PDF-document/.NET/Importing-annotations-from-XFDF-file-to-PDF-document/Program.cs b/Annotation/Importing-annotations-from-XFDF-file-to-PDF-document/.NET/Importing-annotations-from-XFDF-file-to-PDF-document/Program.cs index 5e435697..9eb6a104 100644 --- a/Annotation/Importing-annotations-from-XFDF-file-to-PDF-document/.NET/Importing-annotations-from-XFDF-file-to-PDF-document/Program.cs +++ b/Annotation/Importing-annotations-from-XFDF-file-to-PDF-document/.NET/Importing-annotations-from-XFDF-file-to-PDF-document/Program.cs @@ -1,25 +1,12 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get stream from the XFDF file. -FileStream xfdfStream = new FileStream(Path.GetFullPath(@"Data/Annotations.xfdf"), FileMode.Open, FileAccess.Read); - -//Import annotations from XFDF file to PDF document. -loadedDocument.ImportAnnotations(xfdfStream, AnnotationDataFormat.XFdf); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Import annotation data from FDF stream + FileStream xfdfStream = new FileStream("Annotations.xfdf", FileMode.Open, FileAccess.Read); + loadedDocument.ImportAnnotations(xfdfStream, AnnotationDataFormat.XFdf); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Modify-comments-in-the-existing-PDF-annotation/.NET/Modify-comments-in-the-existing-PDF-annotation/Program.cs b/Annotation/Modify-comments-in-the-existing-PDF-annotation/.NET/Modify-comments-in-the-existing-PDF-annotation/Program.cs index d9a76071..b67e70f0 100644 --- a/Annotation/Modify-comments-in-the-existing-PDF-annotation/.NET/Modify-comments-in-the-existing-PDF-annotation/Program.cs +++ b/Annotation/Modify-comments-in-the-existing-PDF-annotation/.NET/Modify-comments-in-the-existing-PDF-annotation/Program.cs @@ -1,39 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the PDF document page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the annotation collection from PDF page. -PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the PDF document page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Load the rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; + //Get the annotation collection from PDF page. + PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; -//Get the annotation comments collection. -PdfLoadedPopupAnnotationCollection commentsCollection = loadedRectangleAnnotation.Comments; + //Load the rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; -//Get the modified comment. -PdfLoadedPopupAnnotation loadedComments = commentsCollection[0]; + //Get the annotation comments collection. + PdfLoadedPopupAnnotationCollection commentsCollection = loadedRectangleAnnotation.Comments; -//Modify the comment Text. -loadedComments.Text = "This is the modified comments"; + //Get the modified comment. + PdfLoadedPopupAnnotation loadedComments = commentsCollection[0]; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Modify the comment Text. + loadedComments.Text = "This is the modified comments"; -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Modify-review-status-to-the-existing-PDF-annotation/.NET/Modify-review-status-to-the-existing-PDF-annotation/Program.cs b/Annotation/Modify-review-status-to-the-existing-PDF-annotation/.NET/Modify-review-status-to-the-existing-PDF-annotation/Program.cs index ceef6075..d7699019 100644 --- a/Annotation/Modify-review-status-to-the-existing-PDF-annotation/.NET/Modify-review-status-to-the-existing-PDF-annotation/Program.cs +++ b/Annotation/Modify-review-status-to-the-existing-PDF-annotation/.NET/Modify-review-status-to-the-existing-PDF-annotation/Program.cs @@ -1,39 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the existing annotations. -PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; + //Get the existing annotations. + PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; -//Get the annotation review collection. -PdfLoadedPopupAnnotationCollection reviewCollection = loadedRectangleAnnotation.ReviewHistory; + //Get the existing rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; -//Get the modified review state. -PdfLoadedPopupAnnotation loadedReview = reviewCollection[0]; + //Get the annotation review collection. + PdfLoadedPopupAnnotationCollection reviewCollection = loadedRectangleAnnotation.ReviewHistory; -//Modify the review State. -loadedReview.State = PdfAnnotationState.Rejected; + //Get the modified review state. + PdfLoadedPopupAnnotation loadedReview = reviewCollection[0]; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Modify the review State. + loadedReview.State = PdfAnnotationState.Rejected; -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Modify-the-redaction-annotation-in-PDF-document/.NET/Modify-the-redaction-annotation-in-PDF-document/Program.cs b/Annotation/Modify-the-redaction-annotation-in-PDF-document/.NET/Modify-the-redaction-annotation-in-PDF-document/Program.cs index 405f4084..e4a3a329 100644 --- a/Annotation/Modify-the-redaction-annotation-in-PDF-document/.NET/Modify-the-redaction-annotation-in-PDF-document/Program.cs +++ b/Annotation/Modify-the-redaction-annotation-in-PDF-document/.NET/Modify-the-redaction-annotation-in-PDF-document/Program.cs @@ -6,53 +6,45 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -foreach (PdfAnnotation annot in loadedDocument.Pages[0].Annotations) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Check for the Redaction annotation. - if (annot is PdfLoadedRedactionAnnotation) + foreach (PdfAnnotation annot in loadedDocument.Pages[0].Annotations) { - //Load the redaction annotation. - PdfLoadedRedactionAnnotation redactAnnot = annot as PdfLoadedRedactionAnnotation; + //Check for the Redaction annotation. + if (annot is PdfLoadedRedactionAnnotation) + { + //Load the redaction annotation. + PdfLoadedRedactionAnnotation redactAnnot = annot as PdfLoadedRedactionAnnotation; - //Assign the Bounds values. - redactAnnot.Bounds = new RectangleF(50, 50, 100, 100); + //Assign the Bounds values. + redactAnnot.Bounds = new RectangleF(50, 50, 100, 100); - //Assign the OverlayText. - redactAnnot.OverlayText = "Redaction"; + //Assign the OverlayText. + redactAnnot.OverlayText = "Redaction"; - //Assign the InnerColor. - redactAnnot.InnerColor = Color.Yellow; + //Assign the InnerColor. + redactAnnot.InnerColor = Color.Yellow; - //Assign the BorderColor. - redactAnnot.BorderColor = Color.Green; + //Assign the BorderColor. + redactAnnot.BorderColor = Color.Green; - //Assign the TextColor. - redactAnnot.TextColor = Color.Red; + //Assign the TextColor. + redactAnnot.TextColor = Color.Red; - //Assign the TextAlignment. - redactAnnot.TextAlignment = PdfTextAlignment.Right; + //Assign the TextAlignment. + redactAnnot.TextAlignment = PdfTextAlignment.Right; - //Assign the RepeatText. - redactAnnot.RepeatText = true; + //Assign the RepeatText. + redactAnnot.RepeatText = true; - //Flatten the annotations in the page. - redactAnnot.Flatten = true; + //Flatten the annotations in the page. + redactAnnot.Flatten = true; + } } -} -loadedDocument.Redact(); + loadedDocument.Redact(); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); - diff --git a/Annotation/Modifying-annotation-of-existing-PDF-document/.NET/Modifying-annotation-of-existing-PDF-document/Program.cs b/Annotation/Modifying-annotation-of-existing-PDF-document/.NET/Modifying-annotation-of-existing-PDF-document/Program.cs index e971d193..e43e0e04 100644 --- a/Annotation/Modifying-annotation-of-existing-PDF-document/.NET/Modifying-annotation-of-existing-PDF-document/Program.cs +++ b/Annotation/Modifying-annotation-of-existing-PDF-document/.NET/Modifying-annotation-of-existing-PDF-document/Program.cs @@ -1,34 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Gets the first page from the document. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the first page from the document. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Gets the annotation collection. -PdfLoadedAnnotationCollection annotations = loadedPage.Annotations; + //Gets the annotation collection. + PdfLoadedAnnotationCollection annotations = loadedPage.Annotations; -//Gets the first annotation and modify the properties. -PdfLoadedPopupAnnotation popUp = annotations[0] as PdfLoadedPopupAnnotation; -popUp.Border = new PdfAnnotationBorder(4, 0, 0); -popUp.Color = new PdfColor(Color.Red); -popUp.Text = "Modified annotation"; + //Gets the first annotation and modify the properties. + PdfLoadedPopupAnnotation popUp = annotations[0] as PdfLoadedPopupAnnotation; + popUp.Border = new PdfAnnotationBorder(4, 0, 0); + popUp.Color = new PdfColor(Color.Red); + popUp.Text = "Modified annotation"; -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Multi-line-text-redaction-using-quad-points/.NET/Multi-line-text-redaction-using-quad-points/Program.cs b/Annotation/Multi-line-text-redaction-using-quad-points/.NET/Multi-line-text-redaction-using-quad-points/Program.cs index 7596ccfb..45b383d8 100644 --- a/Annotation/Multi-line-text-redaction-using-quad-points/.NET/Multi-line-text-redaction-using-quad-points/Program.cs +++ b/Annotation/Multi-line-text-redaction-using-quad-points/.NET/Multi-line-text-redaction-using-quad-points/Program.cs @@ -4,42 +4,37 @@ using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Create a new page. -PdfPage page = document.Pages.Add(); -//Creates a new Redaction annotation. -PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); - -//set the bounds collection of redaction annotation. -List bounds = new List(); -bounds.Add(new RectangleF(100, 100, 50, 20)); -bounds.Add(new RectangleF(200, 150, 60, 25)); -annot.BoundsCollection = bounds; +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); + //Creates a new Redaction annotation. + PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); -//set the innercolor -annot.InnerColor = Color.Black; -//set the bordercolor -annot.BorderColor = Color.Green; -//set the textcolor -annot.TextColor = Color.Yellow; -//set the font -annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); -//set overlaytext -annot.OverlayText = "Redact"; -//set text alignment -annot.TextAlignment = PdfTextAlignment.Right; -//Assign the RepeatText -annot.RepeatText = true; + //set the bounds collection of redaction annotation. + List bounds = new List(); + bounds.Add(new RectangleF(100, 100, 50, 20)); + bounds.Add(new RectangleF(200, 150, 60, 25)); + annot.BoundsCollection = bounds; -//Add the annotation to the page. -page.Annotations.Add(annot); + //set the innercolor + annot.InnerColor = Color.Black; + //set the bordercolor + annot.BorderColor = Color.Green; + //set the textcolor + annot.TextColor = Color.Yellow; + //set the font + annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); + //set overlaytext + annot.OverlayText = "Redact"; + //set text alignment + annot.TextAlignment = PdfTextAlignment.Right; + //Assign the RepeatText + annot.RepeatText = true; + //Add the annotation to the page. + page.Annotations.Add(annot); -// Save the modified document using a new FileStream -using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) -{ - // Save changes to a new PDF file - document.Save(outputStream); -} -// Close the document and release resources -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Print-annotation-in-the-PDF-document/.NET/Print-annotation-in-the-PDF-document/Program.cs b/Annotation/Print-annotation-in-the-PDF-document/.NET/Print-annotation-in-the-PDF-document/Program.cs index d30eb02f..f207c4b1 100644 --- a/Annotation/Print-annotation-in-the-PDF-document/.NET/Print-annotation-in-the-PDF-document/Program.cs +++ b/Annotation/Print-annotation-in-the-PDF-document/.NET/Print-annotation-in-the-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Creates a new PDF document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -RectangleF rectangle = new RectangleF(40, 60, 80, 20); + RectangleF rectangle = new RectangleF(40, 60, 80, 20); -//Creates a new PDF rubber stamp annotation. -PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Text Rubber Stamp Annotation"); -rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Draft; -rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; + //Creates a new PDF rubber stamp annotation. + PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Text Rubber Stamp Annotation"); + rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Draft; + rubberStampAnnotation.Text = "Text Properties Rubber Stamp Annotation"; -//Set the AnnotationFlags to print. -rubberStampAnnotation.AnnotationFlags = PdfAnnotationFlags.Print; + //Set the AnnotationFlags to print. + rubberStampAnnotation.AnnotationFlags = PdfAnnotationFlags.Print; -//Adds annotation to the page. -page.Annotations.Add(rubberStampAnnotation); + //Adds annotation to the page. + page.Annotations.Add(rubberStampAnnotation); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Remove-commets-from-the-existing-PDF-annotation/.NET/Remove-commets-from-the-existing-PDF-annotation/Program.cs b/Annotation/Remove-commets-from-the-existing-PDF-annotation/.NET/Remove-commets-from-the-existing-PDF-annotation/Program.cs index 04d0b37d..db7bd943 100644 --- a/Annotation/Remove-commets-from-the-existing-PDF-annotation/.NET/Remove-commets-from-the-existing-PDF-annotation/Program.cs +++ b/Annotation/Remove-commets-from-the-existing-PDF-annotation/.NET/Remove-commets-from-the-existing-PDF-annotation/Program.cs @@ -1,36 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing annotations. -PdfLoadedAnnotationCollection annots = loadedPage.Annotations; + //Get the existing annotations. + PdfLoadedAnnotationCollection annots = loadedPage.Annotations; -//Get the existing rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; + //Get the existing rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annots[0] as PdfLoadedRectangleAnnotation; -//Get the annotation comments collection. -PdfLoadedPopupAnnotationCollection commentsCollection = loadedRectangleAnnotation.Comments; + //Get the annotation comments collection. + PdfLoadedPopupAnnotationCollection commentsCollection = loadedRectangleAnnotation.Comments; -//Remove comments by index. -commentsCollection.RemoveAt(0); + //Remove comments by index. + commentsCollection.RemoveAt(0); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Remove-review-status-to-the-existing-PDF-document/.NET/Remove-review-status-to-the-existing-PDF-document/Program.cs b/Annotation/Remove-review-status-to-the-existing-PDF-document/.NET/Remove-review-status-to-the-existing-PDF-document/Program.cs index 4b25cf74..9079d244 100644 --- a/Annotation/Remove-review-status-to-the-existing-PDF-document/.NET/Remove-review-status-to-the-existing-PDF-document/Program.cs +++ b/Annotation/Remove-review-status-to-the-existing-PDF-document/.NET/Remove-review-status-to-the-existing-PDF-document/Program.cs @@ -1,36 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -//Get stream from an existing PDF document. -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the existing annotations. -PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing rectangle annotation. -PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; + //Get the existing annotations. + PdfLoadedAnnotationCollection annotationCollection = loadedPage.Annotations; -//Get the annotation reviewcollection. -PdfLoadedPopupAnnotationCollection reviewCollection = loadedRectangleAnnotation.ReviewHistory; + //Get the existing rectangle annotation. + PdfLoadedRectangleAnnotation loadedRectangleAnnotation = annotationCollection[0] as PdfLoadedRectangleAnnotation; -//Remove review status by index. -reviewCollection.RemoveAt(0); + //Get the annotation reviewcollection. + PdfLoadedPopupAnnotationCollection reviewCollection = loadedRectangleAnnotation.ReviewHistory; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Remove review status by index. + reviewCollection.RemoveAt(0); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Annotation/Removing-annotations-from-an-existing-PDF-document/.NET/Removing-annotations-from-an-existing-PDF-document/Program.cs b/Annotation/Removing-annotations-from-an-existing-PDF-document/.NET/Removing-annotations-from-an-existing-PDF-document/Program.cs index 068c7cb7..c85c0f16 100644 --- a/Annotation/Removing-annotations-from-an-existing-PDF-document/.NET/Removing-annotations-from-an-existing-PDF-document/Program.cs +++ b/Annotation/Removing-annotations-from-an-existing-PDF-document/.NET/Removing-annotations-from-an-existing-PDF-document/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/InputAnnotation.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Gets the first page of the document. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the first page of the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Gets the annotation collection. -PdfLoadedAnnotationCollection annotations = page.Annotations; + //Gets the annotation collection. + PdfLoadedAnnotationCollection annotations = page.Annotations; -//Removes the first annotation. -annotations.RemoveAt(0); + //Removes the first annotation. + annotations.RemoveAt(0); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Annotation/Removing-the-sensitive-text-and-images-from-PDF-document/.NET/Removing-the-sensitive-text-and-images-from-PDF-document/Program.cs b/Annotation/Removing-the-sensitive-text-and-images-from-PDF-document/.NET/Removing-the-sensitive-text-and-images-from-PDF-document/Program.cs index c5ad5be6..800970e9 100644 --- a/Annotation/Removing-the-sensitive-text-and-images-from-PDF-document/.NET/Removing-the-sensitive-text-and-images-from-PDF-document/Program.cs +++ b/Annotation/Removing-the-sensitive-text-and-images-from-PDF-document/.NET/Removing-the-sensitive-text-and-images-from-PDF-document/Program.cs @@ -1,53 +1,45 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Create a new Redaction annotation. -PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); + //Create a new Redaction annotation. + PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); -//Assign the Bounds value. -annot.Bounds = new Rectangle(100, 120, 100, 100); + //Assign the Bounds value. + annot.Bounds = new Rectangle(100, 120, 100, 100); -//Assign the InnerColor. -annot.InnerColor = Color.Black; + //Assign the InnerColor. + annot.InnerColor = Color.Black; -//Assign the Bordercolor. -annot.BorderColor = Color.Yellow; + //Assign the Bordercolor. + annot.BorderColor = Color.Yellow; -//Assign the Textcolor. -annot.TextColor = Color.Blue; + //Assign the Textcolor. + annot.TextColor = Color.Blue; -//Assign the font. -annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); + //Assign the font. + annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); -//Assign the OverlayText. -annot.OverlayText = "REDACTION"; + //Assign the OverlayText. + annot.OverlayText = "REDACTION"; -//Assign the TextAlignment. -annot.TextAlignment = PdfTextAlignment.Right; + //Assign the TextAlignment. + annot.TextAlignment = PdfTextAlignment.Right; -//Assign the RepeatText. -annot.RepeatText = true; -annot.SetAppearance(true); + //Assign the RepeatText. + annot.RepeatText = true; + annot.SetAppearance(true); -//Add the annotation to the page. -page.Annotations.Add(annot); + //Add the annotation to the page. + page.Annotations.Add(annot); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Annotation/Retrieve-review-status-from-the-existing-PDF-annotations/.NET/Program.cs b/Annotation/Retrieve-review-status-from-the-existing-PDF-annotations/.NET/Program.cs index 635a9cb3..839f0d5c 100644 --- a/Annotation/Retrieve-review-status-from-the-existing-PDF-annotations/.NET/Program.cs +++ b/Annotation/Retrieve-review-status-from-the-existing-PDF-annotations/.NET/Program.cs @@ -1,36 +1,29 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the existing PDF page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the annotation. -PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation; - -//Get the review history collection for the annotation. -PdfLoadedPopupAnnotationCollection reviewCollection = rectangleAnnotation.ReviewHistory; - -//Iterate through the review history collection. -foreach (PdfLoadedPopupAnnotation review in reviewCollection) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Get the author of the annotation. - string author = review.Author; - //Get the state of the annotation. - PdfAnnotationState state = review.State; - //Get the state model of the annotation. - PdfAnnotationStateModel model = review.StateModel; - - Console.WriteLine("Author of the reviewer: " + author + "\r\nState: " + state + "\r\nState Model: " + model); + //Get the existing PDF page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + + //Get the annotation. + PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation; + + //Get the review history collection for the annotation. + PdfLoadedPopupAnnotationCollection reviewCollection = rectangleAnnotation.ReviewHistory; + + //Iterate through the review history collection. + foreach (PdfLoadedPopupAnnotation review in reviewCollection) + { + //Get the author of the annotation. + string author = review.Author; + //Get the state of the annotation. + PdfAnnotationState state = review.State; + //Get the state model of the annotation. + PdfAnnotationStateModel model = review.StateModel; + + Console.WriteLine("Author of the reviewer: " + author + "\r\nState: " + state + "\r\nState Model: " + model); + } } - -//Closes the document. -loadedDocument.Close(true); diff --git a/Annotation/Retrieve-the-annotation-comments-from-the-existing-PDF/.NET/Program.cs b/Annotation/Retrieve-the-annotation-comments-from-the-existing-PDF/.NET/Program.cs index 4c786a00..8b39fa41 100644 --- a/Annotation/Retrieve-the-annotation-comments-from-the-existing-PDF/.NET/Program.cs +++ b/Annotation/Retrieve-the-annotation-comments-from-the-existing-PDF/.NET/Program.cs @@ -1,34 +1,30 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from the existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Get the existing PDF page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Get the annotation. + PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation; -//Get the annotation. -PdfLoadedRectangleAnnotation rectangleAnnotation = loadedPage.Annotations[0] as PdfLoadedRectangleAnnotation; + //Get the comments of the annotation. + PdfLoadedPopupAnnotationCollection commentsCollection = rectangleAnnotation.Comments; -//Get the comments of the annotation. -PdfLoadedPopupAnnotationCollection commentsCollection = rectangleAnnotation.Comments; + //Iterate through the comments collection. + foreach (PdfLoadedPopupAnnotation comment in commentsCollection) + { + //Get the author of the comment. + string author = comment.Author; + //Get the content + string content = comment.Text; -//Iterate through the comments collection. -foreach (PdfLoadedPopupAnnotation comment in commentsCollection) -{ - //Get the author of the comment. - string author = comment.Author; - //Get the content - string content = comment.Text; + Console.WriteLine("Author of the comment: " + author + "\r\nContent: " + content); + } - Console.WriteLine("Author of the comment: " + author + "\r\nContent: " + content); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Closes the document. -loadedDocument.Close(true); diff --git a/Annotation/Set-text-alignment-in-a-Combo-Box-field/.NET/Set-text-alignment-in-a-Combo-Box-field/Program.cs b/Annotation/Set-text-alignment-in-a-Combo-Box-field/.NET/Set-text-alignment-in-a-Combo-Box-field/Program.cs index b23e8bf0..b7e8fbeb 100644 --- a/Annotation/Set-text-alignment-in-a-Combo-Box-field/.NET/Set-text-alignment-in-a-Combo-Box-field/Program.cs +++ b/Annotation/Set-text-alignment-in-a-Combo-Box-field/.NET/Set-text-alignment-in-a-Combo-Box-field/Program.cs @@ -1,20 +1,14 @@ using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -// Load an existing document from a file stream. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - PdfLoadedDocument doc = new PdfLoadedDocument(fileStream); // Load an existing combo box field by its name. - PdfLoadedComboBoxField comboField = doc.Form.Fields["JobTitle"] as PdfLoadedComboBoxField; + PdfLoadedComboBoxField comboField = loadedDocument.Form.Fields["JobTitle"] as PdfLoadedComboBoxField; // Set text alignment to center for the combo box field. comboField.TextAlignment = PdfTextAlignment.Center; - // Save the updated document to a file stream. - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - doc.Save(outputStream); - } - // Close the document. - doc.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Annotation/Set-value-from-PDF-annotation/.NET/Set-value-from-PDF-annotation/Program.cs b/Annotation/Set-value-from-PDF-annotation/.NET/Set-value-from-PDF-annotation/Program.cs index 0b3afbfc..13443a4b 100644 --- a/Annotation/Set-value-from-PDF-annotation/.NET/Set-value-from-PDF-annotation/Program.cs +++ b/Annotation/Set-value-from-PDF-annotation/.NET/Set-value-from-PDF-annotation/Program.cs @@ -3,32 +3,21 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -// Load the existing PDF document using FileStream -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the PDF document from the input stream - using (PdfLoadedDocument ldoc = new PdfLoadedDocument(inputStream)) - { - // Access the first page of the document - PdfLoadedPage page = ldoc.Pages[0] as PdfLoadedPage; - - // Get the collection of annotations from the page - PdfLoadedAnnotationCollection annotations = page.Annotations; + // Access the first page of the document + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - // Check if at least one annotation exists and it's a popup annotation - if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation) - { - // Set a custom key-value pair in the annotation's metadata - annotation.SetValues("custom", "This is the custom data for the annotation"); - } + // Get the collection of annotations from the page + PdfLoadedAnnotationCollection annotations = page.Annotations; - // Save the modified document using a new FileStream - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - // Save changes to a new PDF file - ldoc.Save(outputStream); - } - // Close the document and release resources - ldoc.Close(true); + // Check if at least one annotation exists and it's a popup annotation + if (annotations.Count > 0 && annotations[0] is PdfLoadedPopupAnnotation annotation) + { + // Set a custom key-value pair in the annotation's metadata + annotation.SetValues("custom", "This is the custom data for the annotation"); } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs index e93745e7..539ad82e 100644 --- a/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs +++ b/Attachment/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/.NET/Adding-PDF-Attachments-with-Interactive-Launch-Buttons/Program.cs @@ -5,12 +5,9 @@ using Syncfusion.Drawing; using System.Reflection.Metadata; -//Create FileStream object to read the input PDF file -using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the existing PDF file - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - // Get the first page of the PDF PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -46,13 +43,6 @@ // Set default appearance for form fields loadedDocument.Form.SetDefaultAppearance(false); - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - - //Close the document. - loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } diff --git a/Attachment/Adding-attachment-to-a-PDF-document/.NET/Adding-attachment-to-a-PDF-document/Program.cs b/Attachment/Adding-attachment-to-a-PDF-document/.NET/Adding-attachment-to-a-PDF-document/Program.cs index a851473d..5956aab5 100644 --- a/Attachment/Adding-attachment-to-a-PDF-document/.NET/Adding-attachment-to-a-PDF-document/Program.cs +++ b/Attachment/Adding-attachment-to-a-PDF-document/.NET/Adding-attachment-to-a-PDF-document/Program.cs @@ -1,29 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Get stream from an existing PDF document. -Stream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.txt"), FileMode.Open, FileAccess.Read); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Get stream from an existing PDF document. + Stream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.txt"), FileMode.Open, FileAccess.Read); -//Creates an attachment with properties. -PdfAttachment attachment = new PdfAttachment("Input.txt", fileStream); -attachment.ModificationDate = DateTime.Now; -attachment.Description = "Input.txt"; -attachment.MimeType = "application/txt"; + //Creates an attachment with properties. + PdfAttachment attachment = new PdfAttachment("Input.txt", fileStream); + attachment.ModificationDate = DateTime.Now; + attachment.Description = "Input.txt"; + attachment.MimeType = "application/txt"; -//Adds the attachment to the document. -document.Attachments.Add(attachment); + //Adds the attachment to the document. + document.Attachments.Add(attachment); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Attachment/Adding-the-attachments-to-an-existing-PDF-document/.NET/Adding-the-attachments-to-an-existing-PDF-document/Program.cs b/Attachment/Adding-the-attachments-to-an-existing-PDF-document/.NET/Adding-the-attachments-to-an-existing-PDF-document/Program.cs index f0b8efa9..603e00a9 100644 --- a/Attachment/Adding-the-attachments-to-an-existing-PDF-document/.NET/Adding-the-attachments-to-an-existing-PDF-document/Program.cs +++ b/Attachment/Adding-the-attachments-to-an-existing-PDF-document/.NET/Adding-the-attachments-to-an-existing-PDF-document/Program.cs @@ -1,36 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get stream from the text file. -Stream fileStream = new FileStream(Path.GetFullPath("Data/Input.txt"), FileMode.Open, FileAccess.Read); - -//Creates an attachment. -PdfAttachment attachment = new PdfAttachment("Input.txt", fileStream); -attachment.ModificationDate = DateTime.Now; -attachment.Description = "Input.txt"; -attachment.MimeType = "application/txt"; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get stream from the text file. + Stream fileStream = new FileStream(Path.GetFullPath("Data/Input.txt"), FileMode.Open, FileAccess.Read); -//Create attachment. -if (loadedDocument.Attachments == null) - loadedDocument.CreateAttachment(); + //Creates an attachment. + PdfAttachment attachment = new PdfAttachment("Input.txt", fileStream); + attachment.ModificationDate = DateTime.Now; + attachment.Description = "Input.txt"; + attachment.MimeType = "application/txt"; -//Add the attachment to the document. -loadedDocument.Attachments.Add(attachment); + //Create attachment. + if (loadedDocument.Attachments == null) + loadedDocument.CreateAttachment(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Add the attachment to the document. + loadedDocument.Attachments.Add(attachment); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Attachment/Extract-and-saving-an-attachment-to-the-disk/.NET/Extract-and-saving-an-attachment-to-the-disk/Program.cs b/Attachment/Extract-and-saving-an-attachment-to-the-disk/.NET/Extract-and-saving-an-attachment-to-the-disk/Program.cs index abe4c6f4..dc5f4f63 100644 --- a/Attachment/Extract-and-saving-an-attachment-to-the-disk/.NET/Extract-and-saving-an-attachment-to-the-disk/Program.cs +++ b/Attachment/Extract-and-saving-an-attachment-to-the-disk/.NET/Extract-and-saving-an-attachment-to-the-disk/Program.cs @@ -1,22 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from the existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Iterates the attachments. -foreach (PdfAttachment attachment in document.Attachments) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Extracts the attachment and saves it to the disk. - FileStream s = new FileStream(Path.GetFullPath(@"Output/"+ attachment.FileName), FileMode.Create); - s.Write(attachment.Data, 0, attachment.Data.Length); - s.Dispose(); -} + //Iterates the attachments. + foreach (PdfAttachment attachment in loadedDocument.Attachments) + { + //Extracts the attachment and saves it to the disk. + FileStream s = new FileStream(Path.GetFullPath(@"Output/" + attachment.FileName), FileMode.Create); + s.Write(attachment.Data, 0, attachment.Data.Length); + s.Dispose(); + } -//Close the document. -document.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Attachment/Remove-attachment-from-an-existing-PDF-document/.NET/Remove-attachment-from-an-existing-PDF-document/Program.cs b/Attachment/Remove-attachment-from-an-existing-PDF-document/.NET/Remove-attachment-from-an-existing-PDF-document/Program.cs index 23de8c7c..613e4f6e 100644 --- a/Attachment/Remove-attachment-from-an-existing-PDF-document/.NET/Remove-attachment-from-an-existing-PDF-document/Program.cs +++ b/Attachment/Remove-attachment-from-an-existing-PDF-document/.NET/Remove-attachment-from-an-existing-PDF-document/Program.cs @@ -1,25 +1,14 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from the existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Removes an attachment. -loadedDocument.Attachments.RemoveAt(0); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Removes an attachment. + loadedDocument.Attachments.RemoveAt(0); -//PdfAttachment attachment = document.Attachments[0]; -//document.Attachments.Remove(attachment); + //PdfAttachment attachment = document.Attachments[0]; + //document.Attachments.Remove(attachment); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Barcode/Add-a-barcode-to-the-PDF-document-without-displaying-text/.NET/Program.cs b/Barcode/Add-a-barcode-to-the-PDF-document-without-displaying-text/.NET/Program.cs index 91adf22b..162ee81f 100644 --- a/Barcode/Add-a-barcode-to-the-PDF-document-without-displaying-text/.NET/Program.cs +++ b/Barcode/Add-a-barcode-to-the-PDF-document-without-displaying-text/.NET/Program.cs @@ -1,38 +1,30 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; -//Creating new PDF Document. -PdfDocument document = new PdfDocument(); - -//Adding a new page to the PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding a new page to the PDF document. + PdfPage page = document.Pages.Add(); -//Create a new instance for the Codabar barcode. -PdfCode39Barcode barcode = new PdfCode39Barcode(); + //Create a new instance for the Codabar barcode. + PdfCode39Barcode barcode = new PdfCode39Barcode(); -//Set the barcode location. -barcode.Location = new PointF(10, 10); + //Set the barcode location. + barcode.Location = new PointF(10, 10); -//Set the barcode text. -barcode.Text = "123456789"; + //Set the barcode text. + barcode.Text = "123456789"; -//Disable the barcode text. -barcode.TextDisplayLocation = TextLocation.None; + //Disable the barcode text. + barcode.TextDisplayLocation = TextLocation.None; -//Printing barcode on to the PDF document. -barcode.Draw(page); + //Printing barcode on to the PDF document. + barcode.Draw(page); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Barcode/Adding-quiet-zones-to-a-barcode/.NET/Adding-quiet-zones-to-a-barcode/Program.cs b/Barcode/Adding-quiet-zones-to-a-barcode/.NET/Adding-quiet-zones-to-a-barcode/Program.cs index 4f5baa2f..9fdf1b76 100644 --- a/Barcode/Adding-quiet-zones-to-a-barcode/.NET/Adding-quiet-zones-to-a-barcode/Program.cs +++ b/Barcode/Adding-quiet-zones-to-a-barcode/.NET/Adding-quiet-zones-to-a-barcode/Program.cs @@ -4,37 +4,31 @@ using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create a new page. -PdfPage page = document.Pages.Add(); - -// Create barcode with quiet zones -PdfCode128Barcode barcode = new PdfCode128Barcode +using (PdfDocument document = new PdfDocument()) { - Text = "SYNCFUSION", - BarHeight = 40, - QuietZone = new PdfBarcodeQuietZones - { - Left = 15, // 15 points = ~5.3mm - Right = 15, - Top = 8, // 8 points = ~2.8mm - Bottom = 8 - } -}; + //Create a new page. + PdfPage page = document.Pages.Add(); -//Draw a barcode on the new page. -barcode.Draw(page, new PointF(10, 10)); + // Create barcode with quiet zones + PdfCode128Barcode barcode = new PdfCode128Barcode + { + Text = "SYNCFUSION", + BarHeight = 40, + QuietZone = new PdfBarcodeQuietZones + { + Left = 15, // 15 points = ~5.3mm + Right = 15, + Top = 8, // 8 points = ~2.8mm + Bottom = 8 + } + }; -//Draw a rectangle based on the barcode size. -page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, barcode.Size.Width, barcode.Size.Height)); + //Draw a barcode on the new page. + barcode.Draw(page, new PointF(10, 10)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Draw a rectangle based on the barcode size. + page.Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, barcode.Size.Width, barcode.Size.Height)); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Barcode/Export-one-dimensional-barcode-as-image/.NET/Export-one-dimensional-barcode-as-image/Program.cs b/Barcode/Export-one-dimensional-barcode-as-image/.NET/Export-one-dimensional-barcode-as-image/Program.cs index 470b5ff6..fe931184 100644 --- a/Barcode/Export-one-dimensional-barcode-as-image/.NET/Export-one-dimensional-barcode-as-image/Program.cs +++ b/Barcode/Export-one-dimensional-barcode-as-image/.NET/Export-one-dimensional-barcode-as-image/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Barcode; +using Syncfusion.Pdf.Barcode; using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; diff --git a/Barcode/Export-two-dimensional-barcode-as-image/.NET/Export-two-dimensional-barcode-as-image/Program.cs b/Barcode/Export-two-dimensional-barcode-as-image/.NET/Export-two-dimensional-barcode-as-image/Program.cs index cf85efee..534dcabb 100644 --- a/Barcode/Export-two-dimensional-barcode-as-image/.NET/Export-two-dimensional-barcode-as-image/Program.cs +++ b/Barcode/Export-two-dimensional-barcode-as-image/.NET/Export-two-dimensional-barcode-as-image/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Barcode; +using Syncfusion.Pdf.Barcode; using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; diff --git a/Barcode/One dimensional barcode/Add-Code39-barcode-to-the-PDF-document/.NET/Add-Code39-barcode-to-the-PDF-document/Program.cs b/Barcode/One dimensional barcode/Add-Code39-barcode-to-the-PDF-document/.NET/Add-Code39-barcode-to-the-PDF-document/Program.cs index b6bc67fd..1d1e0091 100644 --- a/Barcode/One dimensional barcode/Add-Code39-barcode-to-the-PDF-document/.NET/Add-Code39-barcode-to-the-PDF-document/Program.cs +++ b/Barcode/One dimensional barcode/Add-Code39-barcode-to-the-PDF-document/.NET/Add-Code39-barcode-to-the-PDF-document/Program.cs @@ -1,34 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; -//Creating new PDF Document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Drawing Code39 barcode. -PdfCode39Barcode barcode = new PdfCode39Barcode(); + //Drawing Code39 barcode. + PdfCode39Barcode barcode = new PdfCode39Barcode(); -//Setting height of the barcode. -barcode.BarHeight = 45; + //Setting height of the barcode. + barcode.BarHeight = 45; -//Set barcode text. -barcode.Text = "CODE39$"; + //Set barcode text. + barcode.Text = "CODE39$"; -//Printing barcode on to the Pdf. -barcode.Draw(page, new PointF(25, 70)); + //Printing barcode on to the Pdf. + barcode.Draw(page, new PointF(25, 70)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); - diff --git a/Barcode/One dimensional barcode/Add-PdfEan13-barcode-to-a-PDF-document/.NET/Add-PdfEan13-barcode-to-a-PDF-document/Program.cs b/Barcode/One dimensional barcode/Add-PdfEan13-barcode-to-a-PDF-document/.NET/Add-PdfEan13-barcode-to-a-PDF-document/Program.cs index cd4a908d..81673b74 100644 --- a/Barcode/One dimensional barcode/Add-PdfEan13-barcode-to-a-PDF-document/.NET/Add-PdfEan13-barcode-to-a-PDF-document/Program.cs +++ b/Barcode/One dimensional barcode/Add-PdfEan13-barcode-to-a-PDF-document/.NET/Add-PdfEan13-barcode-to-a-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; @@ -13,21 +11,15 @@ //Set the barcode text. barcode.Text = "400638133393"; -//Creating new PDF document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Printing barcode on to the PDF document. -barcode.Draw(page, new PointF(25, 70)); + //Printing barcode on to the PDF document. + barcode.Draw(page, new PointF(25, 70)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Barcode/One dimensional barcode/Add-PdfEan8-barcode-to-a-PDF-document/.NET/Add-PdfEan8-barcode-to-a-PDF-document/Program.cs b/Barcode/One dimensional barcode/Add-PdfEan8-barcode-to-a-PDF-document/.NET/Add-PdfEan8-barcode-to-a-PDF-document/Program.cs index 2b5da890..d1882b71 100644 --- a/Barcode/One dimensional barcode/Add-PdfEan8-barcode-to-a-PDF-document/.NET/Add-PdfEan8-barcode-to-a-PDF-document/Program.cs +++ b/Barcode/One dimensional barcode/Add-PdfEan8-barcode-to-a-PDF-document/.NET/Add-PdfEan8-barcode-to-a-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; @@ -13,22 +11,16 @@ //Set the barcode text. barcode.Text = "1234567"; -//Creating new PDF document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Printing barcode on to the PDF. -barcode.Draw(page, new PointF(25, 70)); + //Printing barcode on to the PDF. + barcode.Draw(page, new PointF(25, 70)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Barcode/Set-location-and-size-to-the-barcode-in-a-PDF-document/.NET/Set-location-and-size-to-the-barcode-in-a-PDF-document/Program.cs b/Barcode/Set-location-and-size-to-the-barcode-in-a-PDF-document/.NET/Set-location-and-size-to-the-barcode-in-a-PDF-document/Program.cs index 9cf006d6..9fb506dd 100644 --- a/Barcode/Set-location-and-size-to-the-barcode-in-a-PDF-document/.NET/Set-location-and-size-to-the-barcode-in-a-PDF-document/Program.cs +++ b/Barcode/Set-location-and-size-to-the-barcode-in-a-PDF-document/.NET/Set-location-and-size-to-the-barcode-in-a-PDF-document/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; -//Creating new PDF Document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); - -//Create new instance for Codabar barcode. -PdfCodabarBarcode barcode = new PdfCodabarBarcode(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Setting location of the barcode. -barcode.Location = new PointF(100, 100); + //Create new instance for Codabar barcode. + PdfCodabarBarcode barcode = new PdfCodabarBarcode(); -//Setting size of the barcode. -barcode.Size = new SizeF(200, 100); -barcode.Text = "123456789$"; + //Setting location of the barcode. + barcode.Location = new PointF(100, 100); -//Printing barcode on to the PDF document. -barcode.Draw(page); + //Setting size of the barcode. + barcode.Size = new SizeF(200, 100); + barcode.Text = "123456789$"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Printing barcode on to the PDF document. + barcode.Draw(page); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Barcode/Two dimensional barcode/Add-a-Pdf417-barcode-to-the-PDF-document/.NET/Add-a-Pdf417-barcode-to-the-PDF-document/Program.cs b/Barcode/Two dimensional barcode/Add-a-Pdf417-barcode-to-the-PDF-document/.NET/Add-a-Pdf417-barcode-to-the-PDF-document/Program.cs index 992fadfb..6b82655f 100644 --- a/Barcode/Two dimensional barcode/Add-a-Pdf417-barcode-to-the-PDF-document/.NET/Add-a-Pdf417-barcode-to-the-PDF-document/Program.cs +++ b/Barcode/Two dimensional barcode/Add-a-Pdf417-barcode-to-the-PDF-document/.NET/Add-a-Pdf417-barcode-to-the-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; @@ -16,23 +14,17 @@ //Set the barcode text. barcode.Text = "http://www.syncfusion.com"; -//Creating new PDF document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Printing barcode on to the PDF. -barcode.Draw(page, new PointF(25, 70)); + //Printing barcode on to the PDF. + barcode.Draw(page, new PointF(25, 70)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Barcode/Two dimensional barcode/Add-a-QRBarcode-to-the-PDF-document/.NET/Add-a-QRBarcode-to-the-PDF-document/Program.cs b/Barcode/Two dimensional barcode/Add-a-QRBarcode-to-the-PDF-document/.NET/Add-a-QRBarcode-to-the-PDF-document/Program.cs index e2474f9c..41926304 100644 --- a/Barcode/Two dimensional barcode/Add-a-QRBarcode-to-the-PDF-document/.NET/Add-a-QRBarcode-to-the-PDF-document/Program.cs +++ b/Barcode/Two dimensional barcode/Add-a-QRBarcode-to-the-PDF-document/.NET/Add-a-QRBarcode-to-the-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Barcode; @@ -16,21 +14,15 @@ //Set the barcode text. barcode.Text = "http://www.syncfusion.com"; -//Creating a new PDF Document. -PdfDocument document = new PdfDocument(); - -//Adding new page to PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adding new page to PDF document. + PdfPage page = document.Pages.Add(); -//Printing barcode on to the Pdf. -barcode.Draw(page, new PointF(25, 70)); + //Printing barcode on to the Pdf. + barcode.Draw(page, new PointF(25, 70)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Bookmarks/Adding-a-child-to-the-bookmarks-in-a-PDF/.NET/Adding-a-child-to-the-bookmarks-in-a-PDF/Program.cs b/Bookmarks/Adding-a-child-to-the-bookmarks-in-a-PDF/.NET/Adding-a-child-to-the-bookmarks-in-a-PDF/Program.cs index f197c0a5..49441dd4 100644 --- a/Bookmarks/Adding-a-child-to-the-bookmarks-in-a-PDF/.NET/Adding-a-child-to-the-bookmarks-in-a-PDF/Program.cs +++ b/Bookmarks/Adding-a-child-to-the-bookmarks-in-a-PDF/.NET/Adding-a-child-to-the-bookmarks-in-a-PDF/Program.cs @@ -1,48 +1,40 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new document. -PdfDocument document = new PdfDocument(); - -//Adds a page. -PdfPage page = document.Pages.Add(); - -//Creates bookmark. -PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adds a page. + PdfPage page = document.Pages.Add(); -//Sets the destination page. -bookmark.Destination = new PdfDestination(page); + //Creates bookmark. + PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); -//Sets the destination location. -bookmark.Destination.Location = new PointF(20, 20); + //Sets the destination page. + bookmark.Destination = new PdfDestination(page); -//Adds the child bookmark. -PdfBookmark childBookmark = bookmark.Insert(0, "heading 1"); -childBookmark.Destination = new PdfDestination(page); -childBookmark.Destination.Location = new PointF(200, 300); -childBookmark.Destination.Zoom = 2F; + //Sets the destination location. + bookmark.Destination.Location = new PointF(20, 20); -//Sets the text style and color. -bookmark.TextStyle = PdfTextStyle.Bold; -bookmark.Color = Syncfusion.Drawing.Color.Red; + //Adds the child bookmark. + PdfBookmark childBookmark = bookmark.Insert(0, "heading 1"); + childBookmark.Destination = new PdfDestination(page); + childBookmark.Destination.Location = new PointF(200, 300); + childBookmark.Destination.Zoom = 2F; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Sets the text style and color. + bookmark.TextStyle = PdfTextStyle.Bold; + bookmark.Color = Syncfusion.Drawing.Color.Red; -//Draw text in the PDF page. -page.Graphics.DrawString("Parent Bookmark", font, PdfBrushes.Red, new PointF(20,20)); -page.Graphics.DrawString("Child Bookmark", font, PdfBrushes.DarkSeaGreen, new PointF(200,300)); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Draw text in the PDF page. + page.Graphics.DrawString("Parent Bookmark", font, PdfBrushes.Red, new PointF(20, 20)); + page.Graphics.DrawString("Child Bookmark", font, PdfBrushes.DarkSeaGreen, new PointF(200, 300)); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Bookmarks/Adding-bookmarks-in-a-PDF-document/.NET/Adding-bookmarks-in-a-PDF-document/Program.cs b/Bookmarks/Adding-bookmarks-in-a-PDF-document/.NET/Adding-bookmarks-in-a-PDF-document/Program.cs index bdc84059..e8b9e07c 100644 --- a/Bookmarks/Adding-bookmarks-in-a-PDF-document/.NET/Adding-bookmarks-in-a-PDF-document/Program.cs +++ b/Bookmarks/Adding-bookmarks-in-a-PDF-document/.NET/Adding-bookmarks-in-a-PDF-document/Program.cs @@ -1,41 +1,33 @@ -// See https://aka.ms/new-console-template for more information. - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; -//Creates a new document. -PdfDocument document = new PdfDocument(); - -//Adds a page. -PdfPage page = document.Pages.Add(); - -//Creates document bookmarks. -PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adds a page. + PdfPage page = document.Pages.Add(); -//Sets the destination page. -bookmark.Destination = new PdfDestination(page); + //Creates document bookmarks. + PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); -//Sets the destination location. -bookmark.Destination.Location = new PointF(20, 20); + //Sets the destination page. + bookmark.Destination = new PdfDestination(page); -//Sets the text style and color. -bookmark.TextStyle = PdfTextStyle.Bold; -bookmark.Color = Syncfusion.Drawing.Color.Red; + //Sets the destination location. + bookmark.Destination.Location = new PointF(20, 20); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Sets the text style and color. + bookmark.TextStyle = PdfTextStyle.Bold; + bookmark.Color = Syncfusion.Drawing.Color.Red; -//Draw string in the first page with bookmark destination location. -page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(20,20)); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Draw string in the first page with bookmark destination location. + page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(20, 20)); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Bookmarks/Adding-bookmarks-in-an-existing-PDF-document/.NET/Adding-bookmarks-in-an-existing-PDF-document/Program.cs b/Bookmarks/Adding-bookmarks-in-an-existing-PDF-document/.NET/Adding-bookmarks-in-an-existing-PDF-document/Program.cs index 9ef5f1ba..56c17768 100644 --- a/Bookmarks/Adding-bookmarks-in-an-existing-PDF-document/.NET/Adding-bookmarks-in-an-existing-PDF-document/Program.cs +++ b/Bookmarks/Adding-bookmarks-in-an-existing-PDF-document/.NET/Adding-bookmarks-in-an-existing-PDF-document/Program.cs @@ -1,34 +1,23 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Creates document bookmarks. -PdfBookmark bookmark = document.Bookmarks.Add("Page 1"); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Creates document bookmarks. + PdfBookmark bookmark = loadedDocument.Bookmarks.Add("Page 1"); -//Sets the destination page. -bookmark.Destination = new PdfDestination(document.Pages[0]); + //Sets the destination page. + bookmark.Destination = new PdfDestination(loadedDocument.Pages[0]); -//Sets the text style and color. -bookmark.TextStyle = PdfTextStyle.Bold; -bookmark.Color = Color.Red; + //Sets the text style and color. + bookmark.TextStyle = PdfTextStyle.Bold; + bookmark.Color = Color.Red; -//Sets the destination location. -bookmark.Destination.Location = new PointF(20, 20); + //Sets the destination location. + bookmark.Destination.Location = new PointF(20, 20); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Bookmarks/Get-bookmark-page-index-from-the-existing-PDF-document/.NET/Get-bookmark-page-index-from-the-existing-PDF-document/Program.cs b/Bookmarks/Get-bookmark-page-index-from-the-existing-PDF-document/.NET/Get-bookmark-page-index-from-the-existing-PDF-document/Program.cs index e2be74f0..8a4ad3e7 100644 --- a/Bookmarks/Get-bookmark-page-index-from-the-existing-PDF-document/.NET/Get-bookmark-page-index-from-the-existing-PDF-document/Program.cs +++ b/Bookmarks/Get-bookmark-page-index-from-the-existing-PDF-document/.NET/Get-bookmark-page-index-from-the-existing-PDF-document/Program.cs @@ -1,26 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets all the bookmarks. + PdfBookmarkBase bookmark = loadedDocument.Bookmarks; -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); + //Get the bookmark page index. + int pageIndex = bookmark[1].Destination.PageIndex; -//Gets all the bookmarks. -PdfBookmarkBase bookmark = loadedDocument.Bookmarks; + //Write the page index of the bookmark in console window. + Console.WriteLine("Page index of bookmark[1]: " + pageIndex); -//Get the bookmark page index. -int pageIndex = bookmark[1].Destination.PageIndex; - -//Close the document. -loadedDocument.Close(true); - -//Write the page index of the bookmark in console window. -Console.WriteLine("Page index of bookmark[1]: " + pageIndex); -Console.ReadLine(); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Bookmarks/Inserting-bookmarks-in-an-existing-PDF/.NET/Inserting-bookmarks-in-an-existing-PDF/Program.cs b/Bookmarks/Inserting-bookmarks-in-an-existing-PDF/.NET/Inserting-bookmarks-in-an-existing-PDF/Program.cs index c5301a8a..fe9d1d70 100644 --- a/Bookmarks/Inserting-bookmarks-in-an-existing-PDF/.NET/Inserting-bookmarks-in-an-existing-PDF/Program.cs +++ b/Bookmarks/Inserting-bookmarks-in-an-existing-PDF/.NET/Inserting-bookmarks-in-an-existing-PDF/Program.cs @@ -1,28 +1,17 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Inserts a new bookmark in the existing bookmark collection. -PdfBookmark bookmark = document.Bookmarks.Insert(1, "New Page 2"); - -//Sets the destination page and location. -bookmark.Destination = new PdfDestination(document.Pages[1]); -bookmark.Destination.Location = new PointF(0, 300); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Inserts a new bookmark in the existing bookmark collection. + PdfBookmark bookmark = loadedDocument.Bookmarks.Insert(1, "New Page 2"); + + //Sets the destination page and location. + bookmark.Destination = new PdfDestination(loadedDocument.Pages[1]); + bookmark.Destination.Location = new PointF(0, 300); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Bookmarks/Modify-the-bookmarks-in-an-existing-PDF-document/.NET/Modify-the-bookmarks-in-an-existing-PDF-document/Program.cs b/Bookmarks/Modify-the-bookmarks-in-an-existing-PDF-document/.NET/Modify-the-bookmarks-in-an-existing-PDF-document/Program.cs index 9a6a51bf..a8b3258f 100644 --- a/Bookmarks/Modify-the-bookmarks-in-an-existing-PDF-document/.NET/Modify-the-bookmarks-in-an-existing-PDF-document/Program.cs +++ b/Bookmarks/Modify-the-bookmarks-in-an-existing-PDF-document/.NET/Modify-the-bookmarks-in-an-existing-PDF-document/Program.cs @@ -1,32 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Gets all the bookmarks. -PdfBookmarkBase bookmarks = document.Bookmarks; - -//Gets the first bookmark and changes the properties of the bookmark. -PdfLoadedBookmark bookmark = bookmarks[0] as PdfLoadedBookmark; -bookmark.Destination = new PdfDestination(document.Pages[0]); -bookmark.Color = Syncfusion.Drawing.Color.Green; -bookmark.TextStyle = PdfTextStyle.Bold; -bookmark.Title = "Changed title"; - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Gets all the bookmarks. + PdfBookmarkBase bookmarks = loadedDocument.Bookmarks; + + //Gets the first bookmark and changes the properties of the bookmark. + PdfLoadedBookmark bookmark = bookmarks[0] as PdfLoadedBookmark; + bookmark.Destination = new PdfDestination(loadedDocument.Pages[0]); + bookmark.Color = Syncfusion.Drawing.Color.Green; + bookmark.TextStyle = PdfTextStyle.Bold; + bookmark.Title = "Changed title"; + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Bookmarks/Remove-bookmarks-from-an-existing-PDF-document/.NET/Remove-bookmarks-from-an-existing-PDF-document/Program.cs b/Bookmarks/Remove-bookmarks-from-an-existing-PDF-document/.NET/Remove-bookmarks-from-an-existing-PDF-document/Program.cs index b41b25fb..1a1b4f91 100644 --- a/Bookmarks/Remove-bookmarks-from-an-existing-PDF-document/.NET/Remove-bookmarks-from-an-existing-PDF-document/Program.cs +++ b/Bookmarks/Remove-bookmarks-from-an-existing-PDF-document/.NET/Remove-bookmarks-from-an-existing-PDF-document/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Gets all the bookmarks. -PdfBookmarkBase bookmarks = document.Bookmarks; - -//Removes bookmark by bookmark name. -bookmarks.Remove("Page 1"); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets all the bookmarks. + PdfBookmarkBase bookmarks = loadedDocument.Bookmarks; -//Removes bookmark by index. -bookmarks.RemoveAt(1); + //Removes bookmark by bookmark name. + bookmarks.Remove("Page 1"); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Removes bookmark by index. + bookmarks.RemoveAt(1); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Brushes/Draw-shape-on-PDF-with-tiling-brush/.NET/Draw-shape-on-PDF-with-tiling-brush/Program.cs b/Brushes/Draw-shape-on-PDF-with-tiling-brush/.NET/Draw-shape-on-PDF-with-tiling-brush/Program.cs index 88ce4f44..4dfe7912 100644 --- a/Brushes/Draw-shape-on-PDF-with-tiling-brush/.NET/Draw-shape-on-PDF-with-tiling-brush/Program.cs +++ b/Brushes/Draw-shape-on-PDF-with-tiling-brush/.NET/Draw-shape-on-PDF-with-tiling-brush/Program.cs @@ -1,33 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Create new PDF tiling brush. -PdfTilingBrush brush = new PdfTilingBrush(new RectangleF(0, 0, 11, 11)); + //Create new PDF tiling brush. + PdfTilingBrush brush = new PdfTilingBrush(new RectangleF(0, 0, 11, 11)); -//Draw ellipse inside the tile. -brush.Graphics.DrawEllipse(PdfPens.Red, new RectangleF(0, 0, 10, 10)); + //Draw ellipse inside the tile. + brush.Graphics.DrawEllipse(PdfPens.Red, new RectangleF(0, 0, 10, 10)); -//Draw ellipse. -graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); + //Draw ellipse. + graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Brushes/Draw-shapes-on-PDF-with-radial-gradient-brush/.NET/Draw-shapes-on-PDF-with-radial-gradient-brush/Program.cs b/Brushes/Draw-shapes-on-PDF-with-radial-gradient-brush/.NET/Draw-shapes-on-PDF-with-radial-gradient-brush/Program.cs index 82a383f6..843a27dd 100644 --- a/Brushes/Draw-shapes-on-PDF-with-radial-gradient-brush/.NET/Draw-shapes-on-PDF-with-radial-gradient-brush/Program.cs +++ b/Brushes/Draw-shapes-on-PDF-with-radial-gradient-brush/.NET/Draw-shapes-on-PDF-with-radial-gradient-brush/Program.cs @@ -1,30 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Create new PDF radial gradient brush. -PdfRadialGradientBrush brush = new PdfRadialGradientBrush(new PointF(50, 50), 0, new PointF(50, 50), 50, Color.Red, Color.Blue); + //Create new PDF radial gradient brush. + PdfRadialGradientBrush brush = new PdfRadialGradientBrush(new PointF(50, 50), 0, new PointF(50, 50), 50, Color.Red, Color.Blue); -//Draw ellipse on the page. -graphics.DrawEllipse(brush, new RectangleF(0, 0, 100, 100)); + //Draw ellipse on the page. + graphics.DrawEllipse(brush, new RectangleF(0, 0, 100, 100)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Brushes/Fill-an-object-with-gradient-brush-in-a-PDF/.NET/Fill-an-object-with-gradient-brush-in-a-PDF/Program.cs b/Brushes/Fill-an-object-with-gradient-brush-in-a-PDF/.NET/Fill-an-object-with-gradient-brush-in-a-PDF/Program.cs index 5c78a40e..0d820dd8 100644 --- a/Brushes/Fill-an-object-with-gradient-brush-in-a-PDF/.NET/Fill-an-object-with-gradient-brush-in-a-PDF/Program.cs +++ b/Brushes/Fill-an-object-with-gradient-brush-in-a-PDF/.NET/Fill-an-object-with-gradient-brush-in-a-PDF/Program.cs @@ -1,30 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Create new PDF linear gradient brush. -PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue); + //Create new PDF linear gradient brush. + PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(200, 100), Color.Red, Color.Blue); -//Draw ellipse on the page. -graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); + //Draw ellipse on the page. + graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Brushes/Fill-an-object-with-solid-brush-in-a-PDF/.NET/Fill-an-object-with-solid-brush-in-a-PDF/Program.cs b/Brushes/Fill-an-object-with-solid-brush-in-a-PDF/.NET/Fill-an-object-with-solid-brush-in-a-PDF/Program.cs index 6323718f..cdb3867a 100644 --- a/Brushes/Fill-an-object-with-solid-brush-in-a-PDF/.NET/Fill-an-object-with-solid-brush-in-a-PDF/Program.cs +++ b/Brushes/Fill-an-object-with-solid-brush-in-a-PDF/.NET/Fill-an-object-with-solid-brush-in-a-PDF/Program.cs @@ -1,30 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Create new PDF solid brush. -PdfSolidBrush brush = new PdfSolidBrush(Color.Red); + //Create new PDF solid brush. + PdfSolidBrush brush = new PdfSolidBrush(Color.Red); -//Draw ellipse on the page. -graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); + //Draw ellipse on the page. + graphics.DrawEllipse(brush, new RectangleF(0, 0, 200, 100)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Brushes/Hatch-brush/.NET/Hatch-brush/Program.cs b/Brushes/Hatch-brush/.NET/Hatch-brush/Program.cs index 4dc2b94f..1a62e6bc 100644 --- a/Brushes/Hatch-brush/.NET/Hatch-brush/Program.cs +++ b/Brushes/Hatch-brush/.NET/Hatch-brush/Program.cs @@ -2,27 +2,23 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document -PdfDocument document = new PdfDocument(); -//Add a page to the document -PdfPage page = document.Pages.Add(); -//Create PDF graphics for the page -PdfGraphics graphics = page.Graphics; -//Define colors for the hatch brush -Color systemForeColor = Color.FromArgb(255, 255, 255, 0); -Color systemBackColor = Color.FromArgb(255, 78, 167, 46); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document + PdfPage page = document.Pages.Add(); + //Create PDF graphics for the page + PdfGraphics graphics = page.Graphics; + //Define colors for the hatch brush + Color systemForeColor = Color.FromArgb(255, 255, 255, 0); + Color systemBackColor = Color.FromArgb(255, 78, 167, 46); -// Create a new PDF hatch brush with a pattern and colors -PdfHatchBrush pdfHatchBrush = new PdfHatchBrush(PdfHatchStyle.Plaid, new PdfColor(systemForeColor), new PdfColor(systemBackColor)); + // Create a new PDF hatch brush with a pattern and colors + PdfHatchBrush pdfHatchBrush = new PdfHatchBrush(PdfHatchStyle.Plaid, new PdfColor(systemForeColor), new PdfColor(systemBackColor)); -//Draw rectangle on the page -graphics.DrawRectangle(PdfPens.Black, pdfHatchBrush, new Rectangle(100, 100, 300, 200)); + //Draw rectangle on the page + graphics.DrawRectangle(PdfPens.Black, pdfHatchBrush, new Rectangle(100, 100, 300, 200)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs index d2a0e858..aa5c7fcd 100644 --- a/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs +++ b/Brushes/Linear-Gradient-Brush-with-Multiple-Colors/.NET/Linear-Gradient-Brush-with-Multiple-Colors/Program.cs @@ -42,10 +42,6 @@ // Draw a rectangle filled with the gradient graphics.DrawRectangle(brush, new RectangleF(0, 0, 200, 100)); - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - document.Save(outputFileStream); - } + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs index f3ce8c22..463e2bb3 100644 --- a/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs +++ b/Brushes/Radial-gradient-rectangle-in-PDF/.NET/Radial-gradient-rectangle-in-PDF/Program.cs @@ -2,62 +2,57 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create a new PDF document. -PdfDocument document = new PdfDocument(); - -// Add a page to the document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + // Add a page to the document. + PdfPage page = document.Pages.Add(); -// Create PDF graphics object for the page. -PdfGraphics graphics = page.Graphics; + // Create PDF graphics object for the page. + PdfGraphics graphics = page.Graphics; -// Define rectangle dimensions. -float rectWidth = 150f; -float rectHeight = 150f; + // Define rectangle dimensions. + float rectWidth = 150f; + float rectHeight = 150f; -// Calculate position to center the rectangle horizontally at the top. -float pageWidth = page.GetClientSize().Width; -float startX = (pageWidth - rectWidth) / 2; -float startY = 60f; // Positioned near the top + // Calculate position to center the rectangle horizontally at the top. + float pageWidth = page.GetClientSize().Width; + float startX = (pageWidth - rectWidth) / 2; + float startY = 60f; // Positioned near the top -// Define the rectangle path. -PdfPath path = new PdfPath(); -path.AddRectangle(new RectangleF(startX, startY, rectWidth, rectHeight)); + // Define the rectangle path. + PdfPath path = new PdfPath(); + path.AddRectangle(new RectangleF(startX, startY, rectWidth, rectHeight)); -// Define a smooth gradient color scheme. -List gradientColors = new List + // Define a smooth gradient color scheme. + List gradientColors = new List { Color.CornflowerBlue, Color.MediumPurple, Color.DeepPink }; -List gradientPositions = new List { 0.0f, 0.5f, 1.0f }; - -PdfColorBlend colorBlend = new PdfColorBlend -{ - Colors = gradientColors.ToArray(), - Positions = gradientPositions.ToArray() -}; + List gradientPositions = new List { 0.0f, 0.5f, 1.0f }; -// Calculate the radius for the radial gradient. -float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; + PdfColorBlend colorBlend = new PdfColorBlend + { + Colors = gradientColors.ToArray(), + Positions = gradientPositions.ToArray() + }; -// Create a radial gradient brush centered in the rectangle. -PointF center = new PointF(startX + rectWidth / 2, startY + rectHeight / 2); -PdfRadialGradientBrush radialBrush = new PdfRadialGradientBrush(center, 0, center, radius, gradientColors[0], gradientColors[gradientColors.Count - 1]) -{ - InterpolationColors = colorBlend -}; + // Calculate the radius for the radial gradient. + float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; -// Draw the rectangle with the radial gradient fill. -graphics.DrawPath(radialBrush, path); + // Create a radial gradient brush centered in the rectangle. + PointF center = new PointF(startX + rectWidth / 2, startY + rectHeight / 2); + PdfRadialGradientBrush radialBrush = new PdfRadialGradientBrush(center, 0, center, radius, gradientColors[0], gradientColors[gradientColors.Count - 1]) + { + InterpolationColors = colorBlend + }; -// Save the document to file. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - document.Save(fileStream); -} + // Draw the rectangle with the radial gradient fill. + graphics.DrawPath(radialBrush, path); -// Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/ColorSpace/Add-color-space-in-particular-object-in-an-existing-PDF/.NET/Add-color-space-in-particular-object-in-an-existing-PDF/Program.cs b/ColorSpace/Add-color-space-in-particular-object-in-an-existing-PDF/.NET/Add-color-space-in-particular-object-in-an-existing-PDF/Program.cs index e3a51fe0..f1a27768 100644 --- a/ColorSpace/Add-color-space-in-particular-object-in-an-existing-PDF/.NET/Add-color-space-in-particular-object-in-an-existing-PDF/Program.cs +++ b/ColorSpace/Add-color-space-in-particular-object-in-an-existing-PDF/.NET/Add-color-space-in-particular-object-in-an-existing-PDF/Program.cs @@ -1,58 +1,47 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Loads the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Acquires graphics of the page. -PdfGraphics graphics = loadedPage.Graphics; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Loads the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Set the pen. -PdfPen pen = new PdfPen(Color.Red); + //Acquires graphics of the page. + PdfGraphics graphics = loadedPage.Graphics; -//Set the brush. -PdfBrush brush = new PdfSolidBrush(Color.Blue); + //Set the pen. + PdfPen pen = new PdfPen(Color.Red); -//Set the bounds. -RectangleF rectangle = new RectangleF(0, 0, 100, 100); + //Set the brush. + PdfBrush brush = new PdfSolidBrush(Color.Blue); -//Default color space. -graphics.DrawRectangle(pen, brush, rectangle); -graphics.Save(); + //Set the bounds. + RectangleF rectangle = new RectangleF(0, 0, 100, 100); -//GrayScale color space. -graphics.ColorSpace = PdfColorSpace.GrayScale; -graphics.DrawRectangle(pen, brush, rectangle); + //Default color space. + graphics.DrawRectangle(pen, brush, rectangle); + graphics.Save(); -//CMYK color space. -graphics.ColorSpace = PdfColorSpace.CMYK; + //GrayScale color space. + graphics.ColorSpace = PdfColorSpace.GrayScale; + graphics.DrawRectangle(pen, brush, rectangle); -//Draw rectangle. -graphics.DrawRectangle(pen, brush, rectangle); -graphics.Restore(); + //CMYK color space. + graphics.ColorSpace = PdfColorSpace.CMYK; -//Default color space. -graphics.DrawRectangle(pen, brush, rectangle); + //Draw rectangle. + graphics.DrawRectangle(pen, brush, rectangle); + graphics.Restore(); -//Draws by using the PdfBrush. -graphics.DrawRectangle(brush, rectangle); + //Default color space. + graphics.DrawRectangle(pen, brush, rectangle); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Draws by using the PdfBrush. + graphics.DrawRectangle(brush, rectangle); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/ColorSpace/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/.NET/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/Program.cs b/ColorSpace/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/.NET/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/Program.cs index a3607d6c..e244b0b4 100644 --- a/ColorSpace/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/.NET/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/Program.cs +++ b/ColorSpace/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/.NET/Add-graphics-elemets-by-Pantone-color-in-existing-PDF/Program.cs @@ -1,50 +1,39 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Functions; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Creates exponential interpolation function. -PdfExponentialInterpolationFunction function = new PdfExponentialInterpolationFunction(true); -float[] numberArray = new float[4]; -numberArray[0] = 0.38f; -numberArray[1] = 0.88f; -function.C1 = numberArray; - -//Creates SeparationColorSpace. -PdfSeparationColorSpace colorSpace = new PdfSeparationColorSpace(); -colorSpace.TintTransform = function; -colorSpace.Colorant = "PANTONE Orange 021 C"; - -//Creates SeparationColorSpace. -PdfSeparationColor color = new PdfSeparationColor(colorSpace); -color.Tint = 0.7; - -//Set bounds and pen. -RectangleF bounds = new RectangleF(20, 70, 200, 100); -PdfPen pen = new PdfPen(color); - -//Draws the rectangle. -loadedPage.Graphics.DrawRectangle(pen, bounds); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} - -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + + //Creates exponential interpolation function. + PdfExponentialInterpolationFunction function = new PdfExponentialInterpolationFunction(true); + float[] numberArray = new float[4]; + numberArray[0] = 0.38f; + numberArray[1] = 0.88f; + function.C1 = numberArray; + + //Creates SeparationColorSpace. + PdfSeparationColorSpace colorSpace = new PdfSeparationColorSpace(); + colorSpace.TintTransform = function; + colorSpace.Colorant = "PANTONE Orange 021 C"; + + //Creates SeparationColorSpace. + PdfSeparationColor color = new PdfSeparationColor(colorSpace); + color.Tint = 0.7; + + //Set bounds and pen. + RectangleF bounds = new RectangleF(20, 70, 200, 100); + PdfPen pen = new PdfPen(color); + + //Draws the rectangle. + loadedPage.Graphics.DrawRectangle(pen, bounds); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/ColorSpace/Create-PDF-document-with-ICC-color-space/.NET/Create-PDF-document-with-ICC-color-space/Program.cs b/ColorSpace/Create-PDF-document-with-ICC-color-space/.NET/Create-PDF-document-with-ICC-color-space/Program.cs index c6c73f93..4df1fd82 100644 --- a/ColorSpace/Create-PDF-document-with-ICC-color-space/.NET/Create-PDF-document-with-ICC-color-space/Program.cs +++ b/ColorSpace/Create-PDF-document-with-ICC-color-space/.NET/Create-PDF-document-with-ICC-color-space/Program.cs @@ -1,57 +1,49 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Graphics; -//Creates a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Adds a page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); - -//Acquires graphics of the page. -PdfGraphics graphics = pdfPage.Graphics; - -//Creates ICCBased color space. -PdfCalRGBColorSpace calRgbCS = new PdfCalRGBColorSpace(); -calRgbCS.Gamma = new double[] { 7.6, 5.1, 8.5 }; -calRgbCS.Matrix = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; -calRgbCS.WhitePoint = new double[] { 0.7, 1, 0.8 }; - -//Reads the ICC profile. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/input.icc"), FileMode.Open, FileAccess.Read); -byte[] profileData = new byte[fileStream.Length]; -fileStream.Read(profileData, 0, profileData.Length); -fileStream.Close(); - -//Instantiates ICC color space. -PdfICCColorSpace iccBasedCS = new PdfICCColorSpace(); -iccBasedCS.ProfileData = profileData; -iccBasedCS.AlternateColorSpace = calRgbCS; -iccBasedCS.ColorComponents = 3; -iccBasedCS.Range = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; - -//Create ICC color. -PdfICCColor red = new PdfICCColor(iccBasedCS); -red.ColorComponents = new double[] { 1, 0, 1 }; - -//Set the brush. -PdfBrush brush = new PdfSolidBrush(red); - -//Set the bounds. -RectangleF bounds = new RectangleF(0, 0, 300, 300); - -//Draws rectangle by using the PdfBrush. -graphics.DrawRectangle(brush, bounds); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); + //Adds a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); + + //Acquires graphics of the page. + PdfGraphics graphics = pdfPage.Graphics; + + //Creates ICCBased color space. + PdfCalRGBColorSpace calRgbCS = new PdfCalRGBColorSpace(); + calRgbCS.Gamma = new double[] { 7.6, 5.1, 8.5 }; + calRgbCS.Matrix = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; + calRgbCS.WhitePoint = new double[] { 0.7, 1, 0.8 }; + + //Reads the ICC profile. + FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/input.icc"), FileMode.Open, FileAccess.Read); + byte[] profileData = new byte[fileStream.Length]; + fileStream.Read(profileData, 0, profileData.Length); + fileStream.Close(); + + //Instantiates ICC color space. + PdfICCColorSpace iccBasedCS = new PdfICCColorSpace(); + iccBasedCS.ProfileData = profileData; + iccBasedCS.AlternateColorSpace = calRgbCS; + iccBasedCS.ColorComponents = 3; + iccBasedCS.Range = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; + + //Create ICC color. + PdfICCColor red = new PdfICCColor(iccBasedCS); + red.ColorComponents = new double[] { 1, 0, 1 }; + + //Set the brush. + PdfBrush brush = new PdfSolidBrush(red); + + //Set the bounds. + RectangleF bounds = new RectangleF(0, 0, 300, 300); + + //Draws rectangle by using the PdfBrush. + graphics.DrawRectangle(brush, bounds); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/ColorSpace/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/.NET/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/Program.cs b/ColorSpace/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/.NET/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/Program.cs index 54d78fe7..7a2001ff 100644 --- a/ColorSpace/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/.NET/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/Program.cs +++ b/ColorSpace/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/.NET/Draw-graphics-elements-by-using-Pantone-colors-in-a-PDF/Program.cs @@ -1,46 +1,38 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Functions; using Syncfusion.Pdf.Graphics; -//Creates a new document. -PdfDocument document = new PdfDocument(); - -//Creates a new page. -PdfPage page = document.Pages.Add(); - -//Creates exponential interpolation function. -PdfExponentialInterpolationFunction function = new PdfExponentialInterpolationFunction(true); -float[] numberArray = new float[4]; -numberArray[0] = 0.38f; -numberArray[1] = 0.88f; -function.C1 = numberArray; - -//Creates SeparationColorSpace. -PdfSeparationColorSpace colorSpace = new PdfSeparationColorSpace(); -colorSpace.TintTransform = function; -colorSpace.Colorant = "PANTONE Orange 021 C"; - -//Creates SeparationColorSpace. -PdfSeparationColor color = new PdfSeparationColor(colorSpace); -color.Tint = 0.7; - -//Set bounds and pen. -RectangleF bounds = new RectangleF(20, 70, 200, 100); -PdfPen pen = new PdfPen(color); - -//Draws the rectangle. -page.Graphics.DrawRectangle(pen, bounds); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Creates a new page. + PdfPage page = document.Pages.Add(); + + //Creates exponential interpolation function. + PdfExponentialInterpolationFunction function = new PdfExponentialInterpolationFunction(true); + float[] numberArray = new float[4]; + numberArray[0] = 0.38f; + numberArray[1] = 0.88f; + function.C1 = numberArray; + + //Creates SeparationColorSpace. + PdfSeparationColorSpace colorSpace = new PdfSeparationColorSpace(); + colorSpace.TintTransform = function; + colorSpace.Colorant = "PANTONE Orange 021 C"; + + //Creates SeparationColorSpace. + PdfSeparationColor color = new PdfSeparationColor(colorSpace); + color.Tint = 0.7; + + //Set bounds and pen. + RectangleF bounds = new RectangleF(20, 70, 200, 100); + PdfPen pen = new PdfPen(color); + + //Draws the rectangle. + page.Graphics.DrawRectangle(pen, bounds); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/ColorSpace/Draw-rectangle-on-new-PDF-with-CalGray-brush/.NET/Draw-rectangle-on-new-PDF-with-CalGray-brush/Program.cs b/ColorSpace/Draw-rectangle-on-new-PDF-with-CalGray-brush/.NET/Draw-rectangle-on-new-PDF-with-CalGray-brush/Program.cs index e4649bb4..c4b93b59 100644 --- a/ColorSpace/Draw-rectangle-on-new-PDF-with-CalGray-brush/.NET/Draw-rectangle-on-new-PDF-with-CalGray-brush/Program.cs +++ b/ColorSpace/Draw-rectangle-on-new-PDF-with-CalGray-brush/.NET/Draw-rectangle-on-new-PDF-with-CalGray-brush/Program.cs @@ -1,47 +1,39 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Graphics; -//Creates a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Adds a page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adds a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Acquires graphics of the page. -PdfGraphics graphics = pdfPage.Graphics; + //Acquires graphics of the page. + PdfGraphics graphics = pdfPage.Graphics; -//Creates CalGray color space. -PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace(); + //Creates CalGray color space. + PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace(); -//Updates color values. -calGrayColorSpace.Gamma = 0.7; -calGrayColorSpace.WhitePoint = new double[] { 0.2, 1, 0.8 }; + //Updates color values. + calGrayColorSpace.Gamma = 0.7; + calGrayColorSpace.WhitePoint = new double[] { 0.2, 1, 0.8 }; -//Create another CalGray color space. -PdfCalGrayColor calGrayColorSpace1 = new PdfCalGrayColor(calGrayColorSpace); + //Create another CalGray color space. + PdfCalGrayColor calGrayColorSpace1 = new PdfCalGrayColor(calGrayColorSpace); -//Updates the color value. -calGrayColorSpace1.Gray = 0.1; + //Updates the color value. + calGrayColorSpace1.Gray = 0.1; -//Set the brush. -PdfBrush brush = new PdfSolidBrush(calGrayColorSpace1); + //Set the brush. + PdfBrush brush = new PdfSolidBrush(calGrayColorSpace1); -//Set the bounds. -RectangleF bounds = new RectangleF(0, 0, 300, 300); + //Set the bounds. + RectangleF bounds = new RectangleF(0, 0, 300, 300); -//Draws rectangle by using the PdfBrush. -graphics.DrawRectangle(brush, bounds); + //Draws rectangle by using the PdfBrush. + graphics.DrawRectangle(brush, bounds); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/ColorSpace/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/.NET/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/Program.cs b/ColorSpace/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/.NET/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/Program.cs index 87e0a1c3..693fec18 100644 --- a/ColorSpace/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/.NET/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/Program.cs +++ b/ColorSpace/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/.NET/Draw-rectangle-with-CalGray-brush-in-an-existing-PDF/Program.cs @@ -1,49 +1,38 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Loads the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Loads the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Acquires graphics of the page. -PdfGraphics graphics = loadedPage.Graphics; + //Acquires graphics of the page. + PdfGraphics graphics = loadedPage.Graphics; -//Creates CalGray color space. -PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace(); + //Creates CalGray color space. + PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace(); -//Updates color values. -calGrayColorSpace.Gamma = 0.7; -calGrayColorSpace.WhitePoint = new double[] { 0.2, 1, 0.8 }; + //Updates color values. + calGrayColorSpace.Gamma = 0.7; + calGrayColorSpace.WhitePoint = new double[] { 0.2, 1, 0.8 }; -//Creates CalGray color space. -PdfCalGrayColor calGrayColorSpace1 = new PdfCalGrayColor(calGrayColorSpace); -calGrayColorSpace1.Gray = 0.1; + //Creates CalGray color space. + PdfCalGrayColor calGrayColorSpace1 = new PdfCalGrayColor(calGrayColorSpace); + calGrayColorSpace1.Gray = 0.1; -//Set the brush. -PdfBrush brush = new PdfSolidBrush(calGrayColorSpace1); + //Set the brush. + PdfBrush brush = new PdfSolidBrush(calGrayColorSpace1); -//Set the bounds. -RectangleF bounds = new RectangleF(50, 50, 300, 300); + //Set the bounds. + RectangleF bounds = new RectangleF(50, 50, 300, 300); -//Draws rectangle by using the PdfBrush. -graphics.DrawRectangle(brush, bounds); + //Draws rectangle by using the PdfBrush. + graphics.DrawRectangle(brush, bounds); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/ColorSpace/Set-ICC-color-space-in-an-existing-PDF-document/.NET/Set-ICC-color-space-in-an-existing-PDF-document/Program.cs b/ColorSpace/Set-ICC-color-space-in-an-existing-PDF-document/.NET/Set-ICC-color-space-in-an-existing-PDF-document/Program.cs index 7a937205..c392ed9d 100644 --- a/ColorSpace/Set-ICC-color-space-in-an-existing-PDF-document/.NET/Set-ICC-color-space-in-an-existing-PDF-document/Program.cs +++ b/ColorSpace/Set-ICC-color-space-in-an-existing-PDF-document/.NET/Set-ICC-color-space-in-an-existing-PDF-document/Program.cs @@ -1,61 +1,50 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.ColorSpace; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Loads the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Acquires graphics of the page. -PdfGraphics graphics = loadedPage.Graphics; - -//Creates ICCBased color space. -PdfCalRGBColorSpace calRgbCS = new PdfCalRGBColorSpace(); -calRgbCS.Gamma = new double[] { 7.6, 5.1, 8.5 }; -calRgbCS.Matrix = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; -calRgbCS.WhitePoint = new double[] { 0.7, 1, 0.8 }; - -//Reads the ICC profile. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/input.icc"), FileMode.Open, FileAccess.Read); -byte[] profileData = new byte[fileStream.Length]; -fileStream.Read(profileData, 0, profileData.Length); -fileStream.Close(); - -//Instantiates ICC color space. -PdfICCColorSpace iccBasedCS = new PdfICCColorSpace(); -iccBasedCS.ProfileData = profileData; -iccBasedCS.AlternateColorSpace = calRgbCS; -iccBasedCS.ColorComponents = 3; -iccBasedCS.Range = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; - -//Create the ICC color. -PdfICCColor red = new PdfICCColor(iccBasedCS); -red.ColorComponents = new double[] { 1, 0, 1 }; - -//Set the brush. -PdfBrush brush = new PdfSolidBrush(red); - -//Set the bounds. -RectangleF bounds = new RectangleF(0, 0, 300, 300); - -//Draws rectangle by using the PdfBrush. -graphics.DrawRectangle(brush, bounds); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Loads the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + + //Acquires graphics of the page. + PdfGraphics graphics = loadedPage.Graphics; + + //Creates ICCBased color space. + PdfCalRGBColorSpace calRgbCS = new PdfCalRGBColorSpace(); + calRgbCS.Gamma = new double[] { 7.6, 5.1, 8.5 }; + calRgbCS.Matrix = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; + calRgbCS.WhitePoint = new double[] { 0.7, 1, 0.8 }; + + //Reads the ICC profile. + FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/input.icc"), FileMode.Open, FileAccess.Read); + byte[] profileData = new byte[fileStream.Length]; + fileStream.Read(profileData, 0, profileData.Length); + fileStream.Close(); + + //Instantiates ICC color space. + PdfICCColorSpace iccBasedCS = new PdfICCColorSpace(); + iccBasedCS.ProfileData = profileData; + iccBasedCS.AlternateColorSpace = calRgbCS; + iccBasedCS.ColorComponents = 3; + iccBasedCS.Range = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; + + //Create the ICC color. + PdfICCColor red = new PdfICCColor(iccBasedCS); + red.ColorComponents = new double[] { 1, 0, 1 }; + + //Set the brush. + PdfBrush brush = new PdfSolidBrush(red); + + //Set the bounds. + RectangleF bounds = new RectangleF(0, 0, 300, 300); + + //Draws rectangle by using the PdfBrush. + graphics.DrawRectangle(brush, bounds); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/ColorSpace/Use-color-space-in-particular-object-in-a-new-PDF/.NET/Use-color-space-in-particular-object-in-a-new-PDF/Program.cs b/ColorSpace/Use-color-space-in-particular-object-in-a-new-PDF/.NET/Use-color-space-in-particular-object-in-a-new-PDF/Program.cs index 0af79a84..8228a071 100644 --- a/ColorSpace/Use-color-space-in-particular-object-in-a-new-PDF/.NET/Use-color-space-in-particular-object-in-a-new-PDF/Program.cs +++ b/ColorSpace/Use-color-space-in-particular-object-in-a-new-PDF/.NET/Use-color-space-in-particular-object-in-a-new-PDF/Program.cs @@ -1,57 +1,50 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; -//Creates a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Adds a page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Adds a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Acquires graphics of the page. -PdfGraphics graphics = pdfPage.Graphics; + //Acquires graphics of the page. + PdfGraphics graphics = pdfPage.Graphics; -//Set pen. -PdfPen pen = new PdfPen(Color.Red); + //Set pen. + PdfPen pen = new PdfPen(Color.Red); -//Set brush. -PdfBrush brush = new PdfSolidBrush(Color.Blue); + //Set brush. + PdfBrush brush = new PdfSolidBrush(Color.Blue); -//Set bounds. -RectangleF rectangle = new RectangleF(0, 0, 100, 100); + //Set bounds. + RectangleF rectangle = new RectangleF(0, 0, 100, 100); -//Default color space. -graphics.DrawRectangle(pen, brush, rectangle); -graphics.Save(); + //Default color space. + graphics.DrawRectangle(pen, brush, rectangle); + graphics.Save(); -//GrayScale color space. -graphics.ColorSpace = PdfColorSpace.GrayScale; + //GrayScale color space. + graphics.ColorSpace = PdfColorSpace.GrayScale; -//Draw rectangle in page graphics. -graphics.DrawRectangle(pen, brush, rectangle); + //Draw rectangle in page graphics. + graphics.DrawRectangle(pen, brush, rectangle); -//CMYK color space. -graphics.ColorSpace = PdfColorSpace.CMYK; + //CMYK color space. + graphics.ColorSpace = PdfColorSpace.CMYK; -//Draw rectangle. -graphics.DrawRectangle(pen, brush, rectangle); + //Draw rectangle. + graphics.DrawRectangle(pen, brush, rectangle); -graphics.Restore(); + graphics.Restore(); -//Default color space. -graphics.DrawRectangle(pen, brush, rectangle); + //Default color space. + graphics.DrawRectangle(pen, brush, rectangle); -//Draws by using the PdfBrush. -graphics.DrawRectangle(brush, rectangle); + //Draws by using the PdfBrush. + graphics.DrawRectangle(brush, rectangle); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDocument.Close(true); diff --git a/Compression/Compress-and-replace-image-in-a-PDF-document/.NET-Framework/Compress-and-replace-image-in-a-PDF-document/Program.cs b/Compression/Compress-and-replace-image-in-a-PDF-document/.NET-Framework/Compress-and-replace-image-in-a-PDF-document/Program.cs index afb9970b..8280595f 100644 --- a/Compression/Compress-and-replace-image-in-a-PDF-document/.NET-Framework/Compress-and-replace-image-in-a-PDF-document/Program.cs +++ b/Compression/Compress-and-replace-image-in-a-PDF-document/.NET-Framework/Compress-and-replace-image-in-a-PDF-document/Program.cs @@ -44,9 +44,6 @@ static void Main(string[] args) //Save and close the document. loadedDocument.Save("Output.pdf"); loadedDocument.Close(true); - - //This will open the PDF file so, the result will be seen in default PDF viewer - Process.Start("Output.pdf"); } } } diff --git a/Compression/Compress-quality-of-image-in-PDF-document/.NET-Framework/Compress-quality-of-image-in-PDF-document/Program.cs b/Compression/Compress-quality-of-image-in-PDF-document/.NET-Framework/Compress-quality-of-image-in-PDF-document/Program.cs index 53d2dbc2..561d3421 100644 --- a/Compression/Compress-quality-of-image-in-PDF-document/.NET-Framework/Compress-quality-of-image-in-PDF-document/Program.cs +++ b/Compression/Compress-quality-of-image-in-PDF-document/.NET-Framework/Compress-quality-of-image-in-PDF-document/Program.cs @@ -35,9 +35,6 @@ static void Main(string[] args) //Close the document. document.Close(true); - - //This will open the PDF file so, the result will be seen in default PDF viewer - Process.Start("Output.pdf"); } } } diff --git a/Compression/Compress-the-content-of-the-PDF-document/.NET/Compress-the-content-of-the-PDF-document/Program.cs b/Compression/Compress-the-content-of-the-PDF-document/.NET/Compress-the-content-of-the-PDF-document/Program.cs index ec9d204f..91f125f6 100644 --- a/Compression/Compress-the-content-of-the-PDF-document/.NET/Compress-the-content-of-the-PDF-document/Program.cs +++ b/Compression/Compress-the-content-of-the-PDF-document/.NET/Compress-the-content-of-the-PDF-document/Program.cs @@ -1,40 +1,32 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the compression level to best -document.Compression = PdfCompressionLevel.Best; - -//Add a page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Set the compression level to best + document.Compression = PdfCompressionLevel.Best; -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -string text = "Hello World!!!"; -PdfTextElement textElement = new PdfTextElement(text, font); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, font.MeasureString(text).Width, page.GetClientSize().Height)); + string text = "Hello World!!!"; + PdfTextElement textElement = new PdfTextElement(text, font); -for (int i = 0; i < 1000; i++) -{ - result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom + 10, font.MeasureString(text).Width, page.GetClientSize().Height)); -} + PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, font.MeasureString(text).Width, page.GetClientSize().Height)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + for (int i = 0; i < 1000; i++) + { + result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom + 10, font.MeasureString(text).Width, page.GetClientSize().Height)); + } -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs index 5cc5a0c9..a1e796ab 100644 --- a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs +++ b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs @@ -1,33 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -// Open a file stream to read the input PDF file. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/input.pdf"), FileMode.Open, FileAccess.Read)) -{ - // Create a new PdfLoadedDocument object from the file stream. - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream)) - { - // Create a new PdfCompressionOptions object. - PdfCompressionOptions options = new PdfCompressionOptions(); - - //Enable the compress image. - options.CompressImages = true; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + // Create a new PdfCompressionOptions object. + PdfCompressionOptions options = new PdfCompressionOptions(); + + //Enable the compress image. + options.CompressImages = true; + + //Set the image quality. + options.ImageQuality = 50; - //Set the image quality. - options.ImageQuality = 50; - - // Compress the PDF document. - loadedDocument.Compress(options); + // Compress the PDF document. + loadedDocument.Compress(options); - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - //Close the document. - loadedDocument.Close(true); - } -} \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Compression/Compress-the-images-in-an-existing-PDF-document/.NET/Compress-the-images-in-an-existing-PDF-document/Program.cs b/Compression/Compress-the-images-in-an-existing-PDF-document/.NET/Compress-the-images-in-an-existing-PDF-document/Program.cs index 21c6d465..e547bc57 100644 --- a/Compression/Compress-the-images-in-an-existing-PDF-document/.NET/Compress-the-images-in-an-existing-PDF-document/Program.cs +++ b/Compression/Compress-the-images-in-an-existing-PDF-document/.NET/Compress-the-images-in-an-existing-PDF-document/Program.cs @@ -1,40 +1,28 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -// Open a file stream to read the input PDF file. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/imageDoc.pdf"), FileMode.Open, FileAccess.Read)) -{ - // Create a new PdfLoadedDocument object from the file stream. - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream)) - { - // Create a new PdfCompressionOptions object. - PdfCompressionOptions options = new PdfCompressionOptions(); - - // Enable image compression and set image quality. - options.CompressImages = true; - options.ImageQuality = 50; - - // Enable font optimization. - options.OptimizeFont = true; - - // Enable page content optimization. - options.OptimizePageContents = true; - - // Remove metadata from the PDF. - options.RemoveMetadata = true; - - // Compress the PDF document. - loadedDocument.Compress(options); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + // Create a new PdfCompressionOptions object. + PdfCompressionOptions options = new PdfCompressionOptions(); + + // Enable image compression and set image quality. + options.CompressImages = true; + options.ImageQuality = 50; + + // Enable font optimization. + options.OptimizeFont = true; + + // Enable page content optimization. + options.OptimizePageContents = true; + + // Remove metadata from the PDF. + options.RemoveMetadata = true; + + // Compress the PDF document. + loadedDocument.Compress(options); - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - //Close the document. - loadedDocument.Close(true); - } -} \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Compression/Optimize-embedded-font-in-an-existing-PDF-document/.NET/Optimize-embedded-font-in-an-existing-PDF-document/Program.cs b/Compression/Optimize-embedded-font-in-an-existing-PDF-document/.NET/Optimize-embedded-font-in-an-existing-PDF-document/Program.cs index c6e2a401..03407721 100644 --- a/Compression/Optimize-embedded-font-in-an-existing-PDF-document/.NET/Optimize-embedded-font-in-an-existing-PDF-document/Program.cs +++ b/Compression/Optimize-embedded-font-in-an-existing-PDF-document/.NET/Optimize-embedded-font-in-an-existing-PDF-document/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Load an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Create a new compression option. -PdfCompressionOptions options = new PdfCompressionOptions(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create a new compression option. + PdfCompressionOptions options = new PdfCompressionOptions(); -//Enable the optimize font option -options.OptimizeFont = true; + //Enable the optimize font option + options.OptimizeFont = true; -//Assign the compression option to the document -loadedDocument.Compress(options); + //Assign the compression option to the document + loadedDocument.Compress(options); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Compression/Optimize-page-contents-in-an-existing-PDF-document/.NET/Optimize-page-contents-in-an-existing-PDF-document/Program.cs b/Compression/Optimize-page-contents-in-an-existing-PDF-document/.NET/Optimize-page-contents-in-an-existing-PDF-document/Program.cs index c9b58090..7d501a5c 100644 --- a/Compression/Optimize-page-contents-in-an-existing-PDF-document/.NET/Optimize-page-contents-in-an-existing-PDF-document/Program.cs +++ b/Compression/Optimize-page-contents-in-an-existing-PDF-document/.NET/Optimize-page-contents-in-an-existing-PDF-document/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Create a new compression option. -PdfCompressionOptions options = new PdfCompressionOptions(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create a new compression option. + PdfCompressionOptions options = new PdfCompressionOptions(); -//Enable the optimize page contents. -options.OptimizePageContents = true; + //Enable the optimize page contents. + options.OptimizePageContents = true; -//Assign the compression option to the document -loadedDocument.Compress(options); + //Assign the compression option to the document + loadedDocument.Compress(options); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Compression/Reduce-PDF-file-size-by-removing-PDF-metadata/.NET/Reduce-PDF-file-size-by-removing-PDF-metadata/Program.cs b/Compression/Reduce-PDF-file-size-by-removing-PDF-metadata/.NET/Reduce-PDF-file-size-by-removing-PDF-metadata/Program.cs index c2e32f0c..954fa3d3 100644 --- a/Compression/Reduce-PDF-file-size-by-removing-PDF-metadata/.NET/Reduce-PDF-file-size-by-removing-PDF-metadata/Program.cs +++ b/Compression/Reduce-PDF-file-size-by-removing-PDF-metadata/.NET/Reduce-PDF-file-size-by-removing-PDF-metadata/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Create a new compression option. -PdfCompressionOptions options = new PdfCompressionOptions(); - -//Set to remove the metadata information. -options.RemoveMetadata = true; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create a new compression option. + PdfCompressionOptions options = new PdfCompressionOptions(); -//Assign the compression option to the document -loadedDocument.Compress(options); + //Set to remove the metadata information. + options.RemoveMetadata = true; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Assign the compression option to the document + loadedDocument.Compress(options); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Document conversion/Converting-XPS-to-PDF-document/.NET/Converting-XPS-to-PDF-document/Program.cs b/Document conversion/Converting-XPS-to-PDF-document/.NET/Converting-XPS-to-PDF-document/Program.cs index e2d6f537..ef52e632 100644 --- a/Document conversion/Converting-XPS-to-PDF-document/.NET/Converting-XPS-to-PDF-document/Program.cs +++ b/Document conversion/Converting-XPS-to-PDF-document/.NET/Converting-XPS-to-PDF-document/Program.cs @@ -1,25 +1,14 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.XPS; using System.Reflection.Metadata; //Initialize XPS to PDF converter. XPSToPdfConverter converter = new XPSToPdfConverter(); -//Open the XPS file as stream. -FileStream fileStream = new FileStream(System.IO.Path.GetFullPath(@"Data/Input.xps"), FileMode.Open, FileAccess.ReadWrite); - //Convert the XPS to PDF document. -PdfDocument document = converter.Convert(fileStream); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(System.IO.Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +using (PdfDocument document = converter.Convert(Path.GetFullPath(@"Data/Input.xps"))) { //Save the PDF document to file stream. - document.Save(outputFileStream); + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Document conversion/Excel-to-PDF/Convert-workbook-to-PDF-document/.NET/Convert-workbook-to-PDF-document/Program.cs b/Document conversion/Excel-to-PDF/Convert-workbook-to-PDF-document/.NET/Convert-workbook-to-PDF-document/Program.cs index 786395c0..108304e8 100644 --- a/Document conversion/Excel-to-PDF/Convert-workbook-to-PDF-document/.NET/Convert-workbook-to-PDF-document/Program.cs +++ b/Document conversion/Excel-to-PDF/Convert-workbook-to-PDF-document/.NET/Convert-workbook-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.XlsIO; using Syncfusion.XlsIORenderer; @@ -15,12 +13,9 @@ //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - - Stream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); excelStream.Dispose(); - stream.Dispose(); //Close the document. pdfDocument.Close(true); diff --git a/Document conversion/Excel-to-PDF/Converting-Excel-with-chart-to-PDF-document/.NET/Converting-Excel-with-chart-to-PDF-document/Program.cs b/Document conversion/Excel-to-PDF/Converting-Excel-with-chart-to-PDF-document/.NET/Converting-Excel-with-chart-to-PDF-document/Program.cs index 20f3b9eb..e701eae5 100644 --- a/Document conversion/Excel-to-PDF/Converting-Excel-with-chart-to-PDF-document/.NET/Converting-Excel-with-chart-to-PDF-document/Program.cs +++ b/Document conversion/Excel-to-PDF/Converting-Excel-with-chart-to-PDF-document/.NET/Converting-Excel-with-chart-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.XlsIO; using Syncfusion.XlsIORenderer; @@ -18,12 +16,10 @@ //Convert Excel document with charts into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(workbook); - //Save the PDF document. - Stream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + //Save the PDF document. + pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); excelStream.Dispose(); - stream.Dispose(); //Close the PDF document. pdfDocument.Close(true); diff --git a/Document conversion/Excel-to-PDF/Converting-a-worksheet-to-PDF-document/.NET/Converting-a-worksheet-to-PDF-document/Program.cs b/Document conversion/Excel-to-PDF/Converting-a-worksheet-to-PDF-document/.NET/Converting-a-worksheet-to-PDF-document/Program.cs index d7dc6cf9..d17a93dd 100644 --- a/Document conversion/Excel-to-PDF/Converting-a-worksheet-to-PDF-document/.NET/Converting-a-worksheet-to-PDF-document/Program.cs +++ b/Document conversion/Excel-to-PDF/Converting-a-worksheet-to-PDF-document/.NET/Converting-a-worksheet-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.XlsIO; using Syncfusion.XlsIORenderer; @@ -16,10 +14,7 @@ //Convert Excel document into PDF document PdfDocument pdfDocument = renderer.ConvertToPDF(worksheet); - - Stream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); + pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); excelStream.Dispose(); - stream.Dispose(); } diff --git a/Document conversion/Excel-to-PDF/Creating-individual-PDF-document-for-each-worksheet/.NET/Program.cs b/Document conversion/Excel-to-PDF/Creating-individual-PDF-document-for-each-worksheet/.NET/Program.cs index 7d024f08..15371792 100644 --- a/Document conversion/Excel-to-PDF/Creating-individual-PDF-document-for-each-worksheet/.NET/Program.cs +++ b/Document conversion/Excel-to-PDF/Creating-individual-PDF-document-for-each-worksheet/.NET/Program.cs @@ -26,9 +26,7 @@ pdfDocument = renderer.ConvertToPDF(sheet); //Save the PDF file. - Stream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - pdfDocument.Save(stream); - stream.Dispose(); + pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } excelStream.Dispose(); diff --git a/Document conversion/RTF-to-PDF/Convert-RTF-to-PDF-document/.NET/Convert-RTF-to-PDF-document/Program.cs b/Document conversion/RTF-to-PDF/Convert-RTF-to-PDF-document/.NET/Convert-RTF-to-PDF-document/Program.cs index 9299a049..17452822 100644 --- a/Document conversion/RTF-to-PDF/Convert-RTF-to-PDF-document/.NET/Convert-RTF-to-PDF-document/Program.cs +++ b/Document conversion/RTF-to-PDF/Convert-RTF-to-PDF-document/.NET/Convert-RTF-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO.DLS; using Syncfusion.DocIORenderer; using Syncfusion.Pdf; using System.Reflection.Metadata; @@ -21,12 +19,8 @@ render.Dispose(); wordDocument.Dispose(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); -} +//Save the PDF document to file stream. +pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. pdfDocument.Close(true); \ No newline at end of file diff --git a/Document conversion/TIFF-to-PDF/Converting-multipage-TIFF-to-PDF-document/.NET/Converting-multipage-TIFF-to-PDF-document/Program.cs b/Document conversion/TIFF-to-PDF/Converting-multipage-TIFF-to-PDF-document/.NET/Converting-multipage-TIFF-to-PDF-document/Program.cs index ba0155a2..985cd738 100644 --- a/Document conversion/TIFF-to-PDF/Converting-multipage-TIFF-to-PDF-document/.NET/Converting-multipage-TIFF-to-PDF-document/Program.cs +++ b/Document conversion/TIFF-to-PDF/Converting-multipage-TIFF-to-PDF-document/.NET/Converting-multipage-TIFF-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf; //Create a new PDF document. @@ -43,13 +41,8 @@ //Draw TIFF image into the PDF page. page.Graphics.DrawImage(tiffImage, Syncfusion.Drawing.PointF.Empty, size); } - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document to file stream. +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/Document conversion/Word-to-PDF/Converting-Word-to-PDF-document/.NET/Converting-Word-to-PDF-document/Program.cs b/Document conversion/Word-to-PDF/Converting-Word-to-PDF-document/.NET/Converting-Word-to-PDF-document/Program.cs index 3c58dc45..e3da6bdf 100644 --- a/Document conversion/Word-to-PDF/Converting-Word-to-PDF-document/.NET/Converting-Word-to-PDF-document/Program.cs +++ b/Document conversion/Word-to-PDF/Converting-Word-to-PDF-document/.NET/Converting-Word-to-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO.DLS; using Syncfusion.DocIORenderer; using Syncfusion.Pdf; using System.Reflection.Metadata; @@ -21,12 +19,7 @@ render.Dispose(); wordDocument.Dispose(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); -} - +//Save the PDF document. +pdfDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. pdfDocument.Close(true); \ No newline at end of file diff --git a/Redaction/Display-text-on-the-redacted-area/.NET/Display-text-on-the-redacted-area/Program.cs b/Redaction/Display-text-on-the-redacted-area/.NET/Display-text-on-the-redacted-area/Program.cs index 7a77722e..1e80d698 100644 --- a/Redaction/Display-text-on-the-redacted-area/.NET/Display-text-on-the-redacted-area/Program.cs +++ b/Redaction/Display-text-on-the-redacted-area/.NET/Display-text-on-the-redacted-area/Program.cs @@ -1,41 +1,30 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a redaction object. -PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); + //Create a redaction object. + PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); -//Font for the overlay text. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Courier, 10); + //Font for the overlay text. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Courier, 10); -//Draw text on the redacted area. -redaction.Appearance.Graphics.DrawString("Redacted", font, PdfBrushes.Red, new PointF(5, 5)); + //Draw text on the redacted area. + redaction.Appearance.Graphics.DrawString("Redacted", font, PdfBrushes.Red, new PointF(5, 5)); -//Add a redaction object into the redaction collection of loaded page. -page.AddRedaction(redaction); + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); -//Redact the contents from the PDF document. -document.Redact(); + //Redact the contents from the PDF document. + loadedDocument.Redact(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Redaction/Draw-image-on-the-redacted-area-in-PDF-document/.NET/Draw-image-on-the-redacted-area-in-PDF-document/Program.cs b/Redaction/Draw-image-on-the-redacted-area-in-PDF-document/.NET/Draw-image-on-the-redacted-area-in-PDF-document/Program.cs index bea92242..fdd8fdf5 100644 --- a/Redaction/Draw-image-on-the-redacted-area-in-PDF-document/.NET/Draw-image-on-the-redacted-area-in-PDF-document/Program.cs +++ b/Redaction/Draw-image-on-the-redacted-area-in-PDF-document/.NET/Draw-image-on-the-redacted-area-in-PDF-document/Program.cs @@ -1,44 +1,33 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a PDF redaction for the page. -PdfRedaction redaction = new PdfRedaction(new RectangleF(63, 57, 182, 157)); + //Create a PDF redaction for the page. + PdfRedaction redaction = new PdfRedaction(new RectangleF(63, 57, 182, 157)); -//Get stream from the image file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.jpg"), FileMode.Open, FileAccess.Read); + //Get stream from the image file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.jpg"), FileMode.Open, FileAccess.Read); -//Load the image file. -PdfImage image = new PdfBitmap(imageStream); + //Load the image file. + PdfImage image = new PdfBitmap(imageStream); -//Draw image on the redaction appearance. -redaction.Appearance.Graphics.DrawImage(image, new RectangleF(0, 0, 182, 157)); + //Draw image on the redaction appearance. + redaction.Appearance.Graphics.DrawImage(image, new RectangleF(0, 0, 182, 157)); -//Add a redaction object into the redaction collection of loaded page. -page.AddRedaction(redaction); + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); -//Redact the contents from the PDF document. -document.Redact(); + //Redact the contents from the PDF document. + loadedDocument.Redact(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Redaction/Draw-pattern-on-the-redacted-area-in-PDF-document/.NET/Draw-pattern-on-the-redacted-area-in-PDF-document/Program.cs b/Redaction/Draw-pattern-on-the-redacted-area-in-PDF-document/.NET/Draw-pattern-on-the-redacted-area-in-PDF-document/Program.cs index 2440eca0..8c3fc1a7 100644 --- a/Redaction/Draw-pattern-on-the-redacted-area-in-PDF-document/.NET/Draw-pattern-on-the-redacted-area-in-PDF-document/Program.cs +++ b/Redaction/Draw-pattern-on-the-redacted-area-in-PDF-document/.NET/Draw-pattern-on-the-redacted-area-in-PDF-document/Program.cs @@ -1,63 +1,52 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; - -//Create a PDF redaction for the page. -PdfRedaction redaction = new PdfRedaction(new RectangleF(341, 149, 64, 14)); - -//Draw a mosaic pattern on the redaction bounds. -RectangleF rect = new RectangleF(0, 0, 8, 8); - -//Create tilling brush. -PdfTilingBrush tillingBrush = new PdfTilingBrush(rect); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.Gray, new RectangleF(0, 0, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(2, 0, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(4, 0, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(6, 0, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(0, 2, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(2, 2, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(4, 2, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(6, 2, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(0, 4, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(2, 4, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(4, 4, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(6, 4, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(0, 6, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(2, 6, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(4, 6, 2, 2)); -tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(6, 6, 2, 2)); - -rect = new RectangleF(0, 0, 16, 14); PdfTilingBrush tillingBrushNew = new PdfTilingBrush(rect); -tillingBrushNew.Graphics.DrawRectangle(tillingBrush, rect); - -//Draw rectangle in the redaction appearance. -redaction.Appearance.Graphics.DrawRectangle(tillingBrushNew, new RectangleF(0, 0, 64, 14)); - -//Add a redaction object into the redaction collection of loaded page. -page.AddRedaction(redaction); - -//Redact the contents from the PDF document. -document.Redact(); - -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} - -//Close the document. -document.Close(true); \ No newline at end of file + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; + + //Create a PDF redaction for the page. + PdfRedaction redaction = new PdfRedaction(new RectangleF(341, 149, 64, 14)); + + //Draw a mosaic pattern on the redaction bounds. + RectangleF rect = new RectangleF(0, 0, 8, 8); + + //Create tilling brush. + PdfTilingBrush tillingBrush = new PdfTilingBrush(rect); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.Gray, new RectangleF(0, 0, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(2, 0, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(4, 0, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(6, 0, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(0, 2, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(2, 2, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(4, 2, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(6, 2, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(0, 4, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(2, 4, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(4, 4, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.White, new RectangleF(6, 4, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(0, 6, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.LightGray, new RectangleF(2, 6, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.Black, new RectangleF(4, 6, 2, 2)); + tillingBrush.Graphics.DrawRectangle(PdfBrushes.DarkGray, new RectangleF(6, 6, 2, 2)); + + rect = new RectangleF(0, 0, 16, 14); PdfTilingBrush tillingBrushNew = new PdfTilingBrush(rect); + tillingBrushNew.Graphics.DrawRectangle(tillingBrush, rect); + + //Draw rectangle in the redaction appearance. + redaction.Appearance.Graphics.DrawRectangle(tillingBrushNew, new RectangleF(0, 0, 64, 14)); + + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); + + //Redact the contents from the PDF document. + loadedDocument.Redact(); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Redaction/Fill-color-on-the-redacted-area-in-a-PDF/.NET/Fill-color-on-the-redacted-area-in-a-PDF/Program.cs b/Redaction/Fill-color-on-the-redacted-area-in-a-PDF/.NET/Fill-color-on-the-redacted-area-in-a-PDF/Program.cs index 656c80a6..82f05711 100644 --- a/Redaction/Fill-color-on-the-redacted-area-in-a-PDF/.NET/Fill-color-on-the-redacted-area-in-a-PDF/Program.cs +++ b/Redaction/Fill-color-on-the-redacted-area-in-a-PDF/.NET/Fill-color-on-the-redacted-area-in-a-PDF/Program.cs @@ -1,37 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a PDF redaction for the page. -PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17)); + //Create a PDF redaction for the page. + PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17)); -//Set fill color for the redaction bounds. -redaction.FillColor = Color.Red; + //Set fill color for the redaction bounds. + redaction.FillColor = Color.Red; -//Add a redaction object into the redaction collection of loaded page. -page.AddRedaction(redaction); + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); -//Redact the contents from the PDF document. -loadedDocument.Redact(); + //Redact the contents from the PDF document. + loadedDocument.Redact(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET/Find_text_by_regular_expression/Program.cs b/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET/Find_text_by_regular_expression/Program.cs index 013b790e..1081cee5 100644 --- a/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET/Find_text_by_regular_expression/Program.cs +++ b/Redaction/Find-text-by-regular-expression-pattern-and-redact-it-from-PDF-document/.NET/Find_text_by_regular_expression/Program.cs @@ -4,51 +4,42 @@ using Syncfusion.Pdf; using System.Text.RegularExpressions; -//Create stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -TextLineCollection collection = new TextLineCollection(); -//Extract text from first page. -string extractedText = page.ExtractText(out collection); + TextLineCollection collection = new TextLineCollection(); + //Extract text from first page. + string extractedText = page.ExtractText(out collection); -foreach (TextLine line in collection.TextLine) -{ - foreach (TextWord word in line.WordCollection) + foreach (TextLine line in collection.TextLine) { - //Define regular expression pattern to search for dates in the format MM/DD/YYYY - string datePattern = @"\b\d{1,2}\/\d{1,2}\/\d{4}\b"; - //Search for dates - MatchCollection dateMatches = Regex.Matches(word.Text, datePattern); - //Add redaction if the match found - foreach (Match dateMatch in dateMatches) + foreach (TextWord word in line.WordCollection) { - string textToFindAndRedact = dateMatch.Value; - if (textToFindAndRedact == word.Text) + //Define regular expression pattern to search for dates in the format MM/DD/YYYY + string datePattern = @"\b\d{1,2}\/\d{1,2}\/\d{4}\b"; + //Search for dates + MatchCollection dateMatches = Regex.Matches(word.Text, datePattern); + //Add redaction if the match found + foreach (Match dateMatch in dateMatches) { - //Create a redaction object. - PdfRedaction redaction = new PdfRedaction(word.Bounds, Syncfusion.Drawing.Color.Black); - //Add a redaction object into the redaction collection of loaded page. - page.AddRedaction(redaction); + string textToFindAndRedact = dateMatch.Value; + if (textToFindAndRedact == word.Text) + { + //Create a redaction object. + PdfRedaction redaction = new PdfRedaction(word.Bounds, Syncfusion.Drawing.Color.Black); + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); + } } } } -} - -//Redact the contents from the PDF document. -document.Redact(); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Redact the contents from the PDF document. + loadedDocument.Redact(); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Redaction/Get-the-redaction-progress-from-PDF-document/.NET/Get-the-redaction-progress-from-PDF-document/Program.cs b/Redaction/Get-the-redaction-progress-from-PDF-document/.NET/Get-the-redaction-progress-from-PDF-document/Program.cs index 398fa3e0..c6811780 100644 --- a/Redaction/Get-the-redaction-progress-from-PDF-document/.NET/Get-the-redaction-progress-from-PDF-document/Program.cs +++ b/Redaction/Get-the-redaction-progress-from-PDF-document/.NET/Get-the-redaction-progress-from-PDF-document/Program.cs @@ -1,37 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document from stream. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the first page. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the first page. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Create redaction. -PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); + //Create redaction. + PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); -//Add redaction to the loaded page. -page.AddRedaction(redaction); + //Add redaction to the loaded page. + page.AddRedaction(redaction); -loadedDocument.RedactionProgress += redaction_TrackProgress; + loadedDocument.RedactionProgress += redaction_TrackProgress; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); - //Event handler for Track redaction process. void redaction_TrackProgress(object sender, RedactionProgressEventArgs arguments) { diff --git a/Redaction/Get-the-result-of-redaction-with-other-information/.NET/Get-the-result-of-redaction-with-other-information/Program.cs b/Redaction/Get-the-result-of-redaction-with-other-information/.NET/Get-the-result-of-redaction-with-other-information/Program.cs index 0c022b39..0cecdb88 100644 --- a/Redaction/Get-the-result-of-redaction-with-other-information/.NET/Get-the-result-of-redaction-with-other-information/Program.cs +++ b/Redaction/Get-the-result-of-redaction-with-other-information/.NET/Get-the-result-of-redaction-with-other-information/Program.cs @@ -1,44 +1,31 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load an existing PDF. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the first page. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - -//Create PDF redaction for the page. -PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); - -//Add redaction to the loaded page -page.AddRedaction(redaction); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the first page. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Redact the contents from PDF document -List redactionResults = loadedDocument.Redact(); + //Create PDF redaction for the page. + PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17), Color.Black); -foreach (PdfRedactionResult result in redactionResults) -{ - if (result.IsRedactionSuccess) - Console.WriteLine("Content redacted successfully..."); - else - Console.WriteLine("Content not redacted properly..."); -} + //Add redaction to the loaded page + page.AddRedaction(redaction); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Redact the contents from PDF document + List redactionResults = loadedDocument.Redact(); -//Close the document. -loadedDocument.Close(true); + foreach (PdfRedactionResult result in redactionResults) + { + if (result.IsRedactionSuccess) + Console.WriteLine("Content redacted successfully..."); + else + Console.WriteLine("Content not redacted properly..."); + } -Console.ReadLine(); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Redaction/Redact-text-content-alone-on-the-redated-area/.NET/Program.cs b/Redaction/Redact-text-content-alone-on-the-redated-area/.NET/Program.cs index 3ba08abc..335ce243 100644 --- a/Redaction/Redact-text-content-alone-on-the-redated-area/.NET/Program.cs +++ b/Redaction/Redact-text-content-alone-on-the-redated-area/.NET/Program.cs @@ -1,22 +1,20 @@ -// See https://aka.ms/new-console-template for more information -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; using Syncfusion.Drawing; -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument document = new PdfLoadedDocument(docStream); -PdfRedaction redaction = new PdfRedaction(new RectangleF(150, 150, 60, 24), Color.Transparent); -//Only the text within the redaction bounds should be redacted. -redaction.TextOnly = true; -foreach (PdfLoadedPage loadedPage in document.Pages) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - loadedPage.AddRedaction(redaction); + PdfRedaction redaction = new PdfRedaction(new RectangleF(150, 150, 60, 24), Color.Transparent); + //Only the text within the redaction bounds should be redacted. + redaction.TextOnly = true; + foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) + { + loadedPage.AddRedaction(redaction); + } + loadedDocument.Redact(); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -document.Redact(); -//Save the document -MemoryStream stream = new MemoryStream(); -document.Save(stream); -File.WriteAllBytes(Path.GetFullPath(@"Output/Output.pdf"), stream.ToArray()); -//Close the document. -document.Close(true); diff --git a/Redaction/Redaction-fill-color-customization/.NET/Redaction-fill-color-customization/Program.cs b/Redaction/Redaction-fill-color-customization/.NET/Redaction-fill-color-customization/Program.cs index a8515d76..912d368f 100644 --- a/Redaction/Redaction-fill-color-customization/.NET/Redaction-fill-color-customization/Program.cs +++ b/Redaction/Redaction-fill-color-customization/.NET/Redaction-fill-color-customization/Program.cs @@ -3,43 +3,39 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Add a page to the document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create a new Redaction annotation -PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); -//Assign the Bounds Value -annot.Bounds = new Rectangle(100, 120, 100, 100); -//Assign the InnerColor -annot.InnerColor = Color.Black; -//Assign the BorderColor -annot.BorderColor = Color.Yellow; + //Create a new Redaction annotation + PdfRedactionAnnotation annot = new PdfRedactionAnnotation(); + //Assign the Bounds Value + annot.Bounds = new Rectangle(100, 120, 100, 100); + //Assign the InnerColor + annot.InnerColor = Color.Black; + //Assign the BorderColor + annot.BorderColor = Color.Yellow; -//Assign the AppearanceFillColor -annot.AppearanceFillColor = Color.BlueViolet; + //Assign the AppearanceFillColor + annot.AppearanceFillColor = Color.BlueViolet; -//Assign tbe TextColor -annot.TextColor = Color.Blue; -//Assign the font -annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); -//Assign the OverlayText -annot.OverlayText = "REDACTION"; -//Assign the TextAlignment -annot.TextAlignment = PdfTextAlignment.Right; -//Assign the RepeatText -annot.RepeatText = true; -annot.SetAppearance(true); + //Assign tbe TextColor + annot.TextColor = Color.Blue; + //Assign the font + annot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); + //Assign the OverlayText + annot.OverlayText = "REDACTION"; + //Assign the TextAlignment + annot.TextAlignment = PdfTextAlignment.Right; + //Assign the RepeatText + annot.RepeatText = true; + annot.SetAppearance(true); -//Add the annotation to the page -page.Annotations.Add(annot); + //Add the annotation to the page + page.Annotations.Add(annot); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Redaction/Redaction-without-fill-color-and-appearance/.NET/Redaction-without-fill-color-and-appearance/Program.cs b/Redaction/Redaction-without-fill-color-and-appearance/.NET/Redaction-without-fill-color-and-appearance/Program.cs index a63a76b5..6006f23b 100644 --- a/Redaction/Redaction-without-fill-color-and-appearance/.NET/Redaction-without-fill-color-and-appearance/Program.cs +++ b/Redaction/Redaction-without-fill-color-and-appearance/.NET/Redaction-without-fill-color-and-appearance/Program.cs @@ -1,34 +1,23 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Get the first page from the document. -PdfLoadedPage page = document.Pages[0] as PdfLoadedPage; - -//Create a PDF redaction for the page. -PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17)); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page from the document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Add a redaction object into the redaction collection of loaded page. -page.AddRedaction(redaction); + //Create a PDF redaction for the page. + PdfRedaction redaction = new PdfRedaction(new RectangleF(343, 147, 60, 17)); -//Redact the contents from the PDF document. -document.Redact(); + //Add a redaction object into the redaction collection of loaded page. + page.AddRedaction(redaction); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Redact the contents from the PDF document. + loadedDocument.Redact(); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs index e8307093..7db46273 100644 --- a/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs +++ b/Redaction/Removing-sensitive-content-from-the-PDF-document/.NET/Removing-sensitive-content-from-the-PDF-document/Program.cs @@ -1,28 +1,19 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Redaction; -//Create stream from an existing PDF document. -using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Load the PDF document from stream - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream)) - { - PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - //Create a PDF redaction for the page - PdfRedaction redaction = new PdfRedaction(new RectangleF(340, 120, 140, 20), Color.Black); - //Add a redaction object into the redaction collection of loaded page. - loadedPage.AddRedaction(redaction); - //Redact the contents from the PDF document. - loadedDocument.Redact(); + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Create a PDF redaction for the page + PdfRedaction redaction = new PdfRedaction(new RectangleF(340, 120, 140, 20), Color.Black); + //Add a redaction object into the redaction collection of loaded page. + loadedPage.AddRedaction(redaction); + //Redact the contents from the PDF document. + loadedDocument.Redact(); - //Save the redacted PDF document to the memory stream - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - loadedDocument.Save(outputFileStream); - } - } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Save-PDF-file/To AWS S3/HelloWorld/Program.cs b/Save-PDF-file/To AWS S3/HelloWorld/Program.cs index f285de00..4a0070b9 100644 --- a/Save-PDF-file/To AWS S3/HelloWorld/Program.cs +++ b/Save-PDF-file/To AWS S3/HelloWorld/Program.cs @@ -17,12 +17,8 @@ // Draw text on the page graphics.DrawString("Hello, Syncfusion PDF!", new PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Black, new PointF(10, 10)); - // Save the PDF to a stream - MemoryStream stream = new MemoryStream(); - document.Save(stream); - - // Save the stream to a file (optional) - File.WriteAllBytes("HelloWorld.pdf", stream.ToArray()); + // Save the PDF document + document.Save("HelloWorld.pdf"); // Upload the PDF to AWS S3 (see next step) diff --git a/Save-PDF-file/To Azure Blob Storage/HelloWorld/Program.cs b/Save-PDF-file/To Azure Blob Storage/HelloWorld/Program.cs index 60e48a1e..33f33d76 100644 --- a/Save-PDF-file/To Azure Blob Storage/HelloWorld/Program.cs +++ b/Save-PDF-file/To Azure Blob Storage/HelloWorld/Program.cs @@ -18,8 +18,6 @@ // Create a memory stream to save the PDF document MemoryStream stream = new MemoryStream(); doc.Save(stream); - // Write the contents of the memory stream to a file named "sample.pdf" - File.WriteAllBytes("sample.pdf", stream.ToArray()); // Close the document doc.Close(true); } diff --git a/Split PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs b/Split PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs index 41ba0f5e..6e6616ae 100644 --- a/Split PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs +++ b/Split PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs @@ -1,13 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Creates a new document. PdfDocument document = new PdfDocument(); @@ -15,12 +10,8 @@ //Imports the page at 1 from the lDoc. document.ImportPageRange(loadedDocument, 0, loadedDocument.Pages.Count - 1); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document to file stream. +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the documents. loadedDocument.Close(true); diff --git a/Split PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs b/Split PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs index 78cd9f5b..a15865e2 100644 --- a/Split PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs +++ b/Split PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs @@ -1,33 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); - //Load the first PDF document. -PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(docStream1); - -//Get stream from an existing PDF document. -FileStream docStream2 = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read); - +using (PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf"))) //Load the PDF document. -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(docStream2); - -//Creates the new document. -PdfDocument document = new PdfDocument(); +using (PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf"))) +{ + //Creates the new document. + PdfDocument document = new PdfDocument(); -//Imports and arranges the pages. -document.ImportPage(loadedDocument1, 1); -document.ImportPage(loadedDocument2, 0); + //Imports and arranges the pages. + document.ImportPage(loadedDocument1, 1); + document.ImportPage(loadedDocument2, 0); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ //Save the PDF document to file stream. - document.Save(outputFileStream); -} + document.Save(Path.GetFullPath(@"Output/Output.pdf")); -//Close the document. -document.Close(true); \ No newline at end of file + //Close the document. + document.Close(true); +} \ No newline at end of file diff --git a/Split PDFs/Import-tagged-structure-when-splitting-PDF-documents/.NET/Import-tagged-structure-when-splitting-PDF-documents/Program.cs b/Split PDFs/Import-tagged-structure-when-splitting-PDF-documents/.NET/Import-tagged-structure-when-splitting-PDF-documents/Program.cs index ae9a94d2..69b58365 100644 --- a/Split PDFs/Import-tagged-structure-when-splitting-PDF-documents/.NET/Import-tagged-structure-when-splitting-PDF-documents/Program.cs +++ b/Split PDFs/Import-tagged-structure-when-splitting-PDF-documents/.NET/Import-tagged-structure-when-splitting-PDF-documents/Program.cs @@ -8,7 +8,7 @@ internal class Program static void Main(string[] args) { //Load an existing PDF file. - PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open)); + PdfLoadedDocument loadDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Subscribe to the document split event. loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent; void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args) diff --git a/Split PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs b/Split PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs index d9607dac..6877376c 100644 --- a/Split PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs +++ b/Split PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs @@ -1,13 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Creates a new document. PdfDocument document = new PdfDocument(); @@ -15,12 +10,8 @@ //Imports the page at 1 from the loaded document. document.ImportPage(loadedDocument, 1); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the documents. loadedDocument.Close(); diff --git a/Split PDFs/Password-Protect-Split-PDF/.NET/Password-Protect-Split-PDF/Program.cs b/Split PDFs/Password-Protect-Split-PDF/.NET/Password-Protect-Split-PDF/Program.cs index db9dafe1..abacf11c 100644 --- a/Split PDFs/Password-Protect-Split-PDF/.NET/Password-Protect-Split-PDF/Program.cs +++ b/Split PDFs/Password-Protect-Split-PDF/.NET/Password-Protect-Split-PDF/Program.cs @@ -1,11 +1,9 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; -// Create the FileStream object. -using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +// Create a PdfLoadedDocument object +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream,"password")) { - // Create a PdfLoadedDocument object from the FileStream object - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream,"password"); // Iterate over the pages in the PdfLoadedDocument object for (int pageIndex = 0; pageIndex < loadedDocument.PageCount; pageIndex++) { @@ -14,11 +12,8 @@ { // Import the page from the PdfLoadedDocument object to the PdfDocument object outputDocument.ImportPage(loadedDocument, pageIndex); - //Save the document into a filestream object. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output" + pageIndex + ".pdf"), FileMode.Create, FileAccess.Write)) - { - outputDocument.Save(outputFileStream); - } + //Save the document + outputDocument.Save(Path.GetFullPath(@"Output/Output" + pageIndex + ".pdf")); } } } \ No newline at end of file diff --git a/Split PDFs/Rearrange-Page-and-Split/.NET/Rearrange-Page-and-Split/Program.cs b/Split PDFs/Rearrange-Page-and-Split/.NET/Rearrange-Page-and-Split/Program.cs index f7061cac..5761891c 100644 --- a/Split PDFs/Rearrange-Page-and-Split/.NET/Rearrange-Page-and-Split/Program.cs +++ b/Split PDFs/Rearrange-Page-and-Split/.NET/Rearrange-Page-and-Split/Program.cs @@ -3,19 +3,17 @@ using Syncfusion.Pdf.Parsing; //Load the PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Rearrange the page by index loadedDocument.Pages.ReArrange(new int[] { 1,0,3,2 }); // The document will contain minimum 4 pages of the input PDF document. -using (var outputDocument = new PdfDocument()) +using (PdfDocument outputDocument = new PdfDocument()) { //Import the pages to the new PDF document. outputDocument.ImportPageRange(loadedDocument, 0, 3); - //Save the document into a filestream object. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - outputDocument.Save(outputFileStream); - } + //Save the document + outputDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } +//Close the document +loadedDocument.Close(true); diff --git a/Split PDFs/Remove-Unused-Resources-when-Splitting-PDF-Documents/.NET/Remove-Unused-Resources-when-Splitting-PDF-Documents/Program.cs b/Split PDFs/Remove-Unused-Resources-when-Splitting-PDF-Documents/.NET/Remove-Unused-Resources-when-Splitting-PDF-Documents/Program.cs index 244163f9..e85016cc 100644 --- a/Split PDFs/Remove-Unused-Resources-when-Splitting-PDF-Documents/.NET/Remove-Unused-Resources-when-Splitting-PDF-Documents/Program.cs +++ b/Split PDFs/Remove-Unused-Resources-when-Splitting-PDF-Documents/.NET/Remove-Unused-Resources-when-Splitting-PDF-Documents/Program.cs @@ -8,7 +8,7 @@ internal class Program static void Main(string[] args) { //Load the existing PDF file. - PdfLoadedDocument loadDocument = new PdfLoadedDocument(new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open)); + PdfLoadedDocument loadDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Subscribe to the document split event. loadDocument.DocumentSplitEvent += LoadDocument_DocumentSplitEvent; void LoadDocument_DocumentSplitEvent(object sender, PdfDocumentSplitEventArgs args) diff --git a/Split PDFs/Rotate-PDF-and-Split/.NET/Rotate-PDF-and-Split/Program.cs b/Split PDFs/Rotate-PDF-and-Split/.NET/Rotate-PDF-and-Split/Program.cs index 877b08d0..19b173fc 100644 --- a/Split PDFs/Rotate-PDF-and-Split/.NET/Rotate-PDF-and-Split/Program.cs +++ b/Split PDFs/Rotate-PDF-and-Split/.NET/Rotate-PDF-and-Split/Program.cs @@ -1,25 +1,20 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; - //Load the PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); for (int pageIndex = 0;pageIndex data = new List(); -object row = new { Name = "abc", Age = "21", Sex = "Male" }; -data.Add(row); + //Add values to the list. + List data = new List(); + object row = new { Name = "abc", Age = "21", Sex = "Male" }; + data.Add(row); -//Add list to IEnumerable. -IEnumerable table = data; + //Add list to IEnumerable. + IEnumerable table = data; -//Assign data source. -pdfLightTable.DataSource = table; + //Assign data source. + pdfLightTable.DataSource = table; -//Draw PdfLightTable. -pdfLightTable.Draw(graphics, new Syncfusion.Drawing.PointF(0, 0)); + //Draw PdfLightTable. + pdfLightTable.Draw(graphics, new Syncfusion.Drawing.PointF(0, 0)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfLightTable/Customize-the-table-cell-in-PDF-document/.NET/Customize-the-table-cell-in-PDF-document/Program.cs b/Table/PdfLightTable/Customize-the-table-cell-in-PDF-document/.NET/Customize-the-table-cell-in-PDF-document/Program.cs index 09d9fa2f..8706b165 100644 --- a/Table/PdfLightTable/Customize-the-table-cell-in-PDF-document/.NET/Customize-the-table-cell-in-PDF-document/Program.cs +++ b/Table/PdfLightTable/Customize-the-table-cell-in-PDF-document/.NET/Customize-the-table-cell-in-PDF-document/Program.cs @@ -1,59 +1,51 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Tables; using System.Data.Common; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); - -//Create a PdfLightTable. -PdfLightTable pdfLightTable = new PdfLightTable(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Set the DataSourceType as Direct. -pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; + //Create a PdfLightTable. + PdfLightTable pdfLightTable = new PdfLightTable(); -//Create columns. -pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); -pdfLightTable.Columns.Add(new PdfColumn("Name")); -pdfLightTable.Columns.Add(new PdfColumn("Class")); + //Set the DataSourceType as Direct. + pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; -//Add Rows. -pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); -pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); + //Create columns. + pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); + pdfLightTable.Columns.Add(new PdfColumn("Name")); + pdfLightTable.Columns.Add(new PdfColumn("Class")); -//Create the font for setting the style. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Add Rows. + pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); + pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); -//Declare and define the alternate style. -PdfCellStyle altStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.Green); -altStyle.BackgroundBrush = PdfBrushes.DarkGray; + //Create the font for setting the style. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Declare and define the header style. -PdfCellStyle headerStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.Brown); -headerStyle.BackgroundBrush = PdfBrushes.Red; + //Declare and define the alternate style. + PdfCellStyle altStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.Green); + altStyle.BackgroundBrush = PdfBrushes.DarkGray; -//Set the alternate and header style to table. -pdfLightTable.Style.AlternateStyle = altStyle; -pdfLightTable.Style.HeaderStyle = headerStyle; + //Declare and define the header style. + PdfCellStyle headerStyle = new PdfCellStyle(font, PdfBrushes.White, PdfPens.Brown); + headerStyle.BackgroundBrush = PdfBrushes.Red; -//Show header in the table. -pdfLightTable.Style.ShowHeader = true; + //Set the alternate and header style to table. + pdfLightTable.Style.AlternateStyle = altStyle; + pdfLightTable.Style.HeaderStyle = headerStyle; -//Draw the PdfLightTable. -pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); + //Show header in the table. + pdfLightTable.Style.ShowHeader = true; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Draw the PdfLightTable. + pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); -//Close the document. -document.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfLightTable/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs b/Table/PdfLightTable/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs index 29946d50..39b7a3b6 100644 --- a/Table/PdfLightTable/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs +++ b/Table/PdfLightTable/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs @@ -1,56 +1,48 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Tables; +using Syncfusion.Pdf.Tables; using Syncfusion.Pdf; using Syncfusion.Drawing; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create a PdfLightTable. -PdfLightTable pdfLightTable = new PdfLightTable(); + //Create a PdfLightTable. + PdfLightTable pdfLightTable = new PdfLightTable(); -//Add values to the list. -List data = new List(); -object row = new { Name = "abc", Age = "21", Sex = "Male" }; -data.Add(row); + //Add values to the list. + List data = new List(); + object row = new { Name = "abc", Age = "21", Sex = "Male" }; + data.Add(row); -//Add list to IEnumerable. -IEnumerable table = data; + //Add list to IEnumerable. + IEnumerable table = data; -//Assign data source. -pdfLightTable.DataSource = table; + //Assign data source. + pdfLightTable.DataSource = table; -//Declare and define light table style. -PdfLightTableStyle lightTableStyle = new PdfLightTableStyle(); + //Declare and define light table style. + PdfLightTableStyle lightTableStyle = new PdfLightTableStyle(); -//Set cell padding, which specifies the space between the border and content of the cell. -lightTableStyle.CellPadding = 2; + //Set cell padding, which specifies the space between the border and content of the cell. + lightTableStyle.CellPadding = 2; -//Set cell spacing, which specifies the space between the adjacent cells. -lightTableStyle.CellSpacing = 2; + //Set cell spacing, which specifies the space between the adjacent cells. + lightTableStyle.CellSpacing = 2; -//Sets to show header in the table. -lightTableStyle.ShowHeader = true; + //Sets to show header in the table. + lightTableStyle.ShowHeader = true; -//Sets to repeat the header on each page. -lightTableStyle.RepeatHeader = true; + //Sets to repeat the header on each page. + lightTableStyle.RepeatHeader = true; -//Apply style. -pdfLightTable.Style = lightTableStyle; + //Apply style. + pdfLightTable.Style = lightTableStyle; -//Draw PdfLightTable. -pdfLightTable.Draw(page, new PointF(0, 0)); + //Draw PdfLightTable. + pdfLightTable.Draw(page, new PointF(0, 0)); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); \ No newline at end of file diff --git a/Table/PdfLightTable/Draw-graphics-element-in-particular-cell/.NET/Draw-graphics-element-in-particular-cell/Program.cs b/Table/PdfLightTable/Draw-graphics-element-in-particular-cell/.NET/Draw-graphics-element-in-particular-cell/Program.cs index 488d3cdc..4566f41b 100644 --- a/Table/PdfLightTable/Draw-graphics-element-in-particular-cell/.NET/Draw-graphics-element-in-particular-cell/Program.cs +++ b/Table/PdfLightTable/Draw-graphics-element-in-particular-cell/.NET/Draw-graphics-element-in-particular-cell/Program.cs @@ -1,51 +1,42 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Tables; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create a PdfLightTable -PdfLightTable pdfLightTable = new PdfLightTable(); + //Create a PdfLightTable + PdfLightTable pdfLightTable = new PdfLightTable(); -//Set the DataSourceType as Direct. -pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; + //Set the DataSourceType as Direct. + pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; -//Create columns. -pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); -pdfLightTable.Columns.Add(new PdfColumn("Name")); -pdfLightTable.Columns.Add(new PdfColumn("Class")); + //Create columns. + pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); + pdfLightTable.Columns.Add(new PdfColumn("Name")); + pdfLightTable.Columns.Add(new PdfColumn("Class")); -//Add rows. -pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); -pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); + //Add rows. + pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); + pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); -//Subscribing to events. -pdfLightTable.BeginCellLayout += PdfLightTable_BeginCellLayout; -pdfLightTable.EndCellLayout += PdfLightTable_EndCellLayout; + //Subscribing to events. + pdfLightTable.BeginCellLayout += PdfLightTable_BeginCellLayout; + pdfLightTable.EndCellLayout += PdfLightTable_EndCellLayout; -//Show the table header. -pdfLightTable.Style.ShowHeader = true; + //Show the table header. + pdfLightTable.Style.ShowHeader = true; -//Draw the PdfLightTable. -pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); + //Draw the PdfLightTable. + pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - - void PdfLightTable_EndCellLayout(object sender, EndCellLayoutEventArgs args) { if (args.RowIndex == 0 && args.CellIndex == 0) diff --git a/Table/PdfLightTable/Paginate-table-in-a-PDF-document/.NET/Paginate-table-in-a-PDF-document/Program.cs b/Table/PdfLightTable/Paginate-table-in-a-PDF-document/.NET/Paginate-table-in-a-PDF-document/Program.cs index 00f12f53..068997e5 100644 --- a/Table/PdfLightTable/Paginate-table-in-a-PDF-document/.NET/Paginate-table-in-a-PDF-document/Program.cs +++ b/Table/PdfLightTable/Paginate-table-in-a-PDF-document/.NET/Paginate-table-in-a-PDF-document/Program.cs @@ -1,52 +1,44 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Tables; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create a PdfLightTable. -PdfLightTable pdfLightTable = new PdfLightTable(); + //Create a PdfLightTable. + PdfLightTable pdfLightTable = new PdfLightTable(); -//Add values to list. -List data = new List(); + //Add values to list. + List data = new List(); -//you can add multiple rows -Object row = new { Name = "abc", Age = "21", Sex = "Male" }; + //you can add multiple rows + Object row = new { Name = "abc", Age = "21", Sex = "Male" }; -for(int i = 0; i < 500; i++) -data.Add(row); + for (int i = 0; i < 500; i++) + data.Add(row); -//Add list to IEnumerable. -IEnumerable table = data; + //Add list to IEnumerable. + IEnumerable table = data; -//Assign data source. -pdfLightTable.DataSource = table; + //Assign data source. + pdfLightTable.DataSource = table; -//Set properties to paginate the table. -PdfLightTableLayoutFormat layoutFormat = new PdfLightTableLayoutFormat(); -layoutFormat.Break = PdfLayoutBreakType.FitPage; -layoutFormat.Layout = PdfLayoutType.Paginate; + //Set properties to paginate the table. + PdfLightTableLayoutFormat layoutFormat = new PdfLightTableLayoutFormat(); + layoutFormat.Break = PdfLayoutBreakType.FitPage; + layoutFormat.Layout = PdfLayoutType.Paginate; -//Set to view the table header. -pdfLightTable.Style.ShowHeader = true; + //Set to view the table header. + pdfLightTable.Style.ShowHeader = true; -//Draw PdfLightTable. -pdfLightTable.Draw(page, new Syncfusion.Drawing.PointF(0, 0), layoutFormat); + //Draw PdfLightTable. + pdfLightTable.Draw(page, new Syncfusion.Drawing.PointF(0, 0), layoutFormat); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Table/PdfLightTable/Row-customization-of-the-table-in-PDF-document/.NET/Row-customization-of-the-table-in-PDF-document/Program.cs b/Table/PdfLightTable/Row-customization-of-the-table-in-PDF-document/.NET/Row-customization-of-the-table-in-PDF-document/Program.cs index ac236ca5..8b17420d 100644 --- a/Table/PdfLightTable/Row-customization-of-the-table-in-PDF-document/.NET/Row-customization-of-the-table-in-PDF-document/Program.cs +++ b/Table/PdfLightTable/Row-customization-of-the-table-in-PDF-document/.NET/Row-customization-of-the-table-in-PDF-document/Program.cs @@ -1,49 +1,41 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Tables; +using Syncfusion.Pdf.Tables; using Syncfusion.Pdf; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Create a PdfLightTable. -PdfLightTable pdfLightTable = new PdfLightTable(); + //Create a PdfLightTable. + PdfLightTable pdfLightTable = new PdfLightTable(); -//Set the DataSourceType as Direct. -pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; + //Set the DataSourceType as Direct. + pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; -//Create columns. -pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); -pdfLightTable.Columns.Add(new PdfColumn("Name")); -pdfLightTable.Columns.Add(new PdfColumn("Class")); + //Create columns. + pdfLightTable.Columns.Add(new PdfColumn("Roll Number")); + pdfLightTable.Columns.Add(new PdfColumn("Name")); + pdfLightTable.Columns.Add(new PdfColumn("Class")); -//Add rows. -pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); -pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); -pdfLightTable.Rows.Add(new object[] { "113", "john", "III" }); -pdfLightTable.Rows.Add(new object[] { "114", "peter", "III" }); + //Add rows. + pdfLightTable.Rows.Add(new object[] { "111", "Maxim", "III" }); + pdfLightTable.Rows.Add(new object[] { "112", "Minim", "III" }); + pdfLightTable.Rows.Add(new object[] { "113", "john", "III" }); + pdfLightTable.Rows.Add(new object[] { "114", "peter", "III" }); -//Subscribe to events. -pdfLightTable.BeginRowLayout += pdfLightTable_BeginRowLayout; -pdfLightTable.EndRowLayout += pdfLightTable_EndRowLayout; + //Subscribe to events. + pdfLightTable.BeginRowLayout += pdfLightTable_BeginRowLayout; + pdfLightTable.EndRowLayout += pdfLightTable_EndRowLayout; -//Draw the PdfLightTable. -pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); + //Draw the PdfLightTable. + pdfLightTable.Draw(page, Syncfusion.Drawing.PointF.Empty); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - void pdfLightTable_EndRowLayout(object sender, EndRowLayoutEventArgs args) { diff --git a/Text Extraction/Extract-collection-of-words-from-PDF-document/.NET/Extract-collection-of-words-from-PDF-document/Program.cs b/Text Extraction/Extract-collection-of-words-from-PDF-document/.NET/Extract-collection-of-words-from-PDF-document/Program.cs index cf8dfd20..18db2f1f 100644 --- a/Text Extraction/Extract-collection-of-words-from-PDF-document/.NET/Extract-collection-of-words-from-PDF-document/Program.cs +++ b/Text Extraction/Extract-collection-of-words-from-PDF-document/.NET/Extract-collection-of-words-from-PDF-document/Program.cs @@ -1,37 +1,33 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the first page of the loaded PDF document. -PdfPageBase page = loadedDocument.Pages[0]; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the loaded PDF document. + PdfPageBase page = loadedDocument.Pages[0]; -//Create the text collection. -var lineCollection = new TextLineCollection(); + //Create the text collection. + var lineCollection = new TextLineCollection(); -// Extract text from the first page. -string extractedText = page.ExtractText(out lineCollection); + // Extract text from the first page. + string extractedText = page.ExtractText(out lineCollection); -// Gets each line from the collection. -foreach (var line in lineCollection.TextLine) -{ + // Gets each line from the collection. + foreach (var line in lineCollection.TextLine) + { - //Gets bounds of the line. - RectangleF lineBounds = line.Bounds; + //Gets bounds of the line. + RectangleF lineBounds = line.Bounds; - //Gets text in the line. - string text = line.Text; + //Gets text in the line. + string text = line.Text; - //Gets collection of the words in the line. - List textWordCollection = line.WordCollection; -} + //Gets collection of the words in the line. + List textWordCollection = line.WordCollection; + } -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Text Extraction/Extract-each-lines-from-an-existing-PDF-document/.NET/Extract-each-lines-from-an-existing-PDF-document/Program.cs b/Text Extraction/Extract-each-lines-from-an-existing-PDF-document/.NET/Extract-each-lines-from-an-existing-PDF-document/Program.cs index 030716e3..31315a5f 100644 --- a/Text Extraction/Extract-each-lines-from-an-existing-PDF-document/.NET/Extract-each-lines-from-an-existing-PDF-document/Program.cs +++ b/Text Extraction/Extract-each-lines-from-an-existing-PDF-document/.NET/Extract-each-lines-from-an-existing-PDF-document/Program.cs @@ -1,34 +1,30 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Get the first page of the loaded PDF document -PdfPageBase page = loadedDocument.Pages[0]; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the loaded PDF document + PdfPageBase page = loadedDocument.Pages[0]; -//Create line collection. -var lineCollection = new TextLineCollection(); + //Create line collection. + TextLineCollection lineCollection = new TextLineCollection(); -//Extract text from the first page -string extractedText = page.ExtractText(out lineCollection); + //Extract text from the first page + string extractedText = page.ExtractText(out lineCollection); -//Gets each line from the collection -foreach (var line in lineCollection.TextLine) -{ + //Gets each line from the collection + foreach (var line in lineCollection.TextLine) + { - //Gets bounds of the line - RectangleF lineBounds = line.Bounds; + //Gets bounds of the line + RectangleF lineBounds = line.Bounds; - // Gets text in the line - string text = line.Text; -} + // Gets text in the line + string text = line.Text; + } -//Close the PDF document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Text Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document/Program.cs b/Text Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document/Program.cs index b1caf280..bdb97ab8 100644 --- a/Text Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document/Program.cs +++ b/Text Extraction/Extract-text-from-the-entire-PDF-document/.NET/Extract-text-from-the-entire-PDF-document/Program.cs @@ -1,24 +1,17 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -// Open existing PDF document stream. -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the PDF document. - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream)) - { - string extractedText = string.Empty; - - // Extract all text from PDF document pages. - foreach (PdfLoadedPage page in loadedDocument.Pages) - { - extractedText += page.ExtractText(); - } + string extractedText = string.Empty; - //Write the extracted text in console window. - Console.WriteLine("Extracted text from the entire document: " + extractedText); - Console.ReadLine(); + // Extract all text from PDF document pages. + foreach (PdfLoadedPage page in loadedDocument.Pages) + { + extractedText += page.ExtractText(); } -} \ No newline at end of file + + //Write the extracted text in console window. + Console.WriteLine("Extracted text from the entire document: " + extractedText); +} diff --git a/Text Extraction/Extract-the-text-with-layout-in-a-PDF-document/.NET/Extract-the-text-with-layout-in-a-PDF-document/Program.cs b/Text Extraction/Extract-the-text-with-layout-in-a-PDF-document/.NET/Extract-the-text-with-layout-in-a-PDF-document/Program.cs index 4d5db10d..08165c47 100644 --- a/Text Extraction/Extract-the-text-with-layout-in-a-PDF-document/.NET/Extract-the-text-with-layout-in-a-PDF-document/Program.cs +++ b/Text Extraction/Extract-the-text-with-layout-in-a-PDF-document/.NET/Extract-the-text-with-layout-in-a-PDF-document/Program.cs @@ -1,22 +1,14 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load first page. -PdfPageBase page = loadedDocument.Pages[0]; - -//Extract text from first page. -string extractedTexts = page.ExtractText(true); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load first page. + PdfPageBase page = loadedDocument.Pages[0]; -//Close the document. -loadedDocument.Close(true); + //Extract text from first page. + string extractedTexts = page.ExtractText(true); -Console.WriteLine("Extracted text: " + extractedTexts); -Console.ReadLine(); \ No newline at end of file + Console.WriteLine("Extracted text: " + extractedTexts); +} \ No newline at end of file diff --git a/Text Extraction/Extract-the-texts-from-a-page-in-the-PDF-document/.NET/Extract-the-texts-from-a-page-in-the-PDF-document/Program.cs b/Text Extraction/Extract-the-texts-from-a-page-in-the-PDF-document/.NET/Extract-the-texts-from-a-page-in-the-PDF-document/Program.cs index 673a9b79..62f5af7c 100644 --- a/Text Extraction/Extract-the-texts-from-a-page-in-the-PDF-document/.NET/Extract-the-texts-from-a-page-in-the-PDF-document/Program.cs +++ b/Text Extraction/Extract-the-texts-from-a-page-in-the-PDF-document/.NET/Extract-the-texts-from-a-page-in-the-PDF-document/Program.cs @@ -1,23 +1,15 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the first page. -PdfPageBase page = loadedDocument.Pages[0]; - -//Extract text from first page. -string extractedText = page.ExtractText(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the first page. + PdfPageBase page = loadedDocument.Pages[0]; -//Close the document. -loadedDocument.Close(true); + //Extract text from first page. + string extractedText = page.ExtractText(); -//Write the extracted lines in console window. -Console.WriteLine("Extracted Text: " + extractedText); -Console.ReadLine(); + //Write the extracted lines in console window. + Console.WriteLine("Extracted Text: " + extractedText); +} diff --git a/Text Extraction/Get-text-glyph-details-from-extract-text/.NET/Get-text-glyph-details-from-extract-text/Program.cs b/Text Extraction/Get-text-glyph-details-from-extract-text/.NET/Get-text-glyph-details-from-extract-text/Program.cs index 5cc96b09..143fdb0f 100644 --- a/Text Extraction/Get-text-glyph-details-from-extract-text/.NET/Get-text-glyph-details-from-extract-text/Program.cs +++ b/Text Extraction/Get-text-glyph-details-from-extract-text/.NET/Get-text-glyph-details-from-extract-text/Program.cs @@ -2,37 +2,34 @@ using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); -//Get the first page of the loaded PDF document -PdfPageBase page = loadedDocument.Pages[0]; -TextLineCollection lineCollection = new TextLineCollection(); -//Extract text from the first page -string m_extractedText = page.ExtractText(out lineCollection); -//Gets specific line from the collection -TextLine line = lineCollection.TextLine[0]; -//Gets collection of the words in the line -List textWordCollection = line.WordCollection; -//Gets word from the collection using index -TextWord textWord = textWordCollection[0]; -// Gets Glyph details of the word -List textGlyphCollection = textWord.Glyphs; -//Gets character of the word -TextGlyph textGlyph = textGlyphCollection[0]; -//Gets bounds of the character -RectangleF glyphBounds = textGlyph.Bounds; -//Gets font name of the character -string GlyphFontName = textGlyph.FontName; -//Gets font size of the character -float GlyphFontSize = textGlyph.FontSize; -//Gets font style of the character -FontStyle GlyphFontStyle = textGlyph.FontStyle; -//Gets character in the word -char GlyphText = textGlyph.Text; -//Gets the color of the character -Color GlyphColor = textGlyph.TextColor; -//Close the document -loadedDocument.Close(true); \ No newline at end of file +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the loaded PDF document + PdfPageBase page = loadedDocument.Pages[0]; + TextLineCollection lineCollection = new TextLineCollection(); + //Extract text from the first page + string m_extractedText = page.ExtractText(out lineCollection); + //Gets specific line from the collection + TextLine line = lineCollection.TextLine[0]; + //Gets collection of the words in the line + List textWordCollection = line.WordCollection; + //Gets word from the collection using index + TextWord textWord = textWordCollection[0]; + // Gets Glyph details of the word + List textGlyphCollection = textWord.Glyphs; + //Gets character of the word + TextGlyph textGlyph = textGlyphCollection[0]; + //Gets bounds of the character + RectangleF glyphBounds = textGlyph.Bounds; + //Gets font name of the character + string GlyphFontName = textGlyph.FontName; + //Gets font size of the character + float GlyphFontSize = textGlyph.FontSize; + //Gets font style of the character + FontStyle GlyphFontStyle = textGlyph.FontStyle; + //Gets character in the word + char GlyphText = textGlyph.Text; + //Gets the color of the character + Color GlyphColor = textGlyph.TextColor; +} \ No newline at end of file diff --git a/Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document/Program.cs b/Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document/Program.cs index 97875510..e48086bb 100644 --- a/Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document/Program.cs +++ b/Watermark/Add-text-watermark-in-an-existing-PDF-document/.NET/Add-text-watermark-in-an-existing-PDF-document/Program.cs @@ -1,47 +1,37 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -// Create FileStream object to read the input PDF file -using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Load the PDF document from the input stream - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream)) - { - // Get the first page of the PDF document - PdfPageBase loadedPage = loadedDocument.Pages[0]; - - // Create a PDF font to add a watermark text. - PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 32); - - // Measure the watermark text and get the size - string watermarkText = "Created using Syncfusion PDF library"; - SizeF watermarkTextSize = font.MeasureString(watermarkText); - - // Move the graphics to the center of the page - loadedPage.Graphics.Save(); - loadedPage.Graphics.TranslateTransform(loadedPage.Size.Width / 2, loadedPage.Size.Height / 2); - - // Rotate the graphics to 45 degrees - loadedPage.Graphics.RotateTransform(-45); - - //Set transparency - loadedPage.Graphics.SetTransparency(0.25f); - - // Draw the watermark text - loadedPage.Graphics.DrawString(watermarkText, font, PdfBrushes.Red, new PointF(-watermarkTextSize.Width / 2, -watermarkTextSize.Height / 2)); - - // Restore the graphics - loadedPage.Graphics.Restore(); - - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - } + // Get the first page of the PDF document + PdfPageBase loadedPage = loadedDocument.Pages[0]; + + // Create a PDF font to add a watermark text. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 32); + + // Measure the watermark text and get the size + string watermarkText = "Created using Syncfusion PDF library"; + SizeF watermarkTextSize = font.MeasureString(watermarkText); + + // Move the graphics to the center of the page + loadedPage.Graphics.Save(); + loadedPage.Graphics.TranslateTransform(loadedPage.Size.Width / 2, loadedPage.Size.Height / 2); + + // Rotate the graphics to 45 degrees + loadedPage.Graphics.RotateTransform(-45); + + //Set transparency + loadedPage.Graphics.SetTransparency(0.25f); + + // Draw the watermark text + loadedPage.Graphics.DrawString(watermarkText, font, PdfBrushes.Red, new PointF(-watermarkTextSize.Width / 2, -watermarkTextSize.Height / 2)); + + // Restore the graphics + loadedPage.Graphics.Restore(); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Watermark/Adding-image-watermark-in-PDF-document/.NET/Adding-image-watermark-in-PDF-document/Program.cs b/Watermark/Adding-image-watermark-in-PDF-document/.NET/Adding-image-watermark-in-PDF-document/Program.cs index d51767ba..8c097560 100644 --- a/Watermark/Adding-image-watermark-in-PDF-document/.NET/Adding-image-watermark-in-PDF-document/Program.cs +++ b/Watermark/Adding-image-watermark-in-PDF-document/.NET/Adding-image-watermark-in-PDF-document/Program.cs @@ -1,39 +1,32 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add a page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Create graphics for PDF page. -PdfGraphics graphics = pdfPage.Graphics; + //Create graphics for PDF page. + PdfGraphics graphics = pdfPage.Graphics; -//Load the image as stream. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/design.png"), FileMode.Open, FileAccess.Read); + //Load the image as stream. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/design.png"), FileMode.Open, FileAccess.Read); -//Image watermark. -PdfImage image = new PdfBitmap(imageStream); + //Image watermark. + PdfImage image = new PdfBitmap(imageStream); -//Create state for page graphics. -PdfGraphicsState state = graphics.Save(); + //Create state for page graphics. + PdfGraphicsState state = graphics.Save(); -//Set transparency for page graphics. -graphics.SetTransparency(0.25f); + //Set transparency for page graphics. + graphics.SetTransparency(0.25f); -//Draw image in the page. -graphics.DrawImage(image, new PointF(0, 0), pdfPage.Graphics.ClientSize); + //Draw image in the page. + graphics.DrawImage(image, new PointF(0, 0), pdfPage.Graphics.ClientSize); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDocument.Close(true); diff --git a/Watermark/Adding-text-watermark-in-PDF-document/.NET/Adding-text-watermark-in-PDF-document/Program.cs b/Watermark/Adding-text-watermark-in-PDF-document/.NET/Adding-text-watermark-in-PDF-document/Program.cs index 7ac65a8e..eed88a67 100644 --- a/Watermark/Adding-text-watermark-in-PDF-document/.NET/Adding-text-watermark-in-PDF-document/Program.cs +++ b/Watermark/Adding-text-watermark-in-PDF-document/.NET/Adding-text-watermark-in-PDF-document/Program.cs @@ -1,37 +1,29 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add a page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); - -//Create graphics for the PDF page. -PdfGraphics graphics = pdfPage.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Create graphics for the PDF page. + PdfGraphics graphics = pdfPage.Graphics; -//Watermark text. -PdfGraphicsState state = graphics.Save(); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Set the trasparency and rotate transform for the page graphics. -graphics.SetTransparency(0.25f); -graphics.RotateTransform(-40); + //Watermark text. + PdfGraphicsState state = graphics.Save(); -//Draw the text in the PDF document. -graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); + //Set the trasparency and rotate transform for the page graphics. + graphics.SetTransparency(0.25f); + graphics.RotateTransform(-40); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDocument.Save(outputFileStream); -} + //Draw the text in the PDF document. + graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); -//Close the document. -pdfDocument.Close(true); \ No newline at end of file + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Watermark/Draw-the-image-watermark-in-an-existing-PDF-document/.NET/Draw-the-image-watermark-in-an-existing-PDF-document/Program.cs b/Watermark/Draw-the-image-watermark-in-an-existing-PDF-document/.NET/Draw-the-image-watermark-in-an-existing-PDF-document/Program.cs index 67d8d497..6c0fa28e 100644 --- a/Watermark/Draw-the-image-watermark-in-an-existing-PDF-document/.NET/Draw-the-image-watermark-in-an-existing-PDF-document/Program.cs +++ b/Watermark/Draw-the-image-watermark-in-an-existing-PDF-document/.NET/Draw-the-image-watermark-in-an-existing-PDF-document/Program.cs @@ -1,43 +1,32 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the page. -PdfPageBase loadedPage = loadedDocument.Pages[0]; - -//Create graphics for PDF page. -PdfGraphics graphics = loadedPage.Graphics; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfPageBase loadedPage = loadedDocument.Pages[0]; -//Load the image file as stream. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/design.png"), FileMode.Open, FileAccess.Read); + //Create graphics for PDF page. + PdfGraphics graphics = loadedPage.Graphics; -//Load the image file. -PdfImage image = new PdfBitmap(imageStream); + //Load the image file as stream. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/design.png"), FileMode.Open, FileAccess.Read); -//Create state for page graphics. -PdfGraphicsState state = graphics.Save(); + //Load the image file. + PdfImage image = new PdfBitmap(imageStream); -//Set transparency for page graphics. -graphics.SetTransparency(0.25f); + //Create state for page graphics. + PdfGraphicsState state = graphics.Save(); -//Draw image watermark in PDF page. -graphics.DrawImage(image, new PointF(0, 0), loadedPage.Graphics.ClientSize); + //Set transparency for page graphics. + graphics.SetTransparency(0.25f); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); -} + //Draw image watermark in PDF page. + graphics.DrawImage(image, new PointF(0, 0), loadedPage.Graphics.ClientSize); -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Watermark/Removing-watermark-annotation-in-PDF-document/.NET/Remove-watermark-annotation-in-the-PDF-document/Program.cs b/Watermark/Removing-watermark-annotation-in-PDF-document/.NET/Remove-watermark-annotation-in-the-PDF-document/Program.cs index df3b94de..7ddef1de 100644 --- a/Watermark/Removing-watermark-annotation-in-PDF-document/.NET/Remove-watermark-annotation-in-the-PDF-document/Program.cs +++ b/Watermark/Removing-watermark-annotation-in-PDF-document/.NET/Remove-watermark-annotation-in-the-PDF-document/Program.cs @@ -2,28 +2,23 @@ using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Load the PDF document -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -// Iterate through the annotations collection and remove PdfLoadedWatermark annotations -foreach (PdfPageBase page in loadedDocument.Pages) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - for (int i = page.Annotations.Count - 1; i >= 0; i--) + // Iterate through the annotations collection and remove PdfLoadedWatermark annotations + foreach (PdfPageBase page in loadedDocument.Pages) { - // Check if the annotation is a PdfLoadedWatermarkAnnotation - if (page.Annotations[i] is PdfLoadedWatermarkAnnotation) + for (int i = page.Annotations.Count - 1; i >= 0; i--) { - // Remove the PdfLoadedWatermarkAnnotation - page.Annotations.RemoveAt(i); + // Check if the annotation is a PdfLoadedWatermarkAnnotation + if (page.Annotations[i] is PdfLoadedWatermarkAnnotation) + { + // Remove the PdfLoadedWatermarkAnnotation + page.Annotations.RemoveAt(i); + } } } -} -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); diff --git a/ZUGFeRD/Create-ZUGFeRD-compliment-PDF-invoice/.NET/Create-ZUGFeRD-compliment-PDF-invoice/Program.cs b/ZUGFeRD/Create-ZUGFeRD-compliment-PDF-invoice/.NET/Create-ZUGFeRD-compliment-PDF-invoice/Program.cs index a130f2e3..791a97d6 100644 --- a/ZUGFeRD/Create-ZUGFeRD-compliment-PDF-invoice/.NET/Create-ZUGFeRD-compliment-PDF-invoice/Program.cs +++ b/ZUGFeRD/Create-ZUGFeRD-compliment-PDF-invoice/.NET/Create-ZUGFeRD-compliment-PDF-invoice/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; //Create PDF document with PDF/A-3B conformance. @@ -22,12 +20,8 @@ //Add the attachment to the document. document.Attachments.Add(attachment); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document to file stream. +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/ZUGFeRD/Extract-ZUGFeRD-invoice-from-PDF-document/.NET/Extract-ZUGFeRD-invoice-from-PDF-document/Program.cs b/ZUGFeRD/Extract-ZUGFeRD-invoice-from-PDF-document/.NET/Extract-ZUGFeRD-invoice-from-PDF-document/Program.cs index 2f5a0c98..35df4411 100644 --- a/ZUGFeRD/Extract-ZUGFeRD-invoice-from-PDF-document/.NET/Extract-ZUGFeRD-invoice-from-PDF-document/Program.cs +++ b/ZUGFeRD/Extract-ZUGFeRD-invoice-from-PDF-document/.NET/Extract-ZUGFeRD-invoice-from-PDF-document/Program.cs @@ -1,22 +1,15 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Iterates the attachments. -foreach (PdfAttachment attachment in loadedDocument.Attachments) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Extracts the ZUGFeRD invoice attachment and saves it to the disk. - FileStream s = new FileStream(Path.GetFullPath(@"Output/") + attachment.FileName, FileMode.Create, FileAccess.Write); - s.Write(attachment.Data, 0, attachment.Data.Length); - s.Dispose(); -} - -//Close the PDF document. -loadedDocument.Close(true); + //Iterates the attachments. + foreach (PdfAttachment attachment in loadedDocument.Attachments) + { + //Extracts the ZUGFeRD invoice attachment and saves it to the disk. + FileStream s = new FileStream(Path.GetFullPath(@"Output/") + attachment.FileName, FileMode.Create, FileAccess.Write); + s.Write(attachment.Data, 0, attachment.Data.Length); + s.Dispose(); + } +} \ No newline at end of file diff --git a/ZUGFeRD/Factur-X/.NET/Factur-X/Program.cs b/ZUGFeRD/Factur-X/.NET/Factur-X/Program.cs index f21c0951..fa4f17e5 100644 --- a/ZUGFeRD/Factur-X/.NET/Factur-X/Program.cs +++ b/ZUGFeRD/Factur-X/.NET/Factur-X/Program.cs @@ -20,11 +20,8 @@ //Add attachment to PDF document document.Attachments.Add(attachment); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - document.Save(outputFileStream); -} +//Save the PDF document to file stream. +document.Save(Path.GetFullPath(@"Output/Output.pdf")); + //Close the document. document.Close(true);