diff --git a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs index 37c1a081..2c61edff 100644 --- a/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-PDF-document/Program.cs +++ b/Forms/Add-a-textbox-field-to-a-new-PDF-document/.NET/Add-a-textbox-field-to-a-new-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.Graphics; using Syncfusion.Pdf.Interactive; @@ -38,10 +36,6 @@ emailField.ToolTip = "Email address"; pdfDocument.Form.Fields.Add(emailField); - //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")); } \ No newline at end of file diff --git a/Forms/Add-checkbox-field-in-new-PDF-document/.NET/Add-checkbox-field-in-new-PDF-document/Program.cs b/Forms/Add-checkbox-field-in-new-PDF-document/.NET/Add-checkbox-field-in-new-PDF-document/Program.cs index 167bdbfa..aa4b6532 100644 --- a/Forms/Add-checkbox-field-in-new-PDF-document/.NET/Add-checkbox-field-in-new-PDF-document/Program.cs +++ b/Forms/Add-checkbox-field-in-new-PDF-document/.NET/Add-checkbox-field-in-new-PDF-document/Program.cs @@ -1,30 +1,22 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); - -//Create Check Box field. -PdfCheckBoxField checkBoxField = new PdfCheckBoxField(page, "CheckBox"); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Set check box properties. -checkBoxField.ToolTip = "Check Box"; -checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 10, 10); + //Create Check Box field. + PdfCheckBoxField checkBoxField = new PdfCheckBoxField(page, "CheckBox"); -//Add the form field to the document. -document.Form.Fields.Add(checkBoxField); + //Set check box properties. + checkBoxField.ToolTip = "Check Box"; + checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 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); -} + //Add the form field to the document. + document.Form.Fields.Add(checkBoxField); -//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/Forms/Add-complex-script-to-all-the-supported-fields-in-PDF/.NET/Add-complex-script-to-all-the-supported-fields-in-PDF/Program.cs b/Forms/Add-complex-script-to-all-the-supported-fields-in-PDF/.NET/Add-complex-script-to-all-the-supported-fields-in-PDF/Program.cs index adb400e6..aab196f8 100644 --- a/Forms/Add-complex-script-to-all-the-supported-fields-in-PDF/.NET/Add-complex-script-to-all-the-supported-fields-in-PDF/Program.cs +++ b/Forms/Add-complex-script-to-all-the-supported-fields-in-PDF/.NET/Add-complex-script-to-all-the-supported-fields-in-PDF/Program.cs @@ -1,49 +1,41 @@ -// 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(); - -//Add a new PDF page. -PdfPage page = document.Pages.Add(); - -//Create the new PDF text box field. -PdfTextBoxField textField = new PdfTextBoxField(page, "textBox"); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new PDF page. + PdfPage page = document.Pages.Add(); -//Set bounds. -textField.Bounds = new RectangleF(10, 10, 200, 30); + //Create the new PDF text box field. + PdfTextBoxField textField = new PdfTextBoxField(page, "textBox"); -//Set text. -textField.Text = "สวัสดีชาวโลก"; + //Set bounds. + textField.Bounds = new RectangleF(10, 10, 200, 30); -//Get stream from an font file. -FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/tahoma.ttf"), FileMode.Open, FileAccess.Read); + //Set text. + textField.Text = "สวัสดีชาวโลก"; -//Create a new PDF font instance. -PdfFont font = new PdfTrueTypeFont(fontStream, 10); + //Get stream from an font file. + FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/tahoma.ttf"), FileMode.Open, FileAccess.Read); -//Set font. -textField.Font = font; + //Create a new PDF font instance. + PdfFont font = new PdfTrueTypeFont(fontStream, 10); -//Add the text box field to the form collection. -document.Form.Fields.Add(textField); + //Set font. + textField.Font = font; -//Set default appearance as false. -document.Form.SetDefaultAppearance(false); + //Add the text box field to the form collection. + document.Form.Fields.Add(textField); -//Enable complex script layout for form. -document.Form.ComplexScript = true; + //Set default appearance as false. + document.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. - document.Save(outputFileStream); -} + //Enable complex script layout for form. + document.Form.ComplexScript = true; -//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/Forms/Add-listbox-field-in-an-existing-PDF-document/.NET/Add-listbox-field-in-an-existing-PDF-document/Program.cs b/Forms/Add-listbox-field-in-an-existing-PDF-document/.NET/Add-listbox-field-in-an-existing-PDF-document/Program.cs index 99c5145f..af23903d 100644 --- a/Forms/Add-listbox-field-in-an-existing-PDF-document/.NET/Add-listbox-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Add-listbox-field-in-an-existing-PDF-document/.NET/Add-listbox-field-in-an-existing-PDF-document/Program.cs @@ -1,49 +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 document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); - -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Create list box. -PdfListBoxField listBoxField = new PdfListBoxField(loadedPage, "list1"); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Set the properties. -listBoxField.Bounds = new Syncfusion.Drawing.RectangleF(100, 60, 100, 50); + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Add the items to the list box. -listBoxField.Items.Add(new PdfListFieldItem("English", "English")); -listBoxField.Items.Add(new PdfListFieldItem("French", "French")); -listBoxField.Items.Add(new PdfListFieldItem("German", "German")); + //Create list box. + PdfListBoxField listBoxField = new PdfListBoxField(loadedPage, "list1"); -//Select the item. -listBoxField.SelectedIndex = 2; + //Set the properties. + listBoxField.Bounds = new Syncfusion.Drawing.RectangleF(100, 60, 100, 50); -//Set the multi select option. -listBoxField.MultiSelect = true; + //Add the items to the list box. + listBoxField.Items.Add(new PdfListFieldItem("English", "English")); + listBoxField.Items.Add(new PdfListFieldItem("French", "French")); + listBoxField.Items.Add(new PdfListFieldItem("German", "German")); -//Add the list box into PDF document -loadedDocument.Form.Fields.Add(listBoxField); + //Select the item. + listBoxField.SelectedIndex = 2; -//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); -} + //Set the multi select option. + listBoxField.MultiSelect = true; -//Close the document. -loadedDocument.Close(true); + //Add the list box into PDF document + loadedDocument.Form.Fields.Add(listBoxField); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Forms/Add-listbox-field-in-new-PDF-document/.NET/Add-listbox-field-in-new-PDF-document/Program.cs b/Forms/Add-listbox-field-in-new-PDF-document/.NET/Add-listbox-field-in-new-PDF-document/Program.cs index acd3f13e..a3d1fdac 100644 --- a/Forms/Add-listbox-field-in-new-PDF-document/.NET/Add-listbox-field-in-new-PDF-document/Program.cs +++ b/Forms/Add-listbox-field-in-new-PDF-document/.NET/Add-listbox-field-in-new-PDF-document/Program.cs @@ -1,40 +1,32 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Create list box. -PdfListBoxField listBoxField = new PdfListBoxField(page, "list1"); + //Create list box. + PdfListBoxField listBoxField = new PdfListBoxField(page, "list1"); -//Set the properties. -listBoxField.Bounds = new Syncfusion.Drawing.RectangleF(100, 60, 100, 50); + //Set the properties. + listBoxField.Bounds = new Syncfusion.Drawing.RectangleF(100, 60, 100, 50); -//Add the items to the list box. -listBoxField.Items.Add(new PdfListFieldItem("English", "English")); -listBoxField.Items.Add(new PdfListFieldItem("French", "French")); -listBoxField.Items.Add(new PdfListFieldItem("German", "German")); + //Add the items to the list box. + listBoxField.Items.Add(new PdfListFieldItem("English", "English")); + listBoxField.Items.Add(new PdfListFieldItem("French", "French")); + listBoxField.Items.Add(new PdfListFieldItem("German", "German")); -//Select the item. -listBoxField.SelectedIndex = 0; + //Select the item. + listBoxField.SelectedIndex = 0; -//Set the multi select option. -listBoxField.MultiSelect = true; + //Set the multi select option. + listBoxField.MultiSelect = true; -//Add the list box into PDF document -document.Form.Fields.Add(listBoxField); + //Add the list box into PDF document + document.Form.Fields.Add(listBoxField); -//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/Forms/Add-radio-button-in-existing-PDF-document/.NET/Add-radio-button-in-existing-PDF-document/Program.cs b/Forms/Add-radio-button-in-existing-PDF-document/.NET/Add-radio-button-in-existing-PDF-document/Program.cs index ab3a43e5..abc9b427 100644 --- a/Forms/Add-radio-button-in-existing-PDF-document/.NET/Add-radio-button-in-existing-PDF-document/Program.cs +++ b/Forms/Add-radio-button-in-existing-PDF-document/.NET/Add-radio-button-in-existing-PDF-document/Program.cs @@ -1,44 +1,33 @@ -// 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); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a Radio button. -PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(loadedPage, "employeesRadioList"); + //Create a Radio button. + PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(loadedPage, "employeesRadioList"); -//Add the radio button into loaded document. -loadedDocument.Form.Fields.Add(employeesRadioList); + //Add the radio button into loaded document. + loadedDocument.Form.Fields.Add(employeesRadioList); -//Create radio button items. -PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("1-9"); -radioButtonItem1.Bounds = new Syncfusion.Drawing.RectangleF(100, 140, 20, 20); -PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("10-49"); -radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); + //Create radio button items. + PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("1-9"); + radioButtonItem1.Bounds = new Syncfusion.Drawing.RectangleF(100, 140, 20, 20); + PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("10-49"); + radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); -//Add the items to radio button group. -employeesRadioList.Items.Add(radioButtonItem1); -employeesRadioList.Items.Add(radioButtonItem2); + //Add the items to radio button group. + employeesRadioList.Items.Add(radioButtonItem1); + employeesRadioList.Items.Add(radioButtonItem2); -//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/Forms/Add-signature-field-in-a-new-PDF-document/.NET/Add-signature-field-in-a-new-PDF-document/Program.cs b/Forms/Add-signature-field-in-a-new-PDF-document/.NET/Add-signature-field-in-a-new-PDF-document/Program.cs index 88990040..357e3a3e 100644 --- a/Forms/Add-signature-field-in-a-new-PDF-document/.NET/Add-signature-field-in-a-new-PDF-document/Program.cs +++ b/Forms/Add-signature-field-in-a-new-PDF-document/.NET/Add-signature-field-in-a-new-PDF-document/Program.cs @@ -1,30 +1,22 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Create PDF Signature field. -PdfSignatureField signatureField = new PdfSignatureField(page, "Signature"); + //Create PDF Signature field. + PdfSignatureField signatureField = new PdfSignatureField(page, "Signature"); -//Set properties to the signature field. -signatureField.Bounds = new Syncfusion.Drawing.RectangleF(50, 50, 90, 20); -signatureField.ToolTip = "Signature"; + //Set properties to the signature field. + signatureField.Bounds = new Syncfusion.Drawing.RectangleF(50, 50, 90, 20); + signatureField.ToolTip = "Signature"; -//Add the form field to the document. -document.Form.Fields.Add(signatureField); + //Add the form field to the document. + document.Form.Fields.Add(signatureField); -//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/Forms/Add-the-button-field-in-a-new-PDF-document/.NET/Add-the-button-field-in-a-new-PDF-document/Program.cs b/Forms/Add-the-button-field-in-a-new-PDF-document/.NET/Add-the-button-field-in-a-new-PDF-document/Program.cs index 0c8dda23..f80516f7 100644 --- a/Forms/Add-the-button-field-in-a-new-PDF-document/.NET/Add-the-button-field-in-a-new-PDF-document/Program.cs +++ b/Forms/Add-the-button-field-in-a-new-PDF-document/.NET/Add-the-button-field-in-a-new-PDF-document/Program.cs @@ -1,30 +1,22 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Create a Button. -PdfButtonField buttonField = new PdfButtonField(page, "Click"); + //Create a Button. + PdfButtonField buttonField = new PdfButtonField(page, "Click"); -//Set properties to the Button field. -buttonField.Bounds = new Syncfusion.Drawing.RectangleF(0, 100, 90, 20); -buttonField.Text = "Click"; + //Set properties to the Button field. + buttonField.Bounds = new Syncfusion.Drawing.RectangleF(0, 100, 90, 20); + buttonField.Text = "Click"; -//Add the form field to the document. -document.Form.Fields.Add(buttonField); + //Add the form field to the document. + document.Form.Fields.Add(buttonField); -//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/Forms/Add-the-textbox-to-an-existing-PDF-document/.NET/Add-the-textbox-to-an-existing-PDF-document/Program.cs b/Forms/Add-the-textbox-to-an-existing-PDF-document/.NET/Add-the-textbox-to-an-existing-PDF-document/Program.cs index 56c206ee..00ebb2a8 100644 --- a/Forms/Add-the-textbox-to-an-existing-PDF-document/.NET/Add-the-textbox-to-an-existing-PDF-document/Program.cs +++ b/Forms/Add-the-textbox-to-an-existing-PDF-document/.NET/Add-the-textbox-to-an-existing-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); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); - -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Create a textbox field and add the properties. -PdfTextBoxField textBoxField = new PdfTextBoxField(loadedPage, "FirstName"); -textBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 100, 20); -textBoxField.ToolTip = "First Name"; + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Add the form field to the existing PDF document. -loadedDocument.Form.Fields.Add(textBoxField); + //Create a textbox field and add the properties. + PdfTextBoxField textBoxField = new PdfTextBoxField(loadedPage, "FirstName"); + textBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 100, 20); + textBoxField.ToolTip = "First Name"; -//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 form field to the existing PDF document. + loadedDocument.Form.Fields.Add(textBoxField); -//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/Forms/Adding-button-field-in-an-existing-PDF-document/.NET/Adding-button-field-in-an-existing-PDF-document/Program.cs b/Forms/Adding-button-field-in-an-existing-PDF-document/.NET/Adding-button-field-in-an-existing-PDF-document/Program.cs index 3cde67d1..8f42547f 100644 --- a/Forms/Adding-button-field-in-an-existing-PDF-document/.NET/Adding-button-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Adding-button-field-in-an-existing-PDF-document/.NET/Adding-button-field-in-an-existing-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 PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a Button and set properties to the Button field. -PdfButtonField buttonField = new PdfButtonField(loadedPage, "Click"); -buttonField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 90, 20); -buttonField.Text = "Click"; + //Create a Button and set properties to the Button field. + PdfButtonField buttonField = new PdfButtonField(loadedPage, "Click"); + buttonField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 90, 20); + buttonField.Text = "Click"; -//Add the form field to the existing document. -loadedDocument.Form.Fields.Add(buttonField); + //Add the form field to the existing document. + loadedDocument.Form.Fields.Add(buttonField); -//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/Forms/Adding-checkbox-field-in-an-existing-PDF-document/.NET/Adding-checkbox-field-in-an-existing-PDF-document/Program.cs b/Forms/Adding-checkbox-field-in-an-existing-PDF-document/.NET/Adding-checkbox-field-in-an-existing-PDF-document/Program.cs index 7c88aeb0..acf85b3b 100644 --- a/Forms/Adding-checkbox-field-in-an-existing-PDF-document/.NET/Adding-checkbox-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Adding-checkbox-field-in-an-existing-PDF-document/.NET/Adding-checkbox-field-in-an-existing-PDF-document/Program.cs @@ -1,40 +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); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create Check Box field. -PdfCheckBoxField checkBoxField = new PdfCheckBoxField(loadedPage, "CheckBox"); + //Create Check Box field. + PdfCheckBoxField checkBoxField = new PdfCheckBoxField(loadedPage, "CheckBox"); -//Set check box properties. -checkBoxField.ToolTip = "Check Box"; -checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 10, 10); + //Set check box properties. + checkBoxField.ToolTip = "Check Box"; + checkBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 20, 10, 10); -//Add the form field to the existing document. -loadedDocument.Form.Fields.Add(checkBoxField); + //Add the form field to the existing document. + loadedDocument.Form.Fields.Add(checkBoxField); -//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/Forms/Adding-combo-box-in-the-new-PDF-document/.NET/Adding-combo-box-in-the-new-PDF-document/Program.cs b/Forms/Adding-combo-box-in-the-new-PDF-document/.NET/Adding-combo-box-in-the-new-PDF-document/Program.cs index a1873cf2..d784f9e0 100644 --- a/Forms/Adding-combo-box-in-the-new-PDF-document/.NET/Adding-combo-box-in-the-new-PDF-document/Program.cs +++ b/Forms/Adding-combo-box-in-the-new-PDF-document/.NET/Adding-combo-box-in-the-new-PDF-document/Program.cs @@ -1,37 +1,29 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); - -//Create a combo box for the first page. -PdfComboBoxField comboBoxField = new PdfComboBoxField(page, "JobTitle"); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Set the combo box properties. -comboBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 40, 100, 20); + //Create a combo box for the first page. + PdfComboBoxField comboBoxField = new PdfComboBoxField(page, "JobTitle"); -//Set tooltip. -comboBoxField.ToolTip = "Job Title"; + //Set the combo box properties. + comboBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 40, 100, 20); -//Add list items. -comboBoxField.Items.Add(new PdfListFieldItem("Development", "accounts")); -comboBoxField.Items.Add(new PdfListFieldItem("Support", "advertise")); -comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); + //Set tooltip. + comboBoxField.ToolTip = "Job Title"; -//Add combo box to the form. -document.Form.Fields.Add(comboBoxField); + //Add list items. + comboBoxField.Items.Add(new PdfListFieldItem("Development", "accounts")); + comboBoxField.Items.Add(new PdfListFieldItem("Support", "advertise")); + comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); -//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 combo box to the form. + document.Form.Fields.Add(comboBoxField); -//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/Forms/Adding-radio-button-in-new-PDF-document/.NET/Adding-radio-button-in-new-PDF-document/Program.cs b/Forms/Adding-radio-button-in-new-PDF-document/.NET/Adding-radio-button-in-new-PDF-document/Program.cs index ae4b5553..cc4d5050 100644 --- a/Forms/Adding-radio-button-in-new-PDF-document/.NET/Adding-radio-button-in-new-PDF-document/Program.cs +++ b/Forms/Adding-radio-button-in-new-PDF-document/.NET/Adding-radio-button-in-new-PDF-document/Program.cs @@ -1,36 +1,28 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Create a Radio button. -PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(page, "employeesRadioList"); + //Create a Radio button. + PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(page, "employeesRadioList"); -//Add the radio button into form. -document.Form.Fields.Add(employeesRadioList); + //Add the radio button into form. + document.Form.Fields.Add(employeesRadioList); -//Create radio button items. -PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("1-9"); -radioButtonItem1.Bounds = new Syncfusion.Drawing.RectangleF(100, 140, 20, 20); -PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("10-49"); -radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); + //Create radio button items. + PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("1-9"); + radioButtonItem1.Bounds = new Syncfusion.Drawing.RectangleF(100, 140, 20, 20); + PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("10-49"); + radioButtonItem2.Bounds = new Syncfusion.Drawing.RectangleF(100, 170, 20, 20); -//Add the items to radio button group. -employeesRadioList.Items.Add(radioButtonItem1); -employeesRadioList.Items.Add(radioButtonItem2); + //Add the items to radio button group. + employeesRadioList.Items.Add(radioButtonItem1); + employeesRadioList.Items.Add(radioButtonItem2); -//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/Forms/Adding-the-combo-box-in-existing-PDF-document/.NET/Adding-the-combo-box-in-existing-PDF-document/Program.cs b/Forms/Adding-the-combo-box-in-existing-PDF-document/.NET/Adding-the-combo-box-in-existing-PDF-document/Program.cs index 9213e3f0..5045cb84 100644 --- a/Forms/Adding-the-combo-box-in-existing-PDF-document/.NET/Adding-the-combo-box-in-existing-PDF-document/Program.cs +++ b/Forms/Adding-the-combo-box-in-existing-PDF-document/.NET/Adding-the-combo-box-in-existing-PDF-document/Program.cs @@ -1,45 +1,35 @@ -// 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); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a combo box for the first page. -PdfComboBoxField comboBoxField = new PdfComboBoxField(loadedPage, "JobTitle"); + //Create a combo box for the first page. + PdfComboBoxField comboBoxField = new PdfComboBoxField(loadedPage, "JobTitle"); -//Set the combo box properties. -comboBoxField.Bounds = new Syncfusion.Drawing.RectangleF(40, 40, 100, 20); + //Set the combo box properties. + comboBoxField.Bounds = new Syncfusion.Drawing.RectangleF(40, 40, 100, 20); -//Set tooltip. -comboBoxField.ToolTip = "Job Title"; + //Set tooltip. + comboBoxField.ToolTip = "Job Title"; -//Add list items. -comboBoxField.Items.Add(new PdfListFieldItem("Development", "accounts")); -comboBoxField.Items.Add(new PdfListFieldItem("Support", "advertise")); -comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); + //Add list items. + comboBoxField.Items.Add(new PdfListFieldItem("Development", "accounts")); + comboBoxField.Items.Add(new PdfListFieldItem("Support", "advertise")); + comboBoxField.Items.Add(new PdfListFieldItem("Documentation", "content")); -//Add combo box to the form. -loadedDocument.Form.Fields.Add(comboBoxField); + //Add combo box to the form. + loadedDocument.Form.Fields.Add(comboBoxField); -//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/Forms/Adding-the-signatre-field-in-existing-PDF-document/.NET/Adding-the-signatre-field-in-existing-PDF-document/Program.cs b/Forms/Adding-the-signatre-field-in-existing-PDF-document/.NET/Adding-the-signatre-field-in-existing-PDF-document/Program.cs index c4dc6f2c..a47a7978 100644 --- a/Forms/Adding-the-signatre-field-in-existing-PDF-document/.NET/Adding-the-signatre-field-in-existing-PDF-document/Program.cs +++ b/Forms/Adding-the-signatre-field-in-existing-PDF-document/.NET/Adding-the-signatre-field-in-existing-PDF-document/Program.cs @@ -1,38 +1,27 @@ -// 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); - -//Create the form if the form does not exist in the loaded document. -if (loadedDocument.Form == null) - loadedDocument.CreateForm(); - -//Load the page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the form if the form does not exist in the loaded document. + if (loadedDocument.Form == null) + loadedDocument.CreateForm(); -//Create PDF Signature field. -PdfSignatureField signatureField = new PdfSignatureField(loadedPage, "Signature"); + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Set properties to the signature field. -signatureField.Bounds = new Syncfusion.Drawing.RectangleF(100, 100, 90, 20); -signatureField.ToolTip = "Signature"; + //Create PDF Signature field. + PdfSignatureField signatureField = new PdfSignatureField(loadedPage, "Signature"); -//Add the form field to the existing document. -loadedDocument.Form.Fields.Add(signatureField); + //Set properties to the signature field. + signatureField.Bounds = new Syncfusion.Drawing.RectangleF(100, 100, 90, 20); + signatureField.ToolTip = "Signature"; -//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 form field to the existing document. + loadedDocument.Form.Fields.Add(signatureField); -//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/Forms/Auto-naming-of-form-fields-in-a-PDF-document/.NET/Auto-naming-of-form-fields-in-a-PDF-document/Program.cs b/Forms/Auto-naming-of-form-fields-in-a-PDF-document/.NET/Auto-naming-of-form-fields-in-a-PDF-document/Program.cs index 50cad191..d2fefbbf 100644 --- a/Forms/Auto-naming-of-form-fields-in-a-PDF-document/.NET/Auto-naming-of-form-fields-in-a-PDF-document/Program.cs +++ b/Forms/Auto-naming-of-form-fields-in-a-PDF-document/.NET/Auto-naming-of-form-fields-in-a-PDF-document/Program.cs @@ -1,45 +1,37 @@ -// 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(); - -//Add a new page to the PDF document. -PdfPage page = document.Pages.Add(); - -//Create the form. -PdfForm form = document.Form; +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to the PDF document. + PdfPage page = document.Pages.Add(); -//Enable the field auto naming. -form.FieldAutoNaming = true; + //Create the form. + PdfForm form = document.Form; -//Create a text box field and add the properties. -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "Name"); -textBoxField.Bounds = new RectangleF(0, 0, 100, 20); -textBoxField.ToolTip = "FirstName"; -textBoxField.Text = "John"; + //Enable the field auto naming. + form.FieldAutoNaming = true; -//Add the form field to the document. -document.Form.Fields.Add(textBoxField); + //Create a text box field and add the properties. + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "Name"); + textBoxField.Bounds = new RectangleF(0, 0, 100, 20); + textBoxField.ToolTip = "FirstName"; + textBoxField.Text = "John"; -//Create a text box field with the same name and add the properties. -PdfTextBoxField textBoxField1 = new PdfTextBoxField(page, "Name"); -textBoxField1.Bounds = new RectangleF(0, 50, 100, 20); -textBoxField1.ToolTip = "LastName"; -textBoxField1.Text = "Doe"; + //Add the form field to the document. + document.Form.Fields.Add(textBoxField); -//Add form field to the document. -document.Form.Fields.Add(textBoxField1); + //Create a text box field with the same name and add the properties. + PdfTextBoxField textBoxField1 = new PdfTextBoxField(page, "Name"); + textBoxField1.Bounds = new RectangleF(0, 50, 100, 20); + textBoxField1.ToolTip = "LastName"; + textBoxField1.Text = "Doe"; -//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 form field to the document. + document.Form.Fields.Add(textBoxField1); -//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/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF/.NET/Auto-resize-the-text-of-textboxfield-in-a-PDF/Program.cs b/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF/.NET/Auto-resize-the-text-of-textboxfield-in-a-PDF/Program.cs index 50642211..f43fb557 100644 --- a/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF/.NET/Auto-resize-the-text-of-textboxfield-in-a-PDF/Program.cs +++ b/Forms/Auto-resize-the-text-of-textboxfield-in-a-PDF/.NET/Auto-resize-the-text-of-textboxfield-in-a-PDF/Program.cs @@ -1,31 +1,20 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Read the text box field. -PdfLoadedTextBoxField loadedField = loadedDocument.Form.Fields[0] as PdfLoadedTextBoxField; + //Read the text box field. + PdfLoadedTextBoxField loadedField = loadedDocument.Form.Fields[0] as PdfLoadedTextBoxField; -//Enable auto resize. -loadedField.AutoResizeText = true; + //Enable auto resize. + loadedField.AutoResizeText = true; -//Flatten the form -loadedForm.Flatten = true; + //Flatten the form + loadedForm.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/Forms/Creating-a-Multiline-Text-Area-in-PDF/.NET/Creating-a-Multiline-Text-Area-in-PDF/Program.cs b/Forms/Creating-a-Multiline-Text-Area-in-PDF/.NET/Creating-a-Multiline-Text-Area-in-PDF/Program.cs index ab9127d3..51e8a163 100644 --- a/Forms/Creating-a-Multiline-Text-Area-in-PDF/.NET/Creating-a-Multiline-Text-Area-in-PDF/Program.cs +++ b/Forms/Creating-a-Multiline-Text-Area-in-PDF/.NET/Creating-a-Multiline-Text-Area-in-PDF/Program.cs @@ -3,30 +3,26 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create a new PDF document -PdfDocument document = new PdfDocument(); -// Creates a new page and adds it as the last page of the document -PdfPage page = document.Pages.Add(); -// Create a standard font to be used in the text field -PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f); -// Create a text box field and add it to the page with a name -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); -// Set the bounds (position and size) of the text box field -textBoxField.Bounds = new RectangleF(0, 0, 200, 50); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + // Creates a new page and adds it as the last page of the document + PdfPage page = document.Pages.Add(); + // Create a standard font to be used in the text field + PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f); + // Create a text box field and add it to the page with a name + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); + // Set the bounds (position and size) of the text box field + textBoxField.Bounds = new RectangleF(0, 0, 200, 50); -// Enable multiline functionality for the text box (allows multiple lines of text) -textBoxField.Multiline = true; + // Enable multiline functionality for the text box (allows multiple lines of text) + textBoxField.Multiline = true; -// Set the initial text inside the text box field -textBoxField.Text = "Essential PDF allows you to create and manage the form (AcroForm) in PDF document by using PdfForm class. The PdfFormFieldCollection class represents the entire field collection of the form."; -// Add the text box field to the form field collection in the document -document.Form.Fields.Add(textBoxField); + // Set the initial text inside the text box field + textBoxField.Text = "Essential PDF allows you to create and manage the form (AcroForm) in PDF document by using PdfForm class. The PdfFormFieldCollection class represents the entire field collection of the form."; + // Add the text box field to the form field collection in the document + document.Form.Fields.Add(textBoxField); -// Create a FileStream to save the document -using (FileStream stream = new FileStream(Path.GetFullPath(@"Output/Sample.pdf"), FileMode.Create, FileAccess.Write)) -{ - // Save the PDF document to the memory stream - document.Save(stream); -} -// 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/Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Program.cs b/Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Program.cs index 0bb0f553..747e337b 100644 --- a/Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Program.cs +++ b/Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Program.cs @@ -1,12 +1,9 @@ using Syncfusion.Drawing; using Syncfusion.Pdf.Parsing; -// Open the input PDF 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"))) { - // Load the PDF document from the input stream. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); - // Access the existing form fields in the PDF. PdfLoadedForm form = loadedDocument.Form; @@ -29,13 +26,7 @@ } // Disable the default appearance to allow custom rendering of form fields. form.SetDefaultAppearance(false); - // Create the output file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - // Save the modified PDF document to the new file stream. - loadedDocument.Save(outputFileStream); - } - // Close the PDF document. - loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Forms/Default-value-for-radio-button-field/.NET/Default_Value_For_Radio_Button/Program.cs b/Forms/Default-value-for-radio-button-field/.NET/Default_Value_For_Radio_Button/Program.cs index cf698259..314d302b 100644 --- a/Forms/Default-value-for-radio-button-field/.NET/Default_Value_For_Radio_Button/Program.cs +++ b/Forms/Default-value-for-radio-button-field/.NET/Default_Value_For_Radio_Button/Program.cs @@ -3,46 +3,40 @@ using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; - -// Create a new PDF document -PdfDocument document = new PdfDocument(); -// Add a new page to the PDF document -PdfPage page = document.Pages.Add(); - -// Create a new radio button list field -PdfRadioButtonListField genderRadioList = new PdfRadioButtonListField(page, "gender"); -// Create a font -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular); - -// Create a new radio button item for "Male" -PdfRadioButtonListItem radioItem1 = new PdfRadioButtonListItem("Male"); -// Set the bounds for the radio button -radioItem1.Bounds = new RectangleF(90, 203, 15, 15); -// Draw the label "Male" -page.Graphics.DrawString("Male", font, PdfBrushes.Black, new RectangleF(110, 204, 180, 20)); -// Add the radio button item to the list -employeesRadioList.Items.Add(radioItem1); - -// Create a new radio button item for "Female" -PdfRadioButtonListItem radioItem2 = new PdfRadioButtonListItem("Female"); -// Set the bounds for the radio button -radioItem2.Bounds = new RectangleF(205, 203, 15, 15); -// Draw the label "Female" -page.Graphics.DrawString("Female", font, PdfBrushes.Black, new RectangleF(225, 204, 180, 20)); -// Add the radio button item to the list -employeesRadioList.Items.Add(radioItem2); -//Set the default value of the radio button field. -employeesRadioList.SelectedIndex = 1; -// Add the radio button list to the form -document.Form.Fields.Add(employeesRadioList); - -//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); - + // Add a new page to the PDF document + PdfPage page = document.Pages.Add(); + + // Create a new radio button list field + PdfRadioButtonListField genderRadioList = new PdfRadioButtonListField(page, "gender"); + // Create a font + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular); + //Create a Radio button. + PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(page, "employeesRadioList"); + // Create a new radio button item for "Male" + PdfRadioButtonListItem radioItem1 = new PdfRadioButtonListItem("Male"); + // Set the bounds for the radio button + radioItem1.Bounds = new RectangleF(90, 203, 15, 15); + // Draw the label "Male" + page.Graphics.DrawString("Male", font, PdfBrushes.Black, new RectangleF(110, 204, 180, 20)); + // Add the radio button item to the list + employeesRadioList.Items.Add(radioItem1); + + // Create a new radio button item for "Female" + PdfRadioButtonListItem radioItem2 = new PdfRadioButtonListItem("Female"); + // Set the bounds for the radio button + radioItem2.Bounds = new RectangleF(205, 203, 15, 15); + // Draw the label "Female" + page.Graphics.DrawString("Female", font, PdfBrushes.Black, new RectangleF(225, 204, 180, 20)); + // Add the radio button item to the list + employeesRadioList.Items.Add(radioItem2); + //Set the default value of the radio button field. + employeesRadioList.SelectedIndex = 1; + // Add the radio button list to the form + document.Form.Fields.Add(employeesRadioList); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs index 5117c625..0a1660bd 100644 --- a/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs +++ b/Forms/Disable-Auto-Formatting-in-FormFields/.NET/Disable-Auto-Formatting-in-FormFields/Program.cs @@ -1,25 +1,21 @@ using Syncfusion.Pdf.Parsing; -// Load the existing PDF document -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)); - -// Access the form field named "email" from the PDF form -PdfLoadedField field = loadedDocument.Form.Fields["email"] as PdfLoadedField; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + // Access the form field named "email" from the PDF form + PdfLoadedField field = loadedDocument.Form.Fields["email"] as PdfLoadedField; -// Disable automatic formatting to prevent behaviors like JavaScript execution -loadedDocument.Form.DisableAutoFormat = true; + // Disable automatic formatting to prevent behaviors like JavaScript execution + loadedDocument.Form.DisableAutoFormat = true; -// Check if the field is a text box and assign a plain string value -if (field is PdfLoadedTextBoxField textBoxField) -{ - // Set the text box value to a raw email string without formatting - textBoxField.Text = "12345@gmail.com"; -} + // Check if the field is a text box and assign a plain string value + if (field is PdfLoadedTextBoxField textBoxField) + { + // Set the text box value to a raw email string without formatting + textBoxField.Text = "12345@gmail.com"; + } -// Save the modified PDF document to a new file using a file stream -using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - loadedDocument.Save(outputStream); -} -// Close and dispose the document to release resources -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/Forms/Enable-default-appearance-in-existing-PDF-document/.NET/Enable-default-appearance-in-existing-PDF-document/Program.cs b/Forms/Enable-default-appearance-in-existing-PDF-document/.NET/Enable-default-appearance-in-existing-PDF-document/Program.cs index a22ecc75..8eb7f329 100644 --- a/Forms/Enable-default-appearance-in-existing-PDF-document/.NET/Enable-default-appearance-in-existing-PDF-document/Program.cs +++ b/Forms/Enable-default-appearance-in-existing-PDF-document/.NET/Enable-default-appearance-in-existing-PDF-document/Program.cs @@ -1,31 +1,20 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Get the loaded text box field and fill it. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -loadedTextBoxField.Text = "First Name"; + //Get the loaded text box field and fill it. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; + loadedTextBoxField.Text = "First Name"; -//Enable the default Appearance. -loadedDocument.Form.SetDefaultAppearance(false); + //Enable the default Appearance. + 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); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); - diff --git a/Forms/Enable-default-appearance-in-new-PDF-document/.NET/Enable-default-appearance-in-new-PDF-document/Program.cs b/Forms/Enable-default-appearance-in-new-PDF-document/.NET/Enable-default-appearance-in-new-PDF-document/Program.cs index 17cd3be0..e0d24ef5 100644 --- a/Forms/Enable-default-appearance-in-new-PDF-document/.NET/Enable-default-appearance-in-new-PDF-document/Program.cs +++ b/Forms/Enable-default-appearance-in-new-PDF-document/.NET/Enable-default-appearance-in-new-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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); - -//Create a Text box field and add the properties. -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); -textBoxField.Bounds = new RectangleF(0, 0, 100, 20); -textBoxField.ToolTip = "First Name"; +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Add the form field to the document. -document.Form.Fields.Add(textBoxField); + //Create a Text box field and add the properties. + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); + textBoxField.Bounds = new RectangleF(0, 0, 100, 20); + textBoxField.ToolTip = "First Name"; -//Enable the default Appearance -document.Form.SetDefaultAppearance(false); + //Add the form field to the document. + document.Form.Fields.Add(textBoxField); -//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); -} + //Enable the default Appearance + document.Form.SetDefaultAppearance(false); -//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/Forms/Enabling-Edit-Option-for-the-PdfComboboxField/Enabling-Edit-Option-for-the-PdfComboboxField/Program.cs b/Forms/Enabling-Edit-Option-for-the-PdfComboboxField/Enabling-Edit-Option-for-the-PdfComboboxField/Program.cs index ab6b5624..2dafb708 100644 --- a/Forms/Enabling-Edit-Option-for-the-PdfComboboxField/Enabling-Edit-Option-for-the-PdfComboboxField/Program.cs +++ b/Forms/Enabling-Edit-Option-for-the-PdfComboboxField/Enabling-Edit-Option-for-the-PdfComboboxField/Program.cs @@ -1,36 +1,33 @@ -//Create a new PDF document -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf; using Syncfusion.Drawing; -PdfDocument document = new PdfDocument(); - -//Add page -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add page + PdfPage page = document.Pages.Add(); -//Create a PDF standard font -PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f); + //Create a PDF standard font + PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12f); -//Create a combo box + //Create a combo box -PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox"); + PdfComboBoxField positionComboBox = new PdfComboBoxField(page, "positionComboBox"); -//Set the combo box bounds -positionComboBox.Bounds = new RectangleF(100, 115, 200, 20); + //Set the combo box bounds + positionComboBox.Bounds = new RectangleF(100, 115, 200, 20); -//Set the font -positionComboBox.Font = font; + //Set the font + positionComboBox.Font = font; -//Enable editing option -positionComboBox.Editable = true; + //Enable editing option + positionComboBox.Editable = true; -//Add it to document -document.Form.Fields.Add(positionComboBox); + //Add it to document + document.Form.Fields.Add(positionComboBox); -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.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/Forms/Enumarate-form-fields-in-a-PDF-document/.NET/Enumarate-form-fields-in-a-PDF-document/Program.cs b/Forms/Enumarate-form-fields-in-a-PDF-document/.NET/Enumarate-form-fields-in-a-PDF-document/Program.cs index 4e233286..898ba96c 100644 --- a/Forms/Enumarate-form-fields-in-a-PDF-document/.NET/Enumarate-form-fields-in-a-PDF-document/Program.cs +++ b/Forms/Enumarate-form-fields-in-a-PDF-document/.NET/Enumarate-form-fields-in-a-PDF-document/Program.cs @@ -1,36 +1,25 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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); - -//Get the loaded form. -PdfLoadedForm form = document.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm form = loadedDocument.Form; -//Get the form field collection. -PdfLoadedFormFieldCollection fields = form.Fields; + //Get the form field collection. + PdfLoadedFormFieldCollection fields = form.Fields; -//Enumerates the form fields. -for (int i = 0; i < fields.Count; i++) -{ - if (fields[i] is PdfLoadedTextBoxField) + //Enumerates the form fields. + for (int i = 0; i < fields.Count; i++) { - //Get the loaded textbox field and fill it. - PdfLoadedTextBoxField loadedTextBoxField = fields[i] as PdfLoadedTextBoxField; - loadedTextBoxField.Text = "Text"; + if (fields[i] is PdfLoadedTextBoxField) + { + //Get the loaded textbox field and fill it. + PdfLoadedTextBoxField loadedTextBoxField = fields[i] as PdfLoadedTextBoxField; + loadedTextBoxField.Text = "Text"; + } } -} - -//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 + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Forms/Export-FDF-file-from-PDF-document/.NET/Export-FDF-file-from-PDF-document/Program.cs b/Forms/Export-FDF-file-from-PDF-document/.NET/Export-FDF-file-from-PDF-document/Program.cs index 43225fdd..fcaef50c 100644 --- a/Forms/Export-FDF-file-from-PDF-document/.NET/Export-FDF-file-from-PDF-document/Program.cs +++ b/Forms/Export-FDF-file-from-PDF-document/.NET/Export-FDF-file-from-PDF-document/Program.cs @@ -1,24 +1,13 @@ -// 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); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"); //Load an existing form. PdfLoadedForm loadedForm = loadedDocument.Form; -//Create memory stream. -MemoryStream ms = new MemoryStream(); - -//Load the FDF file. -FileStream stream1 = new FileStream(Path.GetFullPath("Output/Output.fdf"), FileMode.Create, FileAccess.ReadWrite); - //Export the existing PDF document to FDF file. -loadedForm.ExportData(stream1, DataFormat.Fdf, "AcroForm1"); +loadedForm.ExportData(Path.GetFullPath("Output/Output.fdf", DataFormat.Fdf, "AcroForm1"); //Close the document. loadedDocument.Close(true); diff --git a/Forms/Export_checkbox_values/.NET/Export_checkbox_values/Program.cs b/Forms/Export_checkbox_values/.NET/Export_checkbox_values/Program.cs index c46f8fb1..0c150bbc 100644 --- a/Forms/Export_checkbox_values/.NET/Export_checkbox_values/Program.cs +++ b/Forms/Export_checkbox_values/.NET/Export_checkbox_values/Program.cs @@ -2,49 +2,45 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document -PdfDocument document = new PdfDocument(); -//Add a new page to the PDF document. -PdfPage page = document.Pages.Add(); - -//Create the form. -PdfForm form = document.Form; - -//Enable the field auto naming. -form.FieldAutoNaming = false; - -//Set default appearance as false. -document.Form.SetDefaultAppearance(false); - -// Create First checkbox field -PdfCheckBoxField checkBoxField1 = new PdfCheckBoxField(page, "CheckBox"); -checkBoxField1.Bounds = new RectangleF(10, 150, 50, 20); -checkBoxField1.BorderColor = Color.Red; -checkBoxField1.BorderWidth = 3; -checkBoxField1.BackColor = Color.Yellow; - -//Set the Export value -checkBoxField1.ExportValue = "Value"; -checkBoxField1.Checked = true; - -// Add to form -form.Fields.Add(checkBoxField1); - -// Create Second checkbox field -PdfCheckBoxField checkBoxField2 = new PdfCheckBoxField(page, "CheckBox"); -checkBoxField2.Bounds = new RectangleF(10, 250, 50, 20); -checkBoxField2.BorderColor = Color.Green; -checkBoxField2.BorderWidth = 2; -checkBoxField2.BackColor = Color.YellowGreen; - -// Add to form -form.Fields.Add(checkBoxField2); - -//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 + //Add a new page to the PDF document. + PdfPage page = document.Pages.Add(); + + //Create the form. + PdfForm form = document.Form; + + //Enable the field auto naming. + form.FieldAutoNaming = false; + + //Set default appearance as false. + document.Form.SetDefaultAppearance(false); + + // Create First checkbox field + PdfCheckBoxField checkBoxField1 = new PdfCheckBoxField(page, "CheckBox"); + checkBoxField1.Bounds = new RectangleF(10, 150, 50, 20); + checkBoxField1.BorderColor = Color.Red; + checkBoxField1.BorderWidth = 3; + checkBoxField1.BackColor = Color.Yellow; + + //Set the Export value + checkBoxField1.ExportValue = "Value"; + checkBoxField1.Checked = true; + + // Add to form + form.Fields.Add(checkBoxField1); + + // Create Second checkbox field + PdfCheckBoxField checkBoxField2 = new PdfCheckBoxField(page, "CheckBox"); + checkBoxField2.Bounds = new RectangleF(10, 250, 50, 20); + checkBoxField2.BorderColor = Color.Green; + checkBoxField2.BorderWidth = 2; + checkBoxField2.BackColor = Color.YellowGreen; + + // Add to form + form.Fields.Add(checkBoxField2); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Forms/Fill-list-box-field-in-an-existing-PDF-document/.NET/Fill-list-box-field-in-an-existing-PDF-document/Program.cs b/Forms/Fill-list-box-field-in-an-existing-PDF-document/.NET/Fill-list-box-field-in-an-existing-PDF-document/Program.cs index 05d12eba..bd8531d4 100644 --- a/Forms/Fill-list-box-field-in-an-existing-PDF-document/.NET/Fill-list-box-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Fill-list-box-field-in-an-existing-PDF-document/.NET/Fill-list-box-field-in-an-existing-PDF-document/Program.cs @@ -1,31 +1,20 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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); - -//Set the default appearance of the PDF form. -loadedDocument.Form.SetDefaultAppearance(true); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Set the default appearance of the PDF form. + loadedDocument.Form.SetDefaultAppearance(true); -//Get the loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Fill list box. -PdfLoadedListBoxField loadedListBox = loadedForm.Fields[5] as PdfLoadedListBoxField; + //Fill list box. + PdfLoadedListBoxField loadedListBox = loadedForm.Fields[5] as PdfLoadedListBoxField; -//Fill list box and Modify the list box select index. -loadedListBox.SelectedIndex = new int[1] { 2 }; + //Fill list box and Modify the list box select index. + loadedListBox.SelectedIndex = new int[1] { 2 }; -//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/Forms/Fill-radio-button-field-in-an-existing-PDF-document/.NET/Fill-radio-button-field-in-an-existing-PDF-document/Program.cs b/Forms/Fill-radio-button-field-in-an-existing-PDF-document/.NET/Fill-radio-button-field-in-an-existing-PDF-document/Program.cs index 3d058e60..73839923 100644 --- a/Forms/Fill-radio-button-field-in-an-existing-PDF-document/.NET/Fill-radio-button-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Fill-radio-button-field-in-an-existing-PDF-document/.NET/Fill-radio-button-field-in-an-existing-PDF-document/Program.cs @@ -1,26 +1,15 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; - -//Get the loaded radio button field. -PdfLoadedRadioButtonListField loadedRadioButtonField = loadedForm.Fields[3] as PdfLoadedRadioButtonListField; -loadedRadioButtonField.SelectedIndex = 1; - -//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. - loadedDocument.Save(outputFileStream); -} + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; + + //Get the loaded radio button field. + PdfLoadedRadioButtonListField loadedRadioButtonField = loadedForm.Fields[3] as PdfLoadedRadioButtonListField; + loadedRadioButtonField.SelectedIndex = 1; -//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/Forms/Fill-the-XFA-forms-fields-via-acroform-API/.NET/Fill-the-XFA-forms-fields-via-acroform-API/Program.cs b/Forms/Fill-the-XFA-forms-fields-via-acroform-API/.NET/Fill-the-XFA-forms-fields-via-acroform-API/Program.cs index 4de5be77..04917bb2 100644 --- a/Forms/Fill-the-XFA-forms-fields-via-acroform-API/.NET/Fill-the-XFA-forms-fields-via-acroform-API/Program.cs +++ b/Forms/Fill-the-XFA-forms-fields-via-acroform-API/.NET/Fill-the-XFA-forms-fields-via-acroform-API/Program.cs @@ -1,37 +1,26 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 Acroform. -PdfLoadedForm acroform = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing Acroform. + PdfLoadedForm acroform = loadedDocument.Form; -//Enable XFA form filling. -acroform.EnableXfaFormFill = true; + //Enable XFA form filling. + acroform.EnableXfaFormFill = true; -//Get the existing text box field named "FirstName". -PdfLoadedTextBoxField firstName = acroform.Fields["FirstName"] as PdfLoadedTextBoxField; + //Get the existing text box field named "FirstName". + PdfLoadedTextBoxField firstName = acroform.Fields["FirstName"] as PdfLoadedTextBoxField; -//Set text. -firstName.Text = "Simon"; + //Set text. + firstName.Text = "Simon"; -//Get the existing text box field named "LastName". -PdfLoadedTextBoxField lastName = acroform.Fields["LastName"] as PdfLoadedTextBoxField; + //Get the existing text box field named "LastName". + PdfLoadedTextBoxField lastName = acroform.Fields["LastName"] as PdfLoadedTextBoxField; -//Set text. -lastName.Text = "Bistro"; + //Set text. + lastName.Text = "Bistro"; -//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/Forms/Fill-the-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-checkbox-field-in-an-existing-PDF-document/Program.cs b/Forms/Fill-the-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-checkbox-field-in-an-existing-PDF-document/Program.cs index 7fb33693..582557f6 100644 --- a/Forms/Fill-the-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-checkbox-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Fill-the-checkbox-field-in-an-existing-PDF-document/.NET/Fill-the-checkbox-field-in-an-existing-PDF-document/Program.cs @@ -1,31 +1,20 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//load the check box from field collection. -PdfLoadedCheckBoxField loadedCheckBoxField = loadedForm.Fields[6] as PdfLoadedCheckBoxField; + //load the check box from field collection. + PdfLoadedCheckBoxField loadedCheckBoxField = loadedForm.Fields[6] as PdfLoadedCheckBoxField; -//Fill the checkbox. -loadedCheckBoxField.Items[0].Checked = true; + //Fill the checkbox. + loadedCheckBoxField.Items[0].Checked = true; -//Check the checkbox if it is not grouped. -loadedCheckBoxField.Checked = true; + //Check the checkbox if it is not grouped. + loadedCheckBoxField.Checked = 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/Forms/Fill-the-combobox-field-in-an-existing-PDF-document/.NET/Fill-the-combobox-field-in-an-existing-PDF-document/Program.cs b/Forms/Fill-the-combobox-field-in-an-existing-PDF-document/.NET/Fill-the-combobox-field-in-an-existing-PDF-document/Program.cs index c825a870..6dffdf8f 100644 --- a/Forms/Fill-the-combobox-field-in-an-existing-PDF-document/.NET/Fill-the-combobox-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Fill-the-combobox-field-in-an-existing-PDF-document/.NET/Fill-the-combobox-field-in-an-existing-PDF-document/Program.cs @@ -1,26 +1,15 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Get the loaded combo box field and modify the properties. -PdfLoadedComboBoxField loadedComboboxField = loadedForm.Fields[4] as PdfLoadedComboBoxField; -loadedComboboxField.SelectedIndex = 1; + //Get the loaded combo box field and modify the properties. + PdfLoadedComboBoxField loadedComboboxField = loadedForm.Fields[4] as PdfLoadedComboBoxField; + loadedComboboxField.SelectedIndex = 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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Forms/Fill-the-signature-field-in-an-existing-PDF/.NET/Fill-the-signature-field-in-an-existing-PDF/Program.cs b/Forms/Fill-the-signature-field-in-an-existing-PDF/.NET/Fill-the-signature-field-in-an-existing-PDF/Program.cs index 0fb535a3..13d6d5cb 100644 --- a/Forms/Fill-the-signature-field-in-an-existing-PDF/.NET/Fill-the-signature-field-in-an-existing-PDF/Program.cs +++ b/Forms/Fill-the-signature-field-in-an-existing-PDF/.NET/Fill-the-signature-field-in-an-existing-PDF/Program.cs @@ -1,48 +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; using Syncfusion.Pdf.Security; -//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 PDF document. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the PDF document. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create PDF Certificate -FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read); -PdfCertificate certificate = new PdfCertificate(certificateStream, "syncfusion"); + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Load the signature field from field collection and fill this with certificate. -PdfLoadedSignatureField loadedSignatureField = loadedForm.Fields[9] as PdfLoadedSignatureField; -loadedSignatureField.Signature = new PdfSignature(loadedDocument, loadedPage, certificate, "Signature", loadedSignatureField); -loadedSignatureField.Signature.Certificate = certificate; -loadedSignatureField.Signature.Reason = "Reason"; + //Create PDF Certificate + FileStream certificateStream = new FileStream(Path.GetFullPath(@"Data/PDF.pfx"), FileMode.Open, FileAccess.Read); + PdfCertificate certificate = new PdfCertificate(certificateStream, "syncfusion"); -//Get stream from an image file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.jpg"), FileMode.Open, FileAccess.Read); + //Load the signature field from field collection and fill this with certificate. + PdfLoadedSignatureField loadedSignatureField = loadedForm.Fields[9] as PdfLoadedSignatureField; + loadedSignatureField.Signature = new PdfSignature(loadedDocument, loadedPage, certificate, "Signature", loadedSignatureField); + loadedSignatureField.Signature.Certificate = certificate; + loadedSignatureField.Signature.Reason = "Reason"; -//Load the image. -PdfBitmap image = new PdfBitmap(imageStream); + //Get stream from an image file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/signature.jpg"), FileMode.Open, FileAccess.Read); -//Draw image in the signature appearance. -loadedSignatureField.Signature.Appearance.Normal.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(loadedSignatureField.Bounds.Width, loadedSignatureField.Bounds.Height)); + //Load the image. + PdfBitmap image = new PdfBitmap(imageStream); -//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 in the signature appearance. + loadedSignatureField.Signature.Appearance.Normal.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(loadedSignatureField.Bounds.Width, loadedSignatureField.Bounds.Height)); -//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/Forms/Filling-the-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-textbox-field-in-an-existing-PDF-document/Program.cs b/Forms/Filling-the-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-textbox-field-in-an-existing-PDF-document/Program.cs index 56805b3f..88e5cfbd 100644 --- a/Forms/Filling-the-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-textbox-field-in-an-existing-PDF-document/Program.cs +++ b/Forms/Filling-the-textbox-field-in-an-existing-PDF-document/.NET/Filling-the-textbox-field-in-an-existing-PDF-document/Program.cs @@ -1,28 +1,17 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; - -//Get the loaded text box field. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Fill the textbox field. -loadedTextBoxField.Text = "Johnson"; + //Get the loaded text box field. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -//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); -} + //Fill the textbox field. + loadedTextBoxField.Text = "Johnson"; -//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/Forms/Flatten-the-existing-form-fields-with-complex-script/.NET/Flatten-the-existing-form-fields-with-complex-script/Program.cs b/Forms/Flatten-the-existing-form-fields-with-complex-script/.NET/Flatten-the-existing-form-fields-with-complex-script/Program.cs index fc16f999..de633f62 100644 --- a/Forms/Flatten-the-existing-form-fields-with-complex-script/.NET/Flatten-the-existing-form-fields-with-complex-script/Program.cs +++ b/Forms/Flatten-the-existing-form-fields-with-complex-script/.NET/Flatten-the-existing-form-fields-with-complex-script/Program.cs @@ -1,31 +1,20 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using System.Reflection.Metadata; -//Get stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - -//Load the existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Get the existing PDF form. -PdfLoadedForm lForm = loadedDocument.Form as PdfLoadedForm; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the existing PDF form. + PdfLoadedForm lForm = loadedDocument.Form as PdfLoadedForm; -//Set the complex script layout. -lForm.ComplexScript = true; + //Set the complex script layout. + lForm.ComplexScript = true; -//Set flatten. -lForm.Flatten = true; + //Set flatten. + lForm.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/Forms/Flatten-the-form-fields-before-saving-PDF-document/.NET/Flatten-the-form-fields-before-saving-PDF-document/Program.cs b/Forms/Flatten-the-form-fields-before-saving-PDF-document/.NET/Flatten-the-form-fields-before-saving-PDF-document/Program.cs index a5027e77..536729e1 100644 --- a/Forms/Flatten-the-form-fields-before-saving-PDF-document/.NET/Flatten-the-form-fields-before-saving-PDF-document/Program.cs +++ b/Forms/Flatten-the-form-fields-before-saving-PDF-document/.NET/Flatten-the-form-fields-before-saving-PDF-document/Program.cs @@ -1,26 +1,15 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using System.Reflection.Metadata; -//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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Flatten the form fields. -loadedForm.FlattenFields(); + //Flatten the form fields. + loadedForm.FlattenFields(); -//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/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs b/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs index 6dd6d7cd..d63b0428 100644 --- a/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs +++ b/Forms/Flattening-form-fields-in-an-existing-PDF-document/.NET/Flattening-form-fields-in-an-existing-PDF-document/Program.cs @@ -1,35 +1,24 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Get the field collection. -PdfLoadedFormFieldCollection fields = loadedForm.Fields; + //Get the field collection. + PdfLoadedFormFieldCollection fields = loadedForm.Fields; -//Get the loaded text box field. -PdfLoadedTextBoxField loadedTextBoxField = fields[0] as PdfLoadedTextBoxField; + //Get the loaded text box field. + PdfLoadedTextBoxField loadedTextBoxField = fields[0] as PdfLoadedTextBoxField; -//Fill the textbox field. -loadedTextBoxField.Text = "Syncfusion"; + //Fill the textbox field. + loadedTextBoxField.Text = "Syncfusion"; -//Flatten the whole form. -loadedForm.Flatten = true; + //Flatten the whole form. + loadedForm.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/Forms/Get-option-value-from-acroform-radio-button/.NET/Get-option-value-from-acroform-radio-button/Program.cs b/Forms/Get-option-value-from-acroform-radio-button/.NET/Get-option-value-from-acroform-radio-button/Program.cs index 34967e1b..478bb318 100644 --- a/Forms/Get-option-value-from-acroform-radio-button/.NET/Get-option-value-from-acroform-radio-button/Program.cs +++ b/Forms/Get-option-value-from-acroform-radio-button/.NET/Get-option-value-from-acroform-radio-button/Program.cs @@ -1,40 +1,29 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm form = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the loaded form. + PdfLoadedForm form = loadedDocument.Form; -//Set default appearance to false. -form.SetDefaultAppearance(false); + //Set default appearance to false. + form.SetDefaultAppearance(false); -//Gets the 'Gender' radio button field. -PdfLoadedRadioButtonListField radioButtonField = form.Fields["SF182[0].#subform[0].P1BCheck[0]"] as PdfLoadedRadioButtonListField; + //Gets the 'Gender' radio button field. + PdfLoadedRadioButtonListField radioButtonField = form.Fields["SF182[0].#subform[0].P1BCheck[0]"] as PdfLoadedRadioButtonListField; -//Select the item that contains option value as "Male". -foreach (PdfLoadedRadioButtonItem item in radioButtonField.Items) -{ - //Gets an option value of the item. - if (item.OptionValue == "Resubmission") + //Select the item that contains option value as "Male". + foreach (PdfLoadedRadioButtonItem item in radioButtonField.Items) { - item.Selected = true; + //Gets an option value of the item. + if (item.OptionValue == "Resubmission") + { + item.Selected = true; + } + } + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//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); - diff --git a/Forms/Get-the-field-from-collection-using-TryGetField/.NET/Get-the-field-from-collection-using-TryGetField/Program.cs b/Forms/Get-the-field-from-collection-using-TryGetField/.NET/Get-the-field-from-collection-using-TryGetField/Program.cs index 9ea33fbe..6048701d 100644 --- a/Forms/Get-the-field-from-collection-using-TryGetField/.NET/Get-the-field-from-collection-using-TryGetField/Program.cs +++ b/Forms/Get-the-field-from-collection-using-TryGetField/.NET/Get-the-field-from-collection-using-TryGetField/Program.cs @@ -1,32 +1,21 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 form from the loaded document. -PdfLoadedForm form = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the form from the loaded document. + PdfLoadedForm form = loadedDocument.Form; -//Load the form field collections from the form. -PdfLoadedFormFieldCollection fieldCollection = form.Fields as PdfLoadedFormFieldCollection; -PdfLoadedField loadedField = null; + //Load the form field collections from the form. + PdfLoadedFormFieldCollection fieldCollection = form.Fields as PdfLoadedFormFieldCollection; + PdfLoadedField loadedField = null; -//Get the field using TryGetField Method. -if (fieldCollection.TryGetField("Name", out loadedField)) -{ - (loadedField as PdfLoadedTextBoxField).Text = "Johnson"; -} + //Get the field using TryGetField Method. + if (fieldCollection.TryGetField("Name", out loadedField)) + { + (loadedField as PdfLoadedTextBoxField).Text = "Johnson"; + } -//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/Forms/Get-the-field-from-collection-using-TryGetValue/.NET/Get-the-field-from-collection-using-TryGetValue/Program.cs b/Forms/Get-the-field-from-collection-using-TryGetValue/.NET/Get-the-field-from-collection-using-TryGetValue/Program.cs index 2cebb826..064f574b 100644 --- a/Forms/Get-the-field-from-collection-using-TryGetValue/.NET/Get-the-field-from-collection-using-TryGetValue/Program.cs +++ b/Forms/Get-the-field-from-collection-using-TryGetValue/.NET/Get-the-field-from-collection-using-TryGetValue/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 form from the loaded document. -PdfLoadedForm form = loadedDocument.Form; - -//Load the form field collections from the form. -PdfLoadedFormFieldCollection fieldCollection = form.Fields as PdfLoadedFormFieldCollection; -string fieldValue = string.Empty; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the form from the loaded document. + PdfLoadedForm form = loadedDocument.Form; -//Get the field value using TryGetValue Method. -fieldCollection.TryGetValue("Name", out fieldValue); + //Load the form field collections from the form. + PdfLoadedFormFieldCollection fieldCollection = form.Fields as PdfLoadedFormFieldCollection; + string fieldValue = string.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. - loadedDocument.Save(outputFileStream); -} + //Get the field value using TryGetValue Method. + fieldCollection.TryGetValue("Name", out fieldValue); -//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/Forms/Get-widget-annotation-in-PDF/.NET/Get-widget-annotation-in-PDF/Program.cs b/Forms/Get-widget-annotation-in-PDF/.NET/Get-widget-annotation-in-PDF/Program.cs index 84516b83..cb50124e 100644 --- a/Forms/Get-widget-annotation-in-PDF/.NET/Get-widget-annotation-in-PDF/Program.cs +++ b/Forms/Get-widget-annotation-in-PDF/.NET/Get-widget-annotation-in-PDF/Program.cs @@ -3,32 +3,31 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -//Load the PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); -// Loop through each page in the loaded PDF document. -foreach (PdfLoadedPage page in loadedDocument.Pages) +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - // Initialize the widget count to zero. - int widgetCount = 0; - // Loop through each annotation on the current page. - foreach (PdfLoadedAnnotation annot in page.Annotations) + // Loop through each page in the loaded PDF document. + foreach (PdfLoadedPage page in loadedDocument.Pages) { - // Check if the annotation is a widget annotation. - if (annot is PdfLoadedWidgetAnnotation) + // Initialize the widget count to zero. + int widgetCount = 0; + // Loop through each annotation on the current page. + foreach (PdfLoadedAnnotation annot in page.Annotations) { - // Cast the annotation to a PdfLoadedWidgetAnnotation type. - PdfLoadedWidgetAnnotation widget = annot as PdfLoadedWidgetAnnotation; - // Retrieve the bounds of the widget annotation. - RectangleF bounds = widget.Bounds; - // Display the index and bounds value of the widget annotation. - Console.WriteLine("Index: {0}, Bounds Value: {1}", widgetCount, bounds); - // Increment the widget count. - widgetCount++; + // Check if the annotation is a widget annotation. + if (annot is PdfLoadedWidgetAnnotation) + { + // Cast the annotation to a PdfLoadedWidgetAnnotation type. + PdfLoadedWidgetAnnotation widget = annot as PdfLoadedWidgetAnnotation; + // Retrieve the bounds of the widget annotation. + RectangleF bounds = widget.Bounds; + // Display the index and bounds value of the widget annotation. + Console.WriteLine("Index: {0}, Bounds Value: {1}", widgetCount, bounds); + // Increment the widget count. + widgetCount++; + } } + // Display the total number of widget annotations. + Console.WriteLine("Total number of widgets: {0}", widgetCount); } - // Display the total number of widget annotations. - Console.WriteLine("Total number of widgets: {0}", widgetCount); -} -//Close the document. -loadedDocument.Close(true); \ No newline at end of file +} \ No newline at end of file diff --git a/Forms/Importing-FDF-file-to-PDF-document/.NET/Importing-FDF-file-to-PDF-document/Program.cs b/Forms/Importing-FDF-file-to-PDF-document/.NET/Importing-FDF-file-to-PDF-document/Program.cs index f8d64625..e312bded 100644 --- a/Forms/Importing-FDF-file-to-PDF-document/.NET/Importing-FDF-file-to-PDF-document/Program.cs +++ b/Forms/Importing-FDF-file-to-PDF-document/.NET/Importing-FDF-file-to-PDF-document/Program.cs @@ -1,28 +1,16 @@ -// 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); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Load the existing form. PdfLoadedForm loadedForm = loadedDocument.Form; -//Load the FDF file. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.fdf"), FileMode.Open, FileAccess.Read); - //Import the FDF stream. -loadedForm.ImportDataFDF(fileStream, true); +loadedForm.ImportDataFDF(Path.GetFullPath(@"Data/Input.fdf"), 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 PDF document. loadedDocument.Close(true); \ No newline at end of file diff --git a/Forms/Modify-the-existing-form-field-in-PDF-document/.NET/Modify-the-existing-form-field-in-PDF-document/Program.cs b/Forms/Modify-the-existing-form-field-in-PDF-document/.NET/Modify-the-existing-form-field-in-PDF-document/Program.cs index 95441ee0..3df0ec8a 100644 --- a/Forms/Modify-the-existing-form-field-in-PDF-document/.NET/Modify-the-existing-form-field-in-PDF-document/Program.cs +++ b/Forms/Modify-the-existing-form-field-in-PDF-document/.NET/Modify-the-existing-form-field-in-PDF-document/Program.cs @@ -1,32 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf.Parsing; using System.Reflection.Metadata; -//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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; - -//Get the loaded form field and modify the properties. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -RectangleF newBounds = new RectangleF(100, 100, 150, 50); -loadedTextBoxField.Bounds = newBounds; -loadedTextBoxField.SpellCheck = true; -loadedTextBoxField.Text = "New text of the field."; -loadedTextBoxField.Password = false; - -//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 the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; + + //Get the loaded form field and modify the properties. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; + RectangleF newBounds = new RectangleF(100, 100, 150, 50); + loadedTextBoxField.Bounds = newBounds; + loadedTextBoxField.SpellCheck = true; + loadedTextBoxField.Text = "New text of the field."; + loadedTextBoxField.Password = false; -//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/Forms/Modifying-fore-and-backcolor-of-existing-form-fields/.NET/Modifying-fore-and-backcolor-of-existing-form-fields/Program.cs b/Forms/Modifying-fore-and-backcolor-of-existing-form-fields/.NET/Modifying-fore-and-backcolor-of-existing-form-fields/Program.cs index 5187e5de..2243aeae 100644 --- a/Forms/Modifying-fore-and-backcolor-of-existing-form-fields/.NET/Modifying-fore-and-backcolor-of-existing-form-fields/Program.cs +++ b/Forms/Modifying-fore-and-backcolor-of-existing-form-fields/.NET/Modifying-fore-and-backcolor-of-existing-form-fields/Program.cs @@ -1,42 +1,31 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; 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); - -//Get the loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Get the loaded form field. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; + //Get the loaded form field. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -//Get fore color of the field. -PdfColor foreColor = loadedTextBoxField.ForeColor; + //Get fore color of the field. + PdfColor foreColor = loadedTextBoxField.ForeColor; -//Set the fore color. -loadedTextBoxField.ForeColor = new PdfColor(Color.Red); + //Set the fore color. + loadedTextBoxField.ForeColor = new PdfColor(Color.Red); -//Get background color of the field. -PdfColor backColor = loadedTextBoxField.BackColor; + //Get background color of the field. + PdfColor backColor = loadedTextBoxField.BackColor; -//Set the background color. -loadedTextBoxField.BackColor = new PdfColor(Color.Green); + //Set the background color. + loadedTextBoxField.BackColor = new PdfColor(Color.Green); -//Set the text. -loadedTextBoxField.Text = "Johnson"; + //Set the text. + loadedTextBoxField.Text = "Johnson"; -//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/Forms/Remove-the-form-fields-form-the-existing-PDF-document/.NET/Remove-the-form-fields-form-the-existing-PDF-document/Program.cs b/Forms/Remove-the-form-fields-form-the-existing-PDF-document/.NET/Remove-the-form-fields-form-the-existing-PDF-document/Program.cs index 9df290d6..004e3b3a 100644 --- a/Forms/Remove-the-form-fields-form-the-existing-PDF-document/.NET/Remove-the-form-fields-form-the-existing-PDF-document/Program.cs +++ b/Forms/Remove-the-form-fields-form-the-existing-PDF-document/.NET/Remove-the-form-fields-form-the-existing-PDF-document/Program.cs @@ -1,35 +1,24 @@ -// 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 page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Load the textbox field. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Remove the field. -loadedForm.Fields.Remove(loadedTextBoxField); + //Load the textbox field. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -//Remove the field at index 0. -loadedForm.Fields.RemoveAt(0); + //Remove the field. + loadedForm.Fields.Remove(loadedTextBoxField); -//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 the field at index 0. + loadedForm.Fields.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/Forms/Removing-editing-capability-of-form-fields/.NET/Removing-editing-capability-of-form-fields/Program.cs b/Forms/Removing-editing-capability-of-form-fields/.NET/Removing-editing-capability-of-form-fields/Program.cs index 1f054315..97e202d2 100644 --- a/Forms/Removing-editing-capability-of-form-fields/.NET/Removing-editing-capability-of-form-fields/Program.cs +++ b/Forms/Removing-editing-capability-of-form-fields/.NET/Removing-editing-capability-of-form-fields/Program.cs @@ -1,35 +1,27 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Create a Text box field and add the properties. -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); -textBoxField.Bounds = new RectangleF(0, 0, 100, 20); -textBoxField.ToolTip = "First Name"; -textBoxField.Text = "Syncfusion"; + //Create a Text box field and add the properties. + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); + textBoxField.Bounds = new RectangleF(0, 0, 100, 20); + textBoxField.ToolTip = "First Name"; + textBoxField.Text = "Syncfusion"; -//Flatten the whole form fields. -document.Form.Flatten = true; + //Flatten the whole form fields. + document.Form.Flatten = true; -//Flattens the first field //form.Fields[0].Flatten = true; + //Flattens the first field //form.Fields[0].Flatten = true; -//Add the form field to the document -document.Form.Fields.Add(textBoxField); + //Add the form field to the document + document.Form.Fields.Add(textBoxField); -//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/Forms/Set-appearance-to-the-PDF-form-fields/.NET/Set-appearance-to-the-PDF-form-fields/Program.cs b/Forms/Set-appearance-to-the-PDF-form-fields/.NET/Set-appearance-to-the-PDF-form-fields/Program.cs index 6add098f..f11cbc64 100644 --- a/Forms/Set-appearance-to-the-PDF-form-fields/.NET/Set-appearance-to-the-PDF-form-fields/Program.cs +++ b/Forms/Set-appearance-to-the-PDF-form-fields/.NET/Set-appearance-to-the-PDF-form-fields/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; - -//Set the default appearance. -loadedForm.SetDefaultAppearance(false); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; -//Get the loaded form field. -PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; -loadedTextBoxField.Text = "John"; + //Set the default appearance. + loadedForm.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); -} + //Get the loaded form field. + PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField; + loadedTextBoxField.Text = "John"; -//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/Forms/Set-readonly-property-to-a-new-PDF-document/.NET/Set-readonly-property-to-a-new-PDF-document/Program.cs b/Forms/Set-readonly-property-to-a-new-PDF-document/.NET/Set-readonly-property-to-a-new-PDF-document/Program.cs index a1b19a02..22327a32 100644 --- a/Forms/Set-readonly-property-to-a-new-PDF-document/.NET/Set-readonly-property-to-a-new-PDF-document/Program.cs +++ b/Forms/Set-readonly-property-to-a-new-PDF-document/.NET/Set-readonly-property-to-a-new-PDF-document/Program.cs @@ -1,39 +1,31 @@ -// 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(); - -//Add a new page to PDF document. -PdfPage page = document.Pages.Add(); - -//Create the form. -PdfForm form = document.Form; +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page to PDF document. + PdfPage page = document.Pages.Add(); -//Set the form as read only. -form.ReadOnly = true; + //Create the form. + PdfForm form = document.Form; -//Create a text box field and add the properties. -PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); -textBoxField.Bounds = new RectangleF(0, 0, 100, 20); -textBoxField.ToolTip = "First Name"; -textBoxField.Text = "john"; + //Set the form as read only. + form.ReadOnly = true; -//set read only property for a particular field -//textBoxField.ReadOnly = true; + //Create a text box field and add the properties. + PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName"); + textBoxField.Bounds = new RectangleF(0, 0, 100, 20); + textBoxField.ToolTip = "First Name"; + textBoxField.Text = "john"; -//Add the form field to the document. -document.Form.Fields.Add(textBoxField); + //set read only property for a particular field + //textBoxField.ReadOnly = 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); -} + //Add the form field to the document. + document.Form.Fields.Add(textBoxField); -//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/Forms/Set-the-ReadOnly-property-to-an-existing-PDF-document/.NET/Set-the-ReadOnly-property-to-an-existing-PDF-document/Program.cs b/Forms/Set-the-ReadOnly-property-to-an-existing-PDF-document/.NET/Set-the-ReadOnly-property-to-an-existing-PDF-document/Program.cs index 21d318b5..ee72b425 100644 --- a/Forms/Set-the-ReadOnly-property-to-an-existing-PDF-document/.NET/Set-the-ReadOnly-property-to-an-existing-PDF-document/Program.cs +++ b/Forms/Set-the-ReadOnly-property-to-an-existing-PDF-document/.NET/Set-the-ReadOnly-property-to-an-existing-PDF-document/Program.cs @@ -1,25 +1,14 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 loaded form. -PdfLoadedForm loadedForm = loadedDocument.Form; - -//Set the form as read only. -loadedForm.ReadOnly = true; - -//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. - loadedDocument.Save(outputFileStream); -} + //Get the loaded form. + PdfLoadedForm loadedForm = loadedDocument.Form; + + //Set the form as read only. + loadedForm.ReadOnly = 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/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs index dd229aa7..eb715a6c 100644 --- a/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs +++ b/Getting Started/.NET/Create_PDF_NET/Create_PDF_NET/Program.cs @@ -2,21 +2,17 @@ using Syncfusion.Pdf; //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; -//Set the standard font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw the text. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); - -//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); -} -//Close the document. -document.Close(true); \ No newline at end of file + //Add a page to the document. + PdfPage page = document.Pages.Add(); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; + //Set the standard font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Draw the text. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Getting Started/.NET/Create_PDF_with_basic_elements_NET/Create_PDF_with_basic_elements_NET/Program.cs b/Getting Started/.NET/Create_PDF_with_basic_elements_NET/Create_PDF_with_basic_elements_NET/Program.cs index 7599a93b..d1b1dece 100644 --- a/Getting Started/.NET/Create_PDF_with_basic_elements_NET/Create_PDF_with_basic_elements_NET/Program.cs +++ b/Getting Started/.NET/Create_PDF_with_basic_elements_NET/Create_PDF_with_basic_elements_NET/Program.cs @@ -149,12 +149,8 @@ static void Main(string[] args) pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString('$' + string.Format("{0:N2}", total), font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 20), new SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); - //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/Getting Started/.NET/Create_PDF_with_image_NET/Create_PDF_with_image_NET/Program.cs b/Getting Started/.NET/Create_PDF_with_image_NET/Create_PDF_with_image_NET/Program.cs index e53644e5..8417f0fe 100644 --- a/Getting Started/.NET/Create_PDF_with_image_NET/Create_PDF_with_image_NET/Program.cs +++ b/Getting Started/.NET/Create_PDF_with_image_NET/Create_PDF_with_image_NET/Program.cs @@ -2,22 +2,18 @@ using Syncfusion.Pdf; //Create a new PDF document. -PdfDocument doc = new PdfDocument(); -//Add a page to the document. -PdfPage page = doc.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; -//Load the image from the disk. -FileStream imageStream = new FileStream(@"Data/Autumn Leaves.jpg", FileMode.Open, FileAccess.Read); -PdfBitmap image = new PdfBitmap(imageStream); -//Draw the image. -graphics.DrawImage(image, 0, 0); - -//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. - doc.Save(outputFileStream); + //Add a page to the document. + PdfPage page = document.Pages.Add(); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; + //Load the image from the disk. + FileStream imageStream = new FileStream(@"Data/Autumn Leaves.jpg", FileMode.Open, FileAccess.Read); + PdfBitmap image = new PdfBitmap(imageStream); + //Draw the image. + graphics.DrawImage(image, 0, 0); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -doc.Close(true); diff --git a/Getting Started/.NET/Create_PDF_with_table_NET/Create_PDF_with_table_NET/Program.cs b/Getting Started/.NET/Create_PDF_with_table_NET/Create_PDF_with_table_NET/Program.cs index e9b087ab..036e696f 100644 --- a/Getting Started/.NET/Create_PDF_with_table_NET/Create_PDF_with_table_NET/Program.cs +++ b/Getting Started/.NET/Create_PDF_with_table_NET/Create_PDF_with_table_NET/Program.cs @@ -1,38 +1,32 @@ - -using Syncfusion.Pdf.Grid; +using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; using System.Data; - //Create a new PDF document. -PdfDocument doc = new PdfDocument(); -//Add a page. -PdfPage page = doc.Pages.Add(); -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); -//Create a DataTable. -DataTable dataTable = new DataTable(); -//Add columns to the DataTable. -dataTable.Columns.Add("ProductID"); -dataTable.Columns.Add("ProductName"); -dataTable.Columns.Add("Quantity"); -dataTable.Columns.Add("UnitPrice"); -dataTable.Columns.Add("Discount"); -dataTable.Columns.Add("Price"); -//Add rows to the DataTable. -dataTable.Rows.Add(new object[] { "CA-1098", "Queso Cabrales", "12", "14", "1", "167" }); -dataTable.Rows.Add(new object[] { "LJ-0192-M", "Singaporean Hokkien Fried Mee", "10", "20", "3", "197" }); -dataTable.Rows.Add(new object[] { "SO-B909-M", "Mozzarella di Giovanni", "15", "65", "10", "956" }); -//Assign data source. -pdfGrid.DataSource = dataTable; -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); - -//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. - doc.Save(outputFileStream); + //Add a page. + PdfPage page = document.Pages.Add(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + //Create a DataTable. + DataTable dataTable = new DataTable(); + //Add columns to the DataTable. + dataTable.Columns.Add("ProductID"); + dataTable.Columns.Add("ProductName"); + dataTable.Columns.Add("Quantity"); + dataTable.Columns.Add("UnitPrice"); + dataTable.Columns.Add("Discount"); + dataTable.Columns.Add("Price"); + //Add rows to the DataTable. + dataTable.Rows.Add(new object[] { "CA-1098", "Queso Cabrales", "12", "14", "1", "167" }); + dataTable.Rows.Add(new object[] { "LJ-0192-M", "Singaporean Hokkien Fried Mee", "10", "20", "3", "197" }); + dataTable.Rows.Add(new object[] { "SO-B909-M", "Mozzarella di Giovanni", "15", "65", "10", "956" }); + //Assign data source. + pdfGrid.DataSource = dataTable; + //Draw grid to the page of PDF document. + pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -doc.Close(true); diff --git a/Getting Started/.NET/Filling_forms_NET/Filling_forms_NET/Program.cs b/Getting Started/.NET/Filling_forms_NET/Filling_forms_NET/Program.cs index cde3a462..c5f1e93c 100644 --- a/Getting Started/.NET/Filling_forms_NET/Filling_forms_NET/Program.cs +++ b/Getting Started/.NET/Filling_forms_NET/Filling_forms_NET/Program.cs @@ -1,39 +1,32 @@ - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; -//Load the PDF document. -FileStream docStream = new FileStream(@"Data/Form.pdf", FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Loads the form. -PdfLoadedForm form = loadedDocument.Form; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Loads the form. + PdfLoadedForm form = loadedDocument.Form; -//Fills the textbox field by using index. -(form.Fields[0] as PdfLoadedTextBoxField).Text = "John"; + //Fills the textbox field by using index. + (form.Fields[0] as PdfLoadedTextBoxField).Text = "John"; -//Fills the textbox fields by using field name. -(form.Fields["Last Name"] as PdfLoadedTextBoxField).Text = "Doe"; -(form.Fields["Address"] as PdfLoadedTextBoxField).Text = " John Doe \n 123 Main St \n Anytown, USA"; + //Fills the textbox fields by using field name. + (form.Fields["Last Name"] as PdfLoadedTextBoxField).Text = "Doe"; + (form.Fields["Address"] as PdfLoadedTextBoxField).Text = " John Doe \n 123 Main St \n Anytown, USA"; -//Loads the radio button group. -PdfLoadedRadioButtonItemCollection radioButtonCollection = (form.Fields["Gender"] as PdfLoadedRadioButtonListField).Items; + //Loads the radio button group. + PdfLoadedRadioButtonItemCollection radioButtonCollection = (form.Fields["Gender"] as PdfLoadedRadioButtonListField).Items; -//Checks the 'Male' option. -radioButtonCollection[0].Checked = true; + //Checks the 'Male' option. + radioButtonCollection[0].Checked = true; -//Loads the radio button group. -PdfLoadedRadioButtonItemCollection radioButtonCollection1 = (form.Fields["Occupation"] as PdfLoadedRadioButtonListField).Items; + //Loads the radio button group. + PdfLoadedRadioButtonItemCollection radioButtonCollection1 = (form.Fields["Occupation"] as PdfLoadedRadioButtonListField).Items; -//Checks the 'Male' option. -radioButtonCollection1[0].Checked = true; + //Checks the 'Male' option. + radioButtonCollection1[0].Checked = 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/Getting Started/.NET/HTML_string_to_PDF_NET/HTML_string_to_PDF_NET/Program.cs b/Getting Started/.NET/HTML_string_to_PDF_NET/HTML_string_to_PDF_NET/Program.cs index f8227846..3dd50198 100644 --- a/Getting Started/.NET/HTML_string_to_PDF_NET/HTML_string_to_PDF_NET/Program.cs +++ b/Getting Started/.NET/HTML_string_to_PDF_NET/HTML_string_to_PDF_NET/Program.cs @@ -1,5 +1,4 @@ - -using Syncfusion.HtmlConverter; +using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO; @@ -11,11 +10,8 @@ string baseUrl = @"C:/Temp/HTMLFiles/"; //Convert URL to PDF. PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); -//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/Getting Started/.NET/HTML_to_PDF_NET/HTML_to_PDF_NET/Program.cs b/Getting Started/.NET/HTML_to_PDF_NET/HTML_to_PDF_NET/Program.cs index cb9db99e..2f017c3b 100644 --- a/Getting Started/.NET/HTML_to_PDF_NET/HTML_to_PDF_NET/Program.cs +++ b/Getting Started/.NET/HTML_to_PDF_NET/HTML_to_PDF_NET/Program.cs @@ -1,5 +1,4 @@ - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.HtmlConverter; //Initialize HTML to PDF converter. @@ -7,11 +6,7 @@ //Convert URL to PDF document. PdfDocument document = htmlConverter.Convert("https://www.google.com"); -//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/Getting Started/.NET/Merge_PDF_documents_NET/Merge_PDF_documents_NET/Program.cs b/Getting Started/.NET/Merge_PDF_documents_NET/Merge_PDF_documents_NET/Program.cs index dc2c70ad..de9a0eed 100644 --- a/Getting Started/.NET/Merge_PDF_documents_NET/Merge_PDF_documents_NET/Program.cs +++ b/Getting Started/.NET/Merge_PDF_documents_NET/Merge_PDF_documents_NET/Program.cs @@ -1,5 +1,4 @@ - -using Syncfusion.Pdf; +using Syncfusion.Pdf; //Generate the PDF document. PdfDocument finalDoc = new PdfDocument(); @@ -10,11 +9,8 @@ // Merges PDFDocument. PdfDocumentBase.Merge(finalDoc, streams); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - finalDoc.Save(outputFileStream); -} +//Save the PDF document +finalDoc.Save(Path.GetFullPath(@"Output/Output.pdf")); + //Close the document. finalDoc.Close(true); diff --git a/Header and Footer/Adding-an-automatic-field-in-header-and-footer/.NET/Adding-an-automatic-field-in-header-and-footer/Program.cs b/Header and Footer/Adding-an-automatic-field-in-header-and-footer/.NET/Adding-an-automatic-field-in-header-and-footer/Program.cs index e95d3ab0..460bd651 100644 --- a/Header and Footer/Adding-an-automatic-field-in-header-and-footer/.NET/Adding-an-automatic-field-in-header-and-footer/Program.cs +++ b/Header and Footer/Adding-an-automatic-field-in-header-and-footer/.NET/Adding-an-automatic-field-in-header-and-footer/Program.cs @@ -1,70 +1,62 @@ -// 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 a header and draw the image. -RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Create the template for header. -PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); + //Create a header and draw the image. + RectangleF bounds = new RectangleF(0, 0, document.Pages[0].GetClientSize().Width, 50); -//Get stream from the image file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Logo.jpg"), FileMode.Open, FileAccess.Read); + //Create the template for header. + PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); -//Load the image file. -PdfImage image = new PdfBitmap(imageStream); + //Get stream from the image file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Logo.jpg"), FileMode.Open, FileAccess.Read); -//Draw the image in the header. -header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50)); + //Load the image file. + PdfImage image = new PdfBitmap(imageStream); -//Add the header at the top. -pdfDocument.Template.Top = header; + //Draw the image in the header. + header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50)); -//Create a Page template that can be used as footer. -PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); + //Add the header at the top. + document.Template.Top = header; -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); + //Create a Page template that can be used as footer. + PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); -//Create the brush. -PdfBrush brush = new PdfSolidBrush(Color.Black); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); -//Create page number field. -PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); + //Create the brush. + PdfBrush brush = new PdfSolidBrush(Color.Black); -//Create page count field. -PdfPageCountField count = new PdfPageCountField(font, brush); + //Create page number field. + PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); -//Add the fields in composite fields. -PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); -compositeField.Bounds = footer.Bounds; + //Create page count field. + PdfPageCountField count = new PdfPageCountField(font, brush); -//Draw the composite field in footer. -compositeField.Draw(footer.Graphics, new PointF(470, 40)); + //Add the fields in composite fields. + PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); + compositeField.Bounds = footer.Bounds; -//Add the footer template at the bottom. -pdfDocument.Template.Bottom = footer; + //Draw the composite field in footer. + compositeField.Draw(footer.Graphics, new PointF(470, 40)); -//Set the font. -font = new PdfStandardFont(PdfFontFamily.Helvetica, 25); + //Add the footer template at the bottom. + document.Template.Bottom = footer; -//Draw string. -pdfPage.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(10,10)); + //Set the font. + font = new PdfStandardFont(PdfFontFamily.Helvetica, 25); -//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 string. + pdfPage.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(10, 10)); -//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/Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs b/Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs index ed81179a..32efa01a 100644 --- a/Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs +++ b/Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs @@ -6,19 +6,19 @@ class Program { static void Main(string[] args) { - // Create a new PDF document. - PdfDocument document = new PdfDocument(); - - // Subscribe to the PageAdded event to add header and footer for every page. - document.Pages.PageAdded += (sender, e) => PageAddedHandler(sender, e); + //Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + // Subscribe to the PageAdded event to add header and footer for every page. + document.Pages.PageAdded += (sender, e) => PageAddedHandler(sender, e); - // Define content font and brush for main text. - PdfFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 18); - PdfBrush contentBrush = new PdfSolidBrush(Color.Black); + // Define content font and brush for main text. + PdfFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 18); + PdfBrush contentBrush = new PdfSolidBrush(Color.Black); - // Define the main instructional text. - string overflowText = - @"Creating PDF documentation programmatically with Syncfusion .NET libraries enables automation of reports, invoices, and technical manuals. + // Define the main instructional text. + string overflowText = +@"Creating PDF documentation programmatically with Syncfusion .NET libraries enables automation of reports, invoices, and technical manuals. Key Features: - Multi-page automatic content flow using pagination @@ -48,33 +48,29 @@ static void Main(string[] args) This concludes the instructional workflow for auto-paginated, footer-enhanced PDF generation in .NET."; - // Set the header and footer height - float headerHeight = 40f; - float footerHeight = 30f; + // Set the header and footer height + float headerHeight = 40f; + float footerHeight = 30f; - // Create a text element for automatic pagination. - PdfTextElement textElement = new PdfTextElement(overflowText, contentFont, contentBrush); + // Create a text element for automatic pagination. + PdfTextElement textElement = new PdfTextElement(overflowText, contentFont, contentBrush); - // Subscribe to the BeginPageLayout event to offset text on each new page below the header. - textElement.BeginPageLayout += (sender, args) => - { - // Always start content BELOW the header on every page. - args.Bounds = new RectangleF(0, headerHeight, args.Page.GetClientSize().Width, args.Page.GetClientSize().Height - headerHeight - footerHeight); - }; + // Subscribe to the BeginPageLayout event to offset text on each new page below the header. + textElement.BeginPageLayout += (sender, args) => + { + // Always start content BELOW the header on every page. + args.Bounds = new RectangleF(0, headerHeight, args.Page.GetClientSize().Width, args.Page.GetClientSize().Height - headerHeight - footerHeight); + }; - // Add the first page. - PdfPage firstPage = document.Pages.Add(); + // Add the first page. + PdfPage firstPage = document.Pages.Add(); - // Start drawing content (pagination and event will handle rest). - textElement.Draw(firstPage, new PointF(0, headerHeight)); + // Start drawing content (pagination and event will handle rest). + textElement.Draw(firstPage, new PointF(0, headerHeight)); - // Save and close the document. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - document.Save(outputFileStream); - } - document.Close(true); - } + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} // Add header and footer to every page. static void PageAddedHandler(object sender, PageAddedEventArgs e) diff --git a/Header and Footer/Header-Management-in-PDF-Sections/.NET/Header-Management-in-PDF-Sections/Program.cs b/Header and Footer/Header-Management-in-PDF-Sections/.NET/Header-Management-in-PDF-Sections/Program.cs index b107ec9a..0a1de8b2 100644 --- a/Header and Footer/Header-Management-in-PDF-Sections/.NET/Header-Management-in-PDF-Sections/Program.cs +++ b/Header and Footer/Header-Management-in-PDF-Sections/.NET/Header-Management-in-PDF-Sections/Program.cs @@ -8,42 +8,38 @@ public class Program { public static void Main(string[] args) { - // Initialize the PDF document - PdfDocument document = new PdfDocument(); - - // Define the font for the header - PdfFont headerfont = new PdfStandardFont(PdfFontFamily.Helvetica, 12); - - // Create the first section with headers - PdfSection sectionWithHeaders = document.Sections.Add(); - // Apply header to this section - sectionWithHeaders.Template.Top = CreateHeaderTemplate(headerfont); - - // Add 5 pages in the first section - for (int i = 0; i < 5; i++) + //Create a new PDF document. + using (PdfDocument document = new PdfDocument()) { - PdfPage page = sectionWithHeaders.Pages.Add(); - DrawContentOnPage(page, $"Content for page {i + 1} in section with headers"); + // Define the font for the header + PdfFont headerfont = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + + // Create the first section with headers + PdfSection sectionWithHeaders = document.Sections.Add(); + // Apply header to this section + sectionWithHeaders.Template.Top = CreateHeaderTemplate(headerfont); + + // Add 5 pages in the first section + for (int i = 0; i < 5; i++) + { + PdfPage page = sectionWithHeaders.Pages.Add(); + DrawContentOnPage(page, $"Content for page {i + 1} in section with headers"); + } + + // Create the second section without headers + PdfSection sectionWithoutHeaders = document.Sections.Add(); + + // Add 5 pages in the second section + for (int i = 0; i < 5; i++) + { + PdfPage page = sectionWithoutHeaders.Pages.Add(); + DrawContentOnPage(page, $"Content for page {i + 6} in section without headers"); + } + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - // Create the second section without headers - PdfSection sectionWithoutHeaders = document.Sections.Add(); - - // Add 5 pages in the second section - for (int i = 0; i < 5; i++) - { - PdfPage page = sectionWithoutHeaders.Pages.Add(); - DrawContentOnPage(page, $"Content for page {i + 6} in section without headers"); - } - - // Save the PDF document - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - document.Save(outputFileStream); - } - document.Close(true); - } - private static PdfPageTemplateElement CreateHeaderTemplate(PdfFont headerfont) { RectangleF rect = new RectangleF(0, 0, 500, 50); // Adjust width and height as needed diff --git a/Hyperlinks/Add-a-web-hyperlink-to-an-existing-PDF-document/.NET/Add-a-web-hyperlink-to-an-existing-PDF-document/Program.cs b/Hyperlinks/Add-a-web-hyperlink-to-an-existing-PDF-document/.NET/Add-a-web-hyperlink-to-an-existing-PDF-document/Program.cs index 5bc46d0e..069949fc 100644 --- a/Hyperlinks/Add-a-web-hyperlink-to-an-existing-PDF-document/.NET/Add-a-web-hyperlink-to-an-existing-PDF-document/Program.cs +++ b/Hyperlinks/Add-a-web-hyperlink-to-an-existing-PDF-document/.NET/Add-a-web-hyperlink-to-an-existing-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.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 page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); -//Create the Text Web Link. -PdfTextWebLink textLink = new PdfTextWebLink(); + //Create the Text Web Link. + PdfTextWebLink textLink = new PdfTextWebLink(); -//Set the hyperlink. -textLink.Url = "http://www.syncfusion.com"; + //Set the hyperlink. + textLink.Url = "http://www.syncfusion.com"; -//Set the link text. -textLink.Text = "Syncfusion .NET components and controls"; + //Set the link text. + textLink.Text = "Syncfusion .NET components and controls"; -//Set the font. -textLink.Font = font; + //Set the font. + textLink.Font = font; -//Draw the hyperlink in loaded page graphics. -textLink.DrawTextWebLink(loadedPage.Graphics, new PointF(10, 40)); + //Draw the hyperlink in loaded page graphics. + textLink.DrawTextWebLink(loadedPage.Graphics, new PointF(10, 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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Hyperlinks/Add-the-hyperlink-for-internal-document-navigation/.NET/Add-the-hyperlink-for-internal-document-navigation/Program.cs b/Hyperlinks/Add-the-hyperlink-for-internal-document-navigation/.NET/Add-the-hyperlink-for-internal-document-navigation/Program.cs index bec1ee52..ef630c6c 100644 --- a/Hyperlinks/Add-the-hyperlink-for-internal-document-navigation/.NET/Add-the-hyperlink-for-internal-document-navigation/Program.cs +++ b/Hyperlinks/Add-the-hyperlink-for-internal-document-navigation/.NET/Add-the-hyperlink-for-internal-document-navigation/Program.cs @@ -1,52 +1,44 @@ -// 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(); - -//Create a new rectangle. -RectangleF docLinkAnnotationBounds = new RectangleF(10, 40, 30, 30); +using (PdfDocument document = new PdfDocument()) +{ + //Create a new page. + PdfPage page = document.Pages.Add(); -//Create a new document link annotation. -PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationBounds); + //Create a new rectangle. + RectangleF docLinkAnnotationBounds = new RectangleF(10, 40, 30, 30); -//Set the annotation flags. -documentLinkAnnotation.AnnotationFlags = PdfAnnotationFlags.NoRotate; + //Create a new document link annotation. + PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationBounds); -//Set the annotation text. -documentLinkAnnotation.Text = "Document link annotation"; + //Set the annotation flags. + documentLinkAnnotation.AnnotationFlags = PdfAnnotationFlags.NoRotate; -//Set the annotation's color. -documentLinkAnnotation.Color = new PdfColor(Color.Navy); + //Set the annotation text. + documentLinkAnnotation.Text = "Document link annotation"; -//Creates another page. -PdfPage navigationPage = document.Pages.Add(); + //Set the annotation's color. + documentLinkAnnotation.Color = new PdfColor(Color.Navy); -//Set the destination. -documentLinkAnnotation.Destination = new PdfDestination(navigationPage); + //Creates another page. + PdfPage navigationPage = document.Pages.Add(); -//Set the document link annotation location. -documentLinkAnnotation.Destination.Location = new PointF(10, 0); + //Set the destination. + documentLinkAnnotation.Destination = new PdfDestination(navigationPage); -//Set the document annotation zoom level. -documentLinkAnnotation.Destination.Zoom = 5; + //Set the document link annotation location. + documentLinkAnnotation.Destination.Location = new PointF(10, 0); -//Add this annotation to a new page. -page.Annotations.Add(documentLinkAnnotation); + //Set the document annotation zoom level. + documentLinkAnnotation.Destination.Zoom = 5; -//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(documentLinkAnnotation); -//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/Hyperlinks/Internal-document-navigation-to-an-existing-PDF/.NET/Internal-document-navigation-to-an-existing-PDF/Program.cs b/Hyperlinks/Internal-document-navigation-to-an-existing-PDF/.NET/Internal-document-navigation-to-an-existing-PDF/Program.cs index 83838e19..fc4fa6e3 100644 --- a/Hyperlinks/Internal-document-navigation-to-an-existing-PDF/.NET/Internal-document-navigation-to-an-existing-PDF/Program.cs +++ b/Hyperlinks/Internal-document-navigation-to-an-existing-PDF/.NET/Internal-document-navigation-to-an-existing-PDF/Program.cs @@ -1,46 +1,35 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; 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 page. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Create a new rectangle. -RectangleF docLinkAnnotationBounds = new RectangleF(10, 40, 30, 30); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a new document link annotation. -PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationBounds); + //Create a new rectangle. + RectangleF docLinkAnnotationBounds = new RectangleF(10, 40, 30, 30); -//Set the annotation text. -documentLinkAnnotation.Text = "Document link annotation"; + //Create a new document link annotation. + PdfDocumentLinkAnnotation documentLinkAnnotation = new PdfDocumentLinkAnnotation(docLinkAnnotationBounds); -//Set the existing page for navigation. -PdfLoadedPage navigationPage = loadedDocument.Pages[1] as PdfLoadedPage; + //Set the annotation text. + documentLinkAnnotation.Text = "Document link annotation"; -//Set the pdf destination. -documentLinkAnnotation.Destination = new PdfDestination(navigationPage); + //Set the existing page for navigation. + PdfLoadedPage navigationPage = loadedDocument.Pages[1] as PdfLoadedPage; -//Set the document link annotation location. -documentLinkAnnotation.Destination.Location = new PointF(10, 0); + //Set the pdf destination. + documentLinkAnnotation.Destination = new PdfDestination(navigationPage); -//Add this annotation to respective page. -loadedPage.Annotations.Add(documentLinkAnnotation); + //Set the document link annotation location. + documentLinkAnnotation.Destination.Location = new PointF(10, 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); -} + //Add this annotation to respective page. + loadedPage.Annotations.Add(documentLinkAnnotation); -//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/Hyperlinks/Navigate-to-specific-URL-from-a-PDF-document/.NET/Navigate-to-specific-URL-from-a-PDF-document/Program.cs b/Hyperlinks/Navigate-to-specific-URL-from-a-PDF-document/.NET/Navigate-to-specific-URL-from-a-PDF-document/Program.cs index cffe5760..848b6ad5 100644 --- a/Hyperlinks/Navigate-to-specific-URL-from-a-PDF-document/.NET/Navigate-to-specific-URL-from-a-PDF-document/Program.cs +++ b/Hyperlinks/Navigate-to-specific-URL-from-a-PDF-document/.NET/Navigate-to-specific-URL-from-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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); - -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create the Text Web Link. -PdfTextWebLink textLink = new PdfTextWebLink(); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f); -//Set the hyperlink. -textLink.Url = "http://www.syncfusion.com"; + //Create the Text Web Link. + PdfTextWebLink textLink = new PdfTextWebLink(); -//Set the link text. -textLink.Text = "Syncfusion .NET components and controls"; + //Set the hyperlink. + textLink.Url = "http://www.syncfusion.com"; -//Set the font. -textLink.Font = font; + //Set the link text. + textLink.Text = "Syncfusion .NET components and controls"; -//Draw the hyperlink in PDF page. -textLink.DrawTextWebLink(page, new PointF(10, 40)); + //Set the font. + textLink.Font = font; -//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 hyperlink in PDF page. + textLink.DrawTextWebLink(page, new PointF(10, 40)); -//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/Hyperlinks/Open-a-file-in-relative-path-using-action/.NET Framework/Open-a-file-in-relative-path-using-action/Program.cs b/Hyperlinks/Open-a-file-in-relative-path-using-action/.NET Framework/Open-a-file-in-relative-path-using-action/Program.cs index 4b637175..b514c3f1 100644 --- a/Hyperlinks/Open-a-file-in-relative-path-using-action/.NET Framework/Open-a-file-in-relative-path-using-action/Program.cs +++ b/Hyperlinks/Open-a-file-in-relative-path-using-action/.NET Framework/Open-a-file-in-relative-path-using-action/Program.cs @@ -39,9 +39,6 @@ static void Main(string[] args) //Close the document. document.Close(); - - //This will open the PDF file so, the result will be seen in default PDF Viewer - Process.Start("Output.pdf"); } } } diff --git a/Image Extraction/Extract-images-from-PDF-documents/.NET/Extract-images-from-PDF-documents/Program.cs b/Image Extraction/Extract-images-from-PDF-documents/.NET/Extract-images-from-PDF-documents/Program.cs index 37e22074..1547ad2c 100644 --- a/Image Extraction/Extract-images-from-PDF-documents/.NET/Extract-images-from-PDF-documents/Program.cs +++ b/Image Extraction/Extract-images-from-PDF-documents/.NET/Extract-images-from-PDF-documents/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using System.IO; //Initialize the PDF document extractor. diff --git a/Image Extraction/Extract-images-from-a-PDF-pages/.NET/Extract-images-from-a-PDF-pages/Program.cs b/Image Extraction/Extract-images-from-a-PDF-pages/.NET/Extract-images-from-a-PDF-pages/Program.cs index ddd2f037..289e0bea 100644 --- a/Image Extraction/Extract-images-from-a-PDF-pages/.NET/Extract-images-from-a-PDF-pages/Program.cs +++ b/Image Extraction/Extract-images-from-a-PDF-pages/.NET/Extract-images-from-a-PDF-pages/Program.cs @@ -1,14 +1,9 @@ - - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Exporting; 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")); //Load the first page. PdfPageBase pageBase = loadedDocument.Pages[0]; @@ -23,4 +18,4 @@ } //Close the document. -loadedDocument.Close(true); +loadedDocument.Close(true); \ No newline at end of file diff --git a/Image Extraction/Extract-the-image-info-from-a-PDF-page/.NET/Extract-the-image-info-from-a-PDF-page/Program.cs b/Image Extraction/Extract-the-image-info-from-a-PDF-page/.NET/Extract-the-image-info-from-a-PDF-page/Program.cs index b37591d1..5c72813f 100644 --- a/Image Extraction/Extract-the-image-info-from-a-PDF-page/.NET/Extract-the-image-info-from-a-PDF-page/Program.cs +++ b/Image Extraction/Extract-the-image-info-from-a-PDF-page/.NET/Extract-the-image-info-from-a-PDF-page/Program.cs @@ -1,15 +1,10 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Exporting; 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")); //Load the first page. PdfPageBase pageBase = loadedDocument.Pages[0]; diff --git a/Images/Add-a-mask-to-TIFF-image/.NET/Add-a-mask-to-TIFF-image/Program.cs b/Images/Add-a-mask-to-TIFF-image/.NET/Add-a-mask-to-TIFF-image/Program.cs index e8875c39..eadd384a 100644 --- a/Images/Add-a-mask-to-TIFF-image/.NET/Add-a-mask-to-TIFF-image/Program.cs +++ b/Images/Add-a-mask-to-TIFF-image/.NET/Add-a-mask-to-TIFF-image/Program.cs @@ -1,42 +1,34 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; -//Create a PDF document. -PdfDocument document = new PdfDocument(); - -//Add pages to the document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add pages 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; -//Get stream from the existing TIF file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.tif"), FileMode.Open, FileAccess.Read); + //Get stream from the existing TIF file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.tif"), FileMode.Open, FileAccess.Read); -//Load the image from stream. -PdfTiffImage image = new PdfTiffImage(imageStream); + //Load the image from stream. + PdfTiffImage image = new PdfTiffImage(imageStream); -//Get stream from the image file. -FileStream maskStream = new FileStream(Path.GetFullPath(@"Data/mask2.bmp"), FileMode.Open, FileAccess.Read); + //Get stream from the image file. + FileStream maskStream = new FileStream(Path.GetFullPath(@"Data/mask2.bmp"), FileMode.Open, FileAccess.Read); -//Load the image mask file from stream. -PdfImageMask mask = new PdfImageMask(new PdfTiffImage(maskStream)); + //Load the image mask file from stream. + PdfImageMask mask = new PdfImageMask(new PdfTiffImage(maskStream)); -//Assign the masking image to TIF image. -image.Mask = mask; + //Assign the masking image to TIF image. + image.Mask = mask; -//Draw the image. -graphics.DrawImage(image, 0, 0); + //Draw the image. + graphics.DrawImage(image, 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); - diff --git a/Images/Add-transparancy-and-rotation-to-the-image/.NET/Add-transparancy-and-rotation-to-the-image/Program.cs b/Images/Add-transparancy-and-rotation-to-the-image/.NET/Add-transparancy-and-rotation-to-the-image/Program.cs index 6a5b3ec6..c259d063 100644 --- a/Images/Add-transparancy-and-rotation-to-the-image/.NET/Add-transparancy-and-rotation-to-the-image/Program.cs +++ b/Images/Add-transparancy-and-rotation-to-the-image/.NET/Add-transparancy-and-rotation-to-the-image/Program.cs @@ -1,45 +1,37 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; -//Create Document. -PdfDocument document = new PdfDocument(); - -//Add a new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page. + PdfPage page = document.Pages.Add(); -//Load a image as stream. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/logo.png"), FileMode.Open, FileAccess.Read); + //Load a image as stream. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/logo.png"), FileMode.Open, FileAccess.Read); -//Load a bitmap. -PdfBitmap image = new PdfBitmap(imageStream); + //Load a bitmap. + PdfBitmap image = new PdfBitmap(imageStream); -//Save the current graphics state. -PdfGraphicsState state = page.Graphics.Save(); + //Save the current graphics state. + PdfGraphicsState state = page.Graphics.Save(); -//Translate the coordinate system to the required position. -page.Graphics.TranslateTransform(20, 100); + //Translate the coordinate system to the required position. + page.Graphics.TranslateTransform(20, 100); -//Apply transparency. -page.Graphics.SetTransparency(0.5f); + //Apply transparency. + page.Graphics.SetTransparency(0.5f); -//Rotate the coordinate system. -page.Graphics.RotateTransform(-45); + //Rotate the coordinate system. + page.Graphics.RotateTransform(-45); -//Draw image. -image.Draw(page, 0, 100); + //Draw image. + image.Draw(page, 0, 100); -//Restore the graphics state. -page.Graphics.Restore(state); + //Restore the graphics state. + page.Graphics.Restore(state); -//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/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs index cec8b91f..3f524b31 100644 --- a/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs +++ b/Images/Convert_Image_to_PDF/.NET/Convert_Image_to_PDF/Program.cs @@ -15,13 +15,9 @@ // Convert the image to a PDF document using the ImageToPdfConverter PdfDocument pdfDocument = imageToPdfConverter.Convert(imageStream); - //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/Images/Converting-multi-page-TIFF-to-PDF/.NET/Converting-multi-page-TIFF-to-PDF/Program.cs b/Images/Converting-multi-page-TIFF-to-PDF/.NET/Converting-multi-page-TIFF-to-PDF/Program.cs index 717f9358..8d9a118a 100644 --- a/Images/Converting-multi-page-TIFF-to-PDF/.NET/Converting-multi-page-TIFF-to-PDF/Program.cs +++ b/Images/Converting-multi-page-TIFF-to-PDF/.NET/Converting-multi-page-TIFF-to-PDF/Program.cs @@ -1,42 +1,34 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); +using (PdfDocument document = new PdfDocument()) +{ + //Set page margins. + document.PageSettings.Margins.All = 0; -//Set page margins. -document.PageSettings.Margins.All = 0; + //Load the multi frame TIFF image from the disk. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.tiff"), FileMode.Open, FileAccess.Read); + PdfTiffImage tiffImage = new PdfTiffImage(imageStream); -//Load the multi frame TIFF image from the disk. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/image.tiff"), FileMode.Open, FileAccess.Read); -PdfTiffImage tiffImage = new PdfTiffImage(imageStream); + //Get the frame count. + int frameCount = tiffImage.FrameCount; -//Get the frame count. -int frameCount = tiffImage.FrameCount; + //Access each frame and draw into the page. + for (int i = 0; i < frameCount; i++) + { + //Add new page to PDF document. + PdfPage page = document.Pages.Add(); -//Access each frame and draw into the page. -for (int i = 0; i < frameCount; i++) -{ - //Add new page to PDF document. - PdfPage page = document.Pages.Add(); + //Create graphics for PDF page + PdfGraphics graphics = page.Graphics; - //Create graphics for PDF page - PdfGraphics graphics = page.Graphics; + tiffImage.ActiveFrame = i; - tiffImage.ActiveFrame = i; + //Draw the image. + graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); + } - //Draw the image. - graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//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); diff --git a/Images/Insert-image-in-a-new-PDF-document/.NET/Insert-image-in-a-new-PDF-document/Program.cs b/Images/Insert-image-in-a-new-PDF-document/.NET/Insert-image-in-a-new-PDF-document/Program.cs index 44d2ba12..4f52dbbc 100644 --- a/Images/Insert-image-in-a-new-PDF-document/.NET/Insert-image-in-a-new-PDF-document/Program.cs +++ b/Images/Insert-image-in-a-new-PDF-document/.NET/Insert-image-in-a-new-PDF-document/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +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(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Get stream from the existing image file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Load the image file. -PdfBitmap image = new PdfBitmap(imageStream); + //Get stream from the existing image file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); -//Draw the image. -graphics.DrawImage(image, 0, 0); + //Load the image file. + PdfBitmap image = new PdfBitmap(imageStream); -//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 image. + graphics.DrawImage(image, 0, 0); -//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/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-PDF-document/Program.cs b/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-PDF-document/Program.cs index aed7bb44..181de058 100644 --- a/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-PDF-document/Program.cs +++ b/Images/Insert-image-in-an-existing-PDF-document/.NET/Insert-image-in-an-existing-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.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); - -//Get first page from document. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get first page from document. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create PDF graphics for the page. -PdfGraphics graphics = loadedPage.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = loadedPage.Graphics; -//Get stream from the existing image file. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); + //Get stream from the existing image file. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); -//Load the image from the disk. -PdfBitmap image = new PdfBitmap(imageStream); + //Load the image from the disk. + PdfBitmap image = new PdfBitmap(imageStream); -//Draw the image. -graphics.DrawImage(image, 0, 0); + //Draw the image. + graphics.DrawImage(image, 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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); - diff --git a/Images/Paginate-an-image-in-PDF-document/.NET/Paginate-an-image-in-PDF-document/Program.cs b/Images/Paginate-an-image-in-PDF-document/.NET/Paginate-an-image-in-PDF-document/Program.cs index a808b83f..16386aed 100644 --- a/Images/Paginate-an-image-in-PDF-document/.NET/Paginate-an-image-in-PDF-document/Program.cs +++ b/Images/Paginate-an-image-in-PDF-document/.NET/Paginate-an-image-in-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.Graphics; -//Create Document. -PdfDocument document = new PdfDocument(); - -//Add new page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add new page. + PdfPage page = document.Pages.Add(); -//Load a bitmap. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); -PdfBitmap image = new PdfBitmap(imageStream); + //Load a bitmap. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); + PdfBitmap image = new PdfBitmap(imageStream); -//Set layout property to make the element break across the pages. -PdfLayoutFormat format = new PdfLayoutFormat(); -format.Break = PdfLayoutBreakType.FitPage; -format.Layout = PdfLayoutType.Paginate; + //Set layout property to make the element break across the pages. + PdfLayoutFormat format = new PdfLayoutFormat(); + format.Break = PdfLayoutBreakType.FitPage; + format.Layout = PdfLayoutType.Paginate; -//Draw image. -image.Draw(page, 20, 400, format); + //Draw image. + image.Draw(page, 20, 400, format); -//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/Images/Remove-images-from-PDF-document/.NET/Remove-images-from-PDF-document/Program.cs b/Images/Remove-images-from-PDF-document/.NET/Remove-images-from-PDF-document/Program.cs index 7360ffd2..d8722624 100644 --- a/Images/Remove-images-from-PDF-document/.NET/Remove-images-from-PDF-document/Program.cs +++ b/Images/Remove-images-from-PDF-document/.NET/Remove-images-from-PDF-document/Program.cs @@ -1,28 +1,19 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Exporting; using Syncfusion.Pdf.Parsing; -//Get stream from an existing PDF document. -FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Load the first page. -PdfPageBase pageBase = loadedDocument.Pages[0]; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the first page. + PdfPageBase pageBase = loadedDocument.Pages[0]; -//Extract images from the first page. -PdfImageInfo[] imageInfo = loadedDocument.Pages[0].GetImagesInfo(); + //Extract images from the first page. + PdfImageInfo[] imageInfo = loadedDocument.Pages[0].GetImagesInfo(); -//Remove the Image. -pageBase.RemoveImage(imageInfo[0]); + //Remove the Image. + pageBase.RemoveImage(imageInfo[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/JavaScript/Add-JavaScript-action-to-the-form-fields-in-a-PDF/.NET/Add-JavaScript-action-to-the-form-fields-in-a-PDF/Program.cs b/JavaScript/Add-JavaScript-action-to-the-form-fields-in-a-PDF/.NET/Add-JavaScript-action-to-the-form-fields-in-a-PDF/Program.cs index 0aa025f9..f76f76f6 100644 --- a/JavaScript/Add-JavaScript-action-to-the-form-fields-in-a-PDF/.NET/Add-JavaScript-action-to-the-form-fields-in-a-PDF/Program.cs +++ b/JavaScript/Add-JavaScript-action-to-the-form-fields-in-a-PDF/.NET/Add-JavaScript-action-to-the-form-fields-in-a-PDF/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 with the properties. -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 field action of PDF \")"); + //Create a new PdfButtonField with the properties. + 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 field action of PDF \")"); -//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/JavaScript/Add-JavaScript-to-3D-annotation-in-a-PDF-document/.NET/Add-JavaScript-to-3D-annotation-in-a-PDF-document/Program.cs b/JavaScript/Add-JavaScript-to-3D-annotation-in-a-PDF-document/.NET/Add-JavaScript-to-3D-annotation-in-a-PDF-document/Program.cs index 96962204..e5bcd06a 100644 --- a/JavaScript/Add-JavaScript-to-3D-annotation-in-a-PDF-document/.NET/Add-JavaScript-to-3D-annotation-in-a-PDF-document/Program.cs +++ b/JavaScript/Add-JavaScript-to-3D-annotation-in-a-PDF-document/.NET/Add-JavaScript-to-3D-annotation-in-a-PDF-document/Program.cs @@ -1,39 +1,31 @@ -// 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(); - -//Get stream from the U3D annotation. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/design.u3d"), FileMode.Open, FileAccess.Read); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Creates a new page. + PdfPage page = document.Pages.Add(); -//Creates a new PDF 3D annotation. -Pdf3DAnnotation pdf3dAnnotation = new Pdf3DAnnotation(new RectangleF(10, 50, 300, 150), inputStream); + //Get stream from the U3D annotation. + FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/design.u3d"), FileMode.Open, FileAccess.Read); -//Assign JavaScript script. -pdf3dAnnotation.OnInstantiate = "host.getURL(\"http://www.google.com\")"; + //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; + //Assign JavaScript script. + pdf3dAnnotation.OnInstantiate = "host.getURL(\"http://www.google.com\")"; -//Adds annotation to page. -page.Annotations.Add(pdf3dAnnotation); + //Handles the activation of the 3D annotation. + Pdf3DActivation activation = new Pdf3DActivation(); + activation.ActivationMode = Pdf3DActivationMode.ExplicitActivation; + activation.ShowToolbar = true; + pdf3dAnnotation.Activation = activation; -//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 page. + page.Annotations.Add(pdf3dAnnotation); -//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/JavaScript/Add-the-JavaScript-action-to-the-PDF-document/.NET/Add-the-JavaScript-action-to-the-PDF-document/Program.cs b/JavaScript/Add-the-JavaScript-action-to-the-PDF-document/.NET/Add-the-JavaScript-action-to-the-PDF-document/Program.cs index 36cd3282..e543c579 100644 --- a/JavaScript/Add-the-JavaScript-action-to-the-PDF-document/.NET/Add-the-JavaScript-action-to-the-PDF-document/Program.cs +++ b/JavaScript/Add-the-JavaScript-action-to-the-PDF-document/.NET/Add-the-JavaScript-action-to-the-PDF-document/Program.cs @@ -1,26 +1,18 @@ -// 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/Layer/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/.NET/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/Program.cs b/Layer/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/.NET/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/Program.cs index 83b90511..2e16ca91 100644 --- a/Layer/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/.NET/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/Program.cs +++ b/Layer/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/.NET/Add-a-lock-state-to-the-layer-in-a-new-PDF-document/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; -//Creating a 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 layer. -PdfLayer layer = document.Layers.Add("Layer"); + //Create a layer. + PdfLayer layer = document.Layers.Add("Layer"); -//Set a lock state. -layer.Locked = true; + //Set a lock state. + layer.Locked = true; -//Create graphics for a layer. -PdfGraphics graphics = layer.CreateGraphics(page); + //Create graphics for a layer. + PdfGraphics graphics = layer.CreateGraphics(page); -//Draw ellipse. -graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 50, 40, 40)); + //Draw ellipse. + graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 50, 40, 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. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs b/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs index aaa0f59e..caaade8c 100644 --- a/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs +++ b/Layer/Add-annotation-to-the-layer-in-an-existing-PDF-document/.NET/Add-annotation-to-the-layer-in-an-existing-PDF-document/Program.cs @@ -1,48 +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.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; -//Add the layer. -PdfLayer Layer = loadedDocument.Layers.Add("Layer"); + //Add the layer. + PdfLayer Layer = loadedDocument.Layers.Add("Layer"); -//Create graphics for layer. -PdfGraphics graphics = Layer.CreateGraphics(loadedPage); + //Create graphics for layer. + PdfGraphics graphics = Layer.CreateGraphics(loadedPage); -//Draw ellipse. -graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 80, 40, 40)); + //Draw ellipse. + graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 80, 40, 40)); -//Create square annotation. -PdfSquareAnnotation annotation = new PdfSquareAnnotation(new RectangleF(200, 260, 50, 50), "Square annotation"); + //Create square annotation. + PdfSquareAnnotation annotation = new PdfSquareAnnotation(new RectangleF(200, 260, 50, 50), "Square annotation"); -//Set the annotation color. -annotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); + //Set the annotation color. + annotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); -//Set layer to annotation. -annotation.Layer = Layer; + //Set layer to annotation. + annotation.Layer = Layer; -//Add annotation to the created page. -loadedPage.Annotations.Add(annotation); + //Add annotation to the created page. + loadedPage.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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -loadedDocument.Close(true); - diff --git a/Layer/Add-nested-layers-in-the-PDF-document/.NET/Add-nested-layers-in-the-PDF-document/Program.cs b/Layer/Add-nested-layers-in-the-PDF-document/.NET/Add-nested-layers-in-the-PDF-document/Program.cs index 8c8fe030..689876f2 100644 --- a/Layer/Add-nested-layers-in-the-PDF-document/.NET/Add-nested-layers-in-the-PDF-document/Program.cs +++ b/Layer/Add-nested-layers-in-the-PDF-document/.NET/Add-nested-layers-in-the-PDF-document/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.Graphics; -//Create the PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Add the parent layer. -PdfLayer layer = document.Layers.Add("Layer1"); + //Add the parent layer. + PdfLayer layer = document.Layers.Add("Layer1"); -//Create graphics for layer. -PdfGraphics graphics = layer.CreateGraphics(page); + //Create graphics for layer. + PdfGraphics graphics = layer.CreateGraphics(page); -//Set translate transform for the graphics. -graphics.TranslateTransform(100, 60); + //Set translate transform for the graphics. + graphics.TranslateTransform(100, 60); -//Draw an arc. -PdfPen pen = new PdfPen(Color.Red, 50); + //Draw an arc. + PdfPen pen = new PdfPen(Color.Red, 50); -//Set the bounds. -RectangleF bounds = new RectangleF(0, 0, 50, 50); + //Set the bounds. + RectangleF bounds = new RectangleF(0, 0, 50, 50); -//Draw an arc in layer graphics. -graphics.DrawArc(pen, bounds, 360, 360); + //Draw an arc in layer graphics. + graphics.DrawArc(pen, bounds, 360, 360); -//Add the child layer. -PdfLayer layer2 = layer.Layers.Add("Layer2"); + //Add the child layer. + PdfLayer layer2 = layer.Layers.Add("Layer2"); -//Create graphics for child layer. -graphics = layer2.CreateGraphics(page); + //Create graphics for child layer. + graphics = layer2.CreateGraphics(page); -//Set translate tranform for layer graphics. -graphics.TranslateTransform(100, 180); + //Set translate tranform for layer graphics. + graphics.TranslateTransform(100, 180); -//Draw an ellipse. -graphics.DrawEllipse(pen, bounds); + //Draw an ellipse. + graphics.DrawEllipse(pen, 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. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Layer/Add-the-multiple-layers-in-an-existing-PDF-document/.NET/Add-the-multiple-layers-in-an-existing-PDF-document/Program.cs b/Layer/Add-the-multiple-layers-in-an-existing-PDF-document/.NET/Add-the-multiple-layers-in-an-existing-PDF-document/Program.cs index 23a9ff0f..67d71583 100644 --- a/Layer/Add-the-multiple-layers-in-an-existing-PDF-document/.NET/Add-the-multiple-layers-in-an-existing-PDF-document/Program.cs +++ b/Layer/Add-the-multiple-layers-in-an-existing-PDF-document/.NET/Add-the-multiple-layers-in-an-existing-PDF-document/Program.cs @@ -1,55 +1,43 @@ -// 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. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Add the first layer. -PdfPageLayer layer = loadedPage.Layers.Add("Layer1"); + //Add the first layer. + PdfPageLayer layer = loadedPage.Layers.Add("Layer1"); -//Create graphics for the layer. -PdfGraphics graphics = layer.Graphics; + //Create graphics for the layer. + PdfGraphics graphics = layer.Graphics; -//Set translate transform for the graphics. -graphics.TranslateTransform(100, 60); + //Set translate transform for the graphics. + graphics.TranslateTransform(100, 60); -//Draw arc. -PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Gray, 50); + //Draw arc. + PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Gray, 50); -RectangleF bounds = new RectangleF(0, 0, 50, 50); + RectangleF bounds = new RectangleF(0, 0, 50, 50); -//Draw arc in layer graphics. -graphics.DrawArc(pen, bounds, 360, 360); + //Draw arc in layer graphics. + graphics.DrawArc(pen, bounds, 360, 360); -//Add another layer on the page. -PdfPageLayer layer2 = loadedPage.Layers.Add("Layer2"); + //Add another layer on the page. + PdfPageLayer layer2 = loadedPage.Layers.Add("Layer2"); -//Create graphics for layer. -graphics = layer2.Graphics; + //Create graphics for layer. + graphics = layer2.Graphics; -//Set translate transform for layer graphics. -graphics.TranslateTransform(100, 180); + //Set translate transform for layer graphics. + graphics.TranslateTransform(100, 180); -//Draw ellipse. -graphics.DrawEllipse(pen, bounds); + //Draw ellipse. + graphics.DrawEllipse(pen, 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/Layer/Adding-annotation-to-layer-in-the-PDF-document/.NET/Adding-annotation-to-layer-in-the-PDF-document/Program.cs b/Layer/Adding-annotation-to-layer-in-the-PDF-document/.NET/Adding-annotation-to-layer-in-the-PDF-document/Program.cs index de24ae6b..b778d441 100644 --- a/Layer/Adding-annotation-to-layer-in-the-PDF-document/.NET/Adding-annotation-to-layer-in-the-PDF-document/Program.cs +++ b/Layer/Adding-annotation-to-layer-in-the-PDF-document/.NET/Adding-annotation-to-layer-in-the-PDF-document/Program.cs @@ -1,43 +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; -//Create new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page. -PdfPage page = document.Pages.Add(); - -//Add the layer. -PdfLayer layer = document.Layers.Add("Layer"); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add page. + PdfPage page = document.Pages.Add(); -//Create graphics for layer. -PdfGraphics graphics = layer.CreateGraphics(page); + //Add the layer. + PdfLayer layer = document.Layers.Add("Layer"); -//Draw ellipse. -graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 50, 40, 40)); + //Create graphics for layer. + PdfGraphics graphics = layer.CreateGraphics(page); -//Create square annotation. -PdfSquareAnnotation annotation = new PdfSquareAnnotation(new RectangleF(200, 260, 50, 50), "Square annotation"); + //Draw ellipse. + graphics.DrawEllipse(PdfPens.Red, new RectangleF(50, 50, 40, 40)); -//Set the annotation color. -annotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); + //Create square annotation. + PdfSquareAnnotation annotation = new PdfSquareAnnotation(new RectangleF(200, 260, 50, 50), "Square annotation"); -//Set layer to annotation. -annotation.Layer = layer; + //Set the annotation color. + annotation.Color = new PdfColor(Syncfusion.Drawing.Color.Red); -//Add annotation to the created page. -page.Annotations.Add(annotation); + //Set layer to annotation. + annotation.Layer = layer; -//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 annotation to the created page. + page.Annotations.Add(annotation); -//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/Layer/Adding-layers-in-a-PDF-document/.NET/Adding-layers-in-a-PDF-document/Program.cs b/Layer/Adding-layers-in-a-PDF-document/.NET/Adding-layers-in-a-PDF-document/Program.cs index 9ab0c9d3..3ff0539a 100644 --- a/Layer/Adding-layers-in-a-PDF-document/.NET/Adding-layers-in-a-PDF-document/Program.cs +++ b/Layer/Adding-layers-in-a-PDF-document/.NET/Adding-layers-in-a-PDF-document/Program.cs @@ -1,52 +1,44 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; -//Create PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the PDF document. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage page = document.Pages.Add(); -//Add the first layer. -PdfPageLayer layer = page.Layers.Add("Layer1"); + //Add the first layer. + PdfPageLayer layer = page.Layers.Add("Layer1"); -//Create graphics for layer. -PdfGraphics graphics = layer.Graphics; + //Create graphics for layer. + PdfGraphics graphics = layer.Graphics; -//Set translate transform. -graphics.TranslateTransform(100, 60); + //Set translate transform. + graphics.TranslateTransform(100, 60); -//Draw arc. -PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Red, 50); + //Draw arc. + PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Red, 50); -RectangleF bounds = new RectangleF(0, 0, 50, 50); + RectangleF bounds = new RectangleF(0, 0, 50, 50); -//Draw arc in layer graphics. -graphics.DrawArc(pen, bounds, 360, 360); + //Draw arc in layer graphics. + graphics.DrawArc(pen, bounds, 360, 360); -//Add another layer on the page. -PdfPageLayer layer2 = page.Layers.Add("Layer2"); + //Add another layer on the page. + PdfPageLayer layer2 = page.Layers.Add("Layer2"); -//Create graphics for another layer. -graphics = layer2.Graphics; + //Create graphics for another layer. + graphics = layer2.Graphics; -//Set translate transform. -graphics.TranslateTransform(100, 180); + //Set translate transform. + graphics.TranslateTransform(100, 180); -//Draw ellipse. -graphics.DrawEllipse(pen, bounds); + //Draw ellipse. + graphics.DrawEllipse(pen, 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. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs b/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs index f1467584..e012b44e 100644 --- a/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs +++ b/Layer/Flattening-the-layers-in-an-existing-PDF-document/.NET/Flattening-the-layers-in-an-existing-PDF-document/Program.cs @@ -1,26 +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 inputStream = new FileStream(Path.GetFullPath(@"Data/Layers.pdf"), FileMode.Open); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the layer collection. -PdfDocumentLayerCollection layers = loadedDocument.Layers; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the layer collection. + PdfDocumentLayerCollection layers = loadedDocument.Layers; -//Flatten a layer in the PDF document. -layers.RemoveAt(0); + //Flatten a layer in the PDF document. + layers.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/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-from-an-existing-PDF-document/Program.cs b/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-from-an-existing-PDF-document/Program.cs index 334cbc51..05909f2c 100644 --- a/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-from-an-existing-PDF-document/Program.cs +++ b/Layer/Removing-layers-from-an-existing-PDF-document/.NET/Removing-layers-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/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; - -//Get the layer collection. -PdfPageLayerCollection layers = loadedPage.Layers; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the first page from the document. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Remove the layer. -layers.RemoveAt(0); + //Get the layer collection. + PdfPageLayerCollection layers = loadedPage.Layers; -//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 the layer. + layers.RemoveAt(0); -//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/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/Program.cs b/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/Program.cs index bf5bd5a3..e5817eed 100644 --- a/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/Program.cs +++ b/Layer/Toggle-the-visibility-of-layers-in-an-existing-PDF/.NET/Toggle-the-visibility-of-layers-in-an-existing-PDF/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 document = new PdfLoadedDocument(docStream); - -//Gets the first layer from the layer collection. -PdfLayer layer = document.Layers[0]; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the first layer from the layer collection. + PdfLayer layer = loadedDocument.Layers[0]; -//Disable the visibility. -layer.Visible = false; + //Disable the visibility. + layer.Visible = 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. - document.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Layer/Toggle-the-visibility-of-layers-in-new-PDF-document/.NET/Toggle-the-visibility-of-layers-in-new-PDF-document/Program.cs b/Layer/Toggle-the-visibility-of-layers-in-new-PDF-document/.NET/Toggle-the-visibility-of-layers-in-new-PDF-document/Program.cs index a1348681..95887570 100644 --- a/Layer/Toggle-the-visibility-of-layers-in-new-PDF-document/.NET/Toggle-the-visibility-of-layers-in-new-PDF-document/Program.cs +++ b/Layer/Toggle-the-visibility-of-layers-in-new-PDF-document/.NET/Toggle-the-visibility-of-layers-in-new-PDF-document/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.Graphics; -//Create the document. -PdfDocument document = new PdfDocument(); - -//Create a page. -PdfPage page = document.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a page. + PdfPage page = document.Pages.Add(); -//Add the first layer and enable the visibility. -PdfPageLayer layer = page.Layers.Add("Layer1", true); + //Add the first layer and enable the visibility. + PdfPageLayer layer = page.Layers.Add("Layer1", true); -//Create graphics for layer. -PdfGraphics graphics = layer.Graphics; + //Create graphics for layer. + PdfGraphics graphics = layer.Graphics; -//Set translate transform for layer graphics. -graphics.TranslateTransform(100, 60); + //Set translate transform for layer graphics. + graphics.TranslateTransform(100, 60); -//Set the pen. -PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Red, 50); + //Set the pen. + PdfPen pen = new PdfPen(Syncfusion.Drawing.Color.Red, 50); -//Set the bounds. -RectangleF bounds = new RectangleF(0, 0, 50, 50); + //Set the bounds. + RectangleF bounds = new RectangleF(0, 0, 50, 50); -//Draw Arc. -graphics.DrawArc(pen, bounds, 360, 360); + //Draw Arc. + graphics.DrawArc(pen, bounds, 360, 360); -//Add another layer on the page and disable the visibility. -PdfPageLayer layer2 = page.Layers.Add("Layer2", false); + //Add another layer on the page and disable the visibility. + PdfPageLayer layer2 = page.Layers.Add("Layer2", false); -//Create graphics for layer2. -graphics = layer2.Graphics; + //Create graphics for layer2. + graphics = layer2.Graphics; -//Set translate transform for layer graphics. -graphics.TranslateTransform(100, 180); + //Set translate transform for layer graphics. + graphics.TranslateTransform(100, 180); -//Draw ellipse. -graphics.DrawEllipse(pen, bounds); + //Draw ellipse. + graphics.DrawEllipse(pen, 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. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Merge PDFs/Add_bookmarks_to_merge_PDF_document_NET/.NET/Add_bookmarks_to_merge_PDF_document_NET/Program.cs b/Merge PDFs/Add_bookmarks_to_merge_PDF_document_NET/.NET/Add_bookmarks_to_merge_PDF_document_NET/Program.cs index 0765a68c..bd864b99 100644 --- a/Merge PDFs/Add_bookmarks_to_merge_PDF_document_NET/.NET/Add_bookmarks_to_merge_PDF_document_NET/Program.cs +++ b/Merge PDFs/Add_bookmarks_to_merge_PDF_document_NET/.NET/Add_bookmarks_to_merge_PDF_document_NET/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; using Syncfusion.Drawing; using System.Reflection.Metadata; @@ -30,12 +28,8 @@ //Sets the destination location for second bookmark. bookmark2.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. - finalDocument.Save(outputFileStream); - } + //Save the PDF document + finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } } diff --git a/Merge PDFs/Combine_and_digitally_sign_the_PDF_files/.NET/Combine_and_digitally_sign_the_PDF_files/Program.cs b/Merge PDFs/Combine_and_digitally_sign_the_PDF_files/.NET/Combine_and_digitally_sign_the_PDF_files/Program.cs index 1d92a013..fcab5131 100644 --- a/Merge PDFs/Combine_and_digitally_sign_the_PDF_files/.NET/Combine_and_digitally_sign_the_PDF_files/Program.cs +++ b/Merge PDFs/Combine_and_digitally_sign_the_PDF_files/.NET/Combine_and_digitally_sign_the_PDF_files/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.Graphics; using Syncfusion.Pdf.Security; @@ -36,12 +34,8 @@ //Draw the image in signature appearance. signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 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 - finalDocument.Save(outputFileStream); -} +//Save the PDF document +finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document finalDocument.Close(true); diff --git a/Merge PDFs/Convert_landscape_to_portrait_and_merge_PDF_files/.NET/Convert_landscape_to_portrait_and_merge_PDF_files/Program.cs b/Merge PDFs/Convert_landscape_to_portrait_and_merge_PDF_files/.NET/Convert_landscape_to_portrait_and_merge_PDF_files/Program.cs index 2ed85a6d..979f431b 100644 --- a/Merge PDFs/Convert_landscape_to_portrait_and_merge_PDF_files/.NET/Convert_landscape_to_portrait_and_merge_PDF_files/Program.cs +++ b/Merge PDFs/Convert_landscape_to_portrait_and_merge_PDF_files/.NET/Convert_landscape_to_portrait_and_merge_PDF_files/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; using System.Reflection.Metadata; using Syncfusion.Pdf.Graphics; @@ -15,8 +13,7 @@ finalDocument.PageSettings.Margins.All = 0; //Load an existing PDF document. -FileStream stream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream1); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); for (int i = 0; i < loadedDocument.Pages.Count; i++) { @@ -33,16 +30,11 @@ } //Load an existing PDF document. -FileStream stream2 = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(stream2); +PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File2.pdf")); finalDocument.ImportPageRange(loadedDocument2, 0, loadedDocument2.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. - finalDocument.Save(outputFileStream); -} +//Save the PDF document. +finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. finalDocument.Close(true); diff --git a/Merge PDFs/Crop_PDF_pages_and_merge_NET/.NET/Crop_PDF_pages_and_merge_NET/Program.cs b/Merge PDFs/Crop_PDF_pages_and_merge_NET/.NET/Crop_PDF_pages_and_merge_NET/Program.cs index 88493c1d..f720a547 100644 --- a/Merge PDFs/Crop_PDF_pages_and_merge_NET/.NET/Crop_PDF_pages_and_merge_NET/Program.cs +++ b/Merge PDFs/Crop_PDF_pages_and_merge_NET/.NET/Crop_PDF_pages_and_merge_NET/Program.cs @@ -1,15 +1,11 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; -//Get the stream from an existing PDF document. -FileStream stream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream1); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); //Load the page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Create the template from the page. @@ -43,12 +39,8 @@ //Merges PDF documents. PdfDocumentBase.Merge(finalDocument, streams); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - finalDocument.Save(outputFileStream); -} +//Save the PDF document +finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the documents. finalDocument.Close(true); \ No newline at end of file diff --git a/Merge PDFs/Extend-the-margin-of-PDF-pages-while-merging-PDFs/.NET/Extend-the-margin-of-PDF-pages-while-merging-PDFs/Program.cs b/Merge PDFs/Extend-the-margin-of-PDF-pages-while-merging-PDFs/.NET/Extend-the-margin-of-PDF-pages-while-merging-PDFs/Program.cs index 2f73f46a..50a4cecb 100644 --- a/Merge PDFs/Extend-the-margin-of-PDF-pages-while-merging-PDFs/.NET/Extend-the-margin-of-PDF-pages-while-merging-PDFs/Program.cs +++ b/Merge PDFs/Extend-the-margin-of-PDF-pages-while-merging-PDFs/.NET/Extend-the-margin-of-PDF-pages-while-merging-PDFs/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.Graphics; //Create a new PDF document @@ -26,11 +24,7 @@ mergeOptions.ExtendMargin = true; //Merge the PDF documents PdfDocumentBase.Merge(outputDocument, mergeOptions, streams); - //Save the document to a memory stream - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - outputDocument.Save(outputFileStream); - } + //Save the document + outputDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - } } diff --git a/Merge PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs b/Merge PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs index 41ba0f5e..6e6616ae 100644 --- a/Merge PDFs/Import-multiple-pages-from-an-existing-PDF/.NET/Import-multiple-pages-from-an-existing-PDF/Program.cs +++ b/Merge 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/Merge PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs b/Merge PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs index 78cd9f5b..bd24f3bb 100644 --- a/Merge PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs +++ b/Merge PDFs/Import-pages-from-multiple-documents-and-arrange-pages/.NET/Import-pages-from-multiple-documents-and-arrange-pages/Program.cs @@ -1,19 +1,11 @@ -// 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); +PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); //Load the PDF document. -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(docStream2); +PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File2.pdf")); //Creates the new document. PdfDocument document = new PdfDocument(); @@ -22,12 +14,10 @@ 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); -} +//Save the PDF document +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. -document.Close(true); \ No newline at end of file +document.Close(true); +loadedDocument2.Close(true); +loadedDocument1.Close(true); \ No newline at end of file diff --git a/Merge PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs b/Merge PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs index d9607dac..6877376c 100644 --- a/Merge PDFs/Importing-pages-from-one-document-another-document/.NET/Importing-pages-from-one-document-another-document/Program.cs +++ b/Merge 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/Merge PDFs/Merge-PDF-without-compromising-accessibility-tags/.NET/Merge-PDF-without-compromising-accessibility-tags/Program.cs b/Merge PDFs/Merge-PDF-without-compromising-accessibility-tags/.NET/Merge-PDF-without-compromising-accessibility-tags/Program.cs index 76e32e85..af67df45 100644 --- a/Merge PDFs/Merge-PDF-without-compromising-accessibility-tags/.NET/Merge-PDF-without-compromising-accessibility-tags/Program.cs +++ b/Merge PDFs/Merge-PDF-without-compromising-accessibility-tags/.NET/Merge-PDF-without-compromising-accessibility-tags/Program.cs @@ -3,29 +3,22 @@ //Create a PDF document. PdfDocument finalDoc = new PdfDocument(); //Get stream from the PDF documents. -FileStream stream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); -FileStream stream2 = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read); - -//Create a PDF stream for merging. -Stream[] streams = { stream1, stream2 }; -PdfMergeOptions mergeOptions = new PdfMergeOptions(); - -//Enable the Merge Accessibility Tags. -mergeOptions.MergeAccessibilityTags = true; +using (FileStream stream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read)) +using (FileStream stream2 = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read)) +{ + //Create a PDF stream for merging. + Stream[] streams = { stream1, stream2 }; + PdfMergeOptions mergeOptions = new PdfMergeOptions(); -//Merge PDFDocument. -PdfDocumentBase.Merge(finalDoc, mergeOptions, streams); + //Enable the Merge Accessibility Tags. + mergeOptions.MergeAccessibilityTags = 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. - finalDoc.Save(outputFileStream); -} + //Merge PDFDocument. + PdfDocumentBase.Merge(finalDoc, mergeOptions, streams); -//Close the documents. -finalDoc.Close(true); + //Save the PDF document + finalDoc.Save(Path.GetFullPath(@"Output/Output.pdf")); -//Dispose the stream. -stream1.Dispose(); -stream2.Dispose(); \ No newline at end of file + //Close the documents. + finalDoc.Close(true); +} \ No newline at end of file diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs index c0384e8d..f54a9b61 100644 --- a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs +++ b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; //Create a PDF document using (PdfDocument finalDocument = new PdfDocument()) @@ -13,10 +11,7 @@ Stream[] streams = { firstStream, secondStream }; //Merge PDF documents PdfDocumentBase.Merge(finalDocument, streams); - //Save the document into a stream - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - finalDocument.Save(outputFileStream); - } + //Save the document + finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } } \ No newline at end of file diff --git a/Merge PDFs/Merge-specific-range-of-pages-from-different-PDF/.NET/Merge-specific-range-of-pages-from-different-PDF/Program.cs b/Merge PDFs/Merge-specific-range-of-pages-from-different-PDF/.NET/Merge-specific-range-of-pages-from-different-PDF/Program.cs index b99d9b0e..beb56940 100644 --- a/Merge PDFs/Merge-specific-range-of-pages-from-different-PDF/.NET/Merge-specific-range-of-pages-from-different-PDF/Program.cs +++ b/Merge PDFs/Merge-specific-range-of-pages-from-different-PDF/.NET/Merge-specific-range-of-pages-from-different-PDF/Program.cs @@ -5,26 +5,19 @@ using (PdfDocument finalDocument = new PdfDocument()) { //Open the first PDF file - using (FileStream firstStream = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read)) + using (PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf"))) { - //Load the first PDF document - PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(firstStream); //Import a range of pages from the first PDF document into the final document //The range starts at page 2 and ends at the last page finalDocument.ImportPageRange(loadedDocument1, 1, loadedDocument1.Pages.Count - 1); //Open the second PDF file - using (FileStream secondStream = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read)) + using (PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File2.pdf"))) { - //Load the second PDF document - PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(secondStream); //Import a range of pages from the second PDF document into the final document. //The range starts at page 2 and ends at page 5 finalDocument.ImportPageRange(loadedDocument2, 2, 5); - //Save the final document into a memory stream - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - finalDocument.Save(outputFileStream); - } + //Save the final document + finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } } } \ No newline at end of file diff --git a/Merge PDFs/Merge_PDF_files_and_fill_form_fields_NET/.NET/Merge_PDF_files_and_fill_form_fields_NET/Program.cs b/Merge PDFs/Merge_PDF_files_and_fill_form_fields_NET/.NET/Merge_PDF_files_and_fill_form_fields_NET/Program.cs index b08398b7..bd12c156 100644 --- a/Merge PDFs/Merge_PDF_files_and_fill_form_fields_NET/.NET/Merge_PDF_files_and_fill_form_fields_NET/Program.cs +++ b/Merge PDFs/Merge_PDF_files_and_fill_form_fields_NET/.NET/Merge_PDF_files_and_fill_form_fields_NET/Program.cs @@ -1,8 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; using System.Reflection.Metadata; using Syncfusion.Pdf.Interactive; @@ -34,12 +30,8 @@ PdfLoadedTextBoxField loadedTextBoxField2 = loadedForm.Fields[4] as PdfLoadedTextBoxField; loadedTextBoxField2.Text = "SSN0001"; -//Create file stream -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream - finalDocument.Save(outputFileStream); -} +//Save the PDF document +finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document finalDocument.Close(true); diff --git a/Merge PDFs/Merge_password_protected_PDF_files_NET/.NET/Merge_password_protected_PDF_files_NET/Program.cs b/Merge PDFs/Merge_password_protected_PDF_files_NET/.NET/Merge_password_protected_PDF_files_NET/Program.cs index cc3ae115..b93e9baa 100644 --- a/Merge PDFs/Merge_password_protected_PDF_files_NET/.NET/Merge_password_protected_PDF_files_NET/Program.cs +++ b/Merge PDFs/Merge_password_protected_PDF_files_NET/.NET/Merge_password_protected_PDF_files_NET/Program.cs @@ -1,31 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; //Creates a PDF document. PdfDocument finalDoc = new PdfDocument(); -//Get stream from an existing PDF document. -FileStream firstPDFStream = new FileStream(Path.GetFullPath(@"Data/Protected_File1.pdf"), FileMode.Open, FileAccess.Read); //Load the PDF document. -PdfLoadedDocument firstDocument = new PdfLoadedDocument(firstPDFStream, "Syncfusion"); +PdfLoadedDocument firstDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Protected_File1.pdf"), "Syncfusion"); //Imports the page at 1 from the loaded document. finalDoc.ImportPageRange(firstDocument, 0, firstDocument.Pages.Count-1); -//Get stream from an existing PDF document. -FileStream secondPDFStream = new FileStream(Path.GetFullPath(@"Data/Protected_File2.pdf"), FileMode.Open, FileAccess.Read); //Load the PDF document. -PdfLoadedDocument secondDocument = new PdfLoadedDocument(secondPDFStream, "Password"); +PdfLoadedDocument secondDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Protected_File2.pdf"), "Password"); //Imports the page at 1 from the loaded document. finalDoc.ImportPageRange(secondDocument, 0, secondDocument.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. - finalDoc.Save(outputFileStream); -} +//Save the PDF document +finalDoc.Save(Path.GetFullPath(@"Output/Output.pdf")); + //Close the documents. firstDocument.Close(); diff --git a/Merge PDFs/Optimize-the-PDF-resources-when-merging-PDF-documents/.NET/Optimize-the-PDF-resources-when-merging-PDF-documents/Program.cs b/Merge PDFs/Optimize-the-PDF-resources-when-merging-PDF-documents/.NET/Optimize-the-PDF-resources-when-merging-PDF-documents/Program.cs index abc2ea0d..239c929c 100644 --- a/Merge PDFs/Optimize-the-PDF-resources-when-merging-PDF-documents/.NET/Optimize-the-PDF-resources-when-merging-PDF-documents/Program.cs +++ b/Merge PDFs/Optimize-the-PDF-resources-when-merging-PDF-documents/.NET/Optimize-the-PDF-resources-when-merging-PDF-documents/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; //Create a new PDF document using (PdfDocument outputDocument = new PdfDocument()) @@ -19,11 +17,8 @@ mergeOptions.OptimizeResources = true; //Merge the PDF documents PdfDocumentBase.Merge(outputDocument, mergeOptions, streams); - //Save the document to a memory stream - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - outputDocument.Save(outputFileStream); - } + //Save the document + outputDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } } } \ No newline at end of file diff --git a/Merge PDFs/Reduce-size-of-PDF-file-while-importing-pages/.NET/Reduce-size-of-PDF-file-while-importing-pages/Program.cs b/Merge PDFs/Reduce-size-of-PDF-file-while-importing-pages/.NET/Reduce-size-of-PDF-file-while-importing-pages/Program.cs index 992bb212..cc5927b1 100644 --- a/Merge PDFs/Reduce-size-of-PDF-file-while-importing-pages/.NET/Reduce-size-of-PDF-file-while-importing-pages/Program.cs +++ b/Merge PDFs/Reduce-size-of-PDF-file-while-importing-pages/.NET/Reduce-size-of-PDF-file-while-importing-pages/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); - //Create a PDF document. -PdfLoadedDocument lDoc = new PdfLoadedDocument(docStream); +PdfLoadedDocument lDoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Create a new document. PdfDocument document = new PdfDocument(); @@ -18,12 +13,9 @@ //Import the page at 1 from the lDoc. document.ImportPageRange(lDoc, 0, 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 document. document.Close(true); +lDoc.Close(true); diff --git a/Merge PDFs/Rotate_pages_and_merge_PDF_files_NET/.NET/Rotate_pages_and_merge_PDF_files_NET/Program.cs b/Merge PDFs/Rotate_pages_and_merge_PDF_files_NET/.NET/Rotate_pages_and_merge_PDF_files_NET/Program.cs index 4dafe506..0647113c 100644 --- a/Merge PDFs/Rotate_pages_and_merge_PDF_files_NET/.NET/Rotate_pages_and_merge_PDF_files_NET/Program.cs +++ b/Merge PDFs/Rotate_pages_and_merge_PDF_files_NET/.NET/Rotate_pages_and_merge_PDF_files_NET/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf; using System.Reflection.Metadata; @@ -8,8 +6,7 @@ PdfDocument finalDocument = new PdfDocument(); //Load the PDF document. -FileStream docStream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); -PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(docStream1); +PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); //Gets the page PdfPageBase loadedPage1 = loadedDocument1.Pages[0] as PdfPageBase; //Set the rotation for loaded page. @@ -27,12 +24,8 @@ //Imports the page at 1 from the loaded document finalDocument.ImportPageRange(loadedDocument2, 0, loadedDocument2.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 - finalDocument.Save(outputFileStream); -} +//Save the PDF document +finalDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document finalDocument.Close(true); diff --git a/Metadata/Adding-XMP-metadata-along-with-an-image-in-PDF/.NET/Adding-XMP-metadata-along-with-an-image-in-PDF/Program.cs b/Metadata/Adding-XMP-metadata-along-with-an-image-in-PDF/.NET/Adding-XMP-metadata-along-with-an-image-in-PDF/Program.cs index 41729ae4..2e9a0f9d 100644 --- a/Metadata/Adding-XMP-metadata-along-with-an-image-in-PDF/.NET/Adding-XMP-metadata-along-with-an-image-in-PDF/Program.cs +++ b/Metadata/Adding-XMP-metadata-along-with-an-image-in-PDF/.NET/Adding-XMP-metadata-along-with-an-image-in-PDF/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf; using System.Reflection.Metadata; //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; -//Load the image as stream which contains XMP metadata. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); -PdfBitmap image = new PdfBitmap(imageStream, true); + //Load the image as stream which contains XMP metadata. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read); + PdfBitmap image = new PdfBitmap(imageStream, true); -//Draw the image. -graphics.DrawImage(image, 0, 0); + //Draw the image. + graphics.DrawImage(image, 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); - diff --git a/Metadata/Adding-XMP-metadata-in-PDF-document/.NET/Adding-XMP-metadata-in-PDF-document/Program.cs b/Metadata/Adding-XMP-metadata-in-PDF-document/.NET/Adding-XMP-metadata-in-PDF-document/Program.cs index 7bb99613..29ae0205 100644 --- a/Metadata/Adding-XMP-metadata-in-PDF-document/.NET/Adding-XMP-metadata-in-PDF-document/Program.cs +++ b/Metadata/Adding-XMP-metadata-in-PDF-document/.NET/Adding-XMP-metadata-in-PDF-document/Program.cs @@ -1,39 +1,31 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Xmp; -//Create a PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create a page. -PdfPage page = pdfDocument.Pages.Add(); - -//Get XMP object. -XmpMetadata metaData = pdfDocument.DocumentInformation.XmpMetadata; - -//XMP Basic Schema. -BasicSchema basic = metaData.BasicSchema; - -//Set the basic details of the document. -basic.Advisory.Add("advisory"); -basic.BaseURL = new Uri("http://google.com"); -basic.CreateDate = DateTime.Now; -basic.CreatorTool = "creator tool"; -basic.Identifier.Add("identifier"); -basic.Label = "label"; -basic.MetadataDate = DateTime.Now; -basic.ModifyDate = DateTime.Now; -basic.Nickname = "nickname"; -basic.Rating.Add(-25); - -//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); + //Create a page. + PdfPage page = document.Pages.Add(); + + //Get XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; + + //XMP Basic Schema. + BasicSchema basic = metaData.BasicSchema; + + //Set the basic details of the document. + basic.Advisory.Add("advisory"); + basic.BaseURL = new Uri("http://google.com"); + basic.CreateDate = DateTime.Now; + basic.CreatorTool = "creator tool"; + basic.Identifier.Add("identifier"); + basic.Label = "label"; + basic.MetadataDate = DateTime.Now; + basic.ModifyDate = DateTime.Now; + basic.Nickname = "nickname"; + basic.Rating.Add(-25); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/Metadata/Adding-XMP-metadata-to-an-existing-PDF-document/.NET/Adding-XMP-metadata-to-an-existing-PDF-document/Program.cs b/Metadata/Adding-XMP-metadata-to-an-existing-PDF-document/.NET/Adding-XMP-metadata-to-an-existing-PDF-document/Program.cs index fc5a318a..aedfa484 100644 --- a/Metadata/Adding-XMP-metadata-to-an-existing-PDF-document/.NET/Adding-XMP-metadata-to-an-existing-PDF-document/Program.cs +++ b/Metadata/Adding-XMP-metadata-to-an-existing-PDF-document/.NET/Adding-XMP-metadata-to-an-existing-PDF-document/Program.cs @@ -1,38 +1,27 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Xmp; -//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 pdfDocument = new PdfLoadedDocument(docStream); - -//Get XMP object. -XmpMetadata metaData = pdfDocument.DocumentInformation.XmpMetadata; - -//XMP Basic Schema. -BasicSchema basic = metaData.BasicSchema; - -//Set the basic details of the document. -basic.Advisory.Add("advisory"); -basic.BaseURL = new Uri("http://google.com"); -basic.CreateDate = DateTime.Now; -basic.CreatorTool = "creator tool"; -basic.Identifier.Add("identifier"); -basic.Label = "label"; -basic.MetadataDate = DateTime.Now; -basic.ModifyDate = DateTime.Now; -basic.Nickname = "nickname"; -basic.Rating.Add(-25); - -//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. - pdfDocument.Save(outputFileStream); -} - -//Close the document. -pdfDocument.Close(true); \ No newline at end of file + //Get XMP object. + XmpMetadata metaData = loadedDocument.DocumentInformation.XmpMetadata; + + //XMP Basic Schema. + BasicSchema basic = metaData.BasicSchema; + + //Set the basic details of the document. + basic.Advisory.Add("advisory"); + basic.BaseURL = new Uri("http://google.com"); + basic.CreateDate = DateTime.Now; + basic.CreatorTool = "creator tool"; + basic.Identifier.Add("identifier"); + basic.Label = "label"; + basic.MetadataDate = DateTime.Now; + basic.ModifyDate = DateTime.Now; + basic.Nickname = "nickname"; + basic.Rating.Add(-25); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Metadata/Adding-custom-metadata-to-the-PDF-document/.NET/Adding-custom-metadata-to-the-PDF-document/Program.cs b/Metadata/Adding-custom-metadata-to-the-PDF-document/.NET/Adding-custom-metadata-to-the-PDF-document/Program.cs index 6167b473..39c4268a 100644 --- a/Metadata/Adding-custom-metadata-to-the-PDF-document/.NET/Adding-custom-metadata-to-the-PDF-document/Program.cs +++ b/Metadata/Adding-custom-metadata-to-the-PDF-document/.NET/Adding-custom-metadata-to-the-PDF-document/Program.cs @@ -1,25 +1,17 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf; -using Syncfusion.Pdf; - -//Create PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add new PDF page. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add new PDF page. + PdfPage page = document.Pages.Add(); -//Add Custom MetaData. -pdfDoc.DocumentInformation.CustomMetadata["ID"] = "IO1"; -pdfDoc.DocumentInformation.CustomMetadata["CompanyName"] = "Syncfusion"; -pdfDoc.DocumentInformation.CustomMetadata["Key"] = "DocumentKey"; + //Add Custom MetaData. + document.DocumentInformation.CustomMetadata["ID"] = "IO1"; + document.DocumentInformation.CustomMetadata["CompanyName"] = "Syncfusion"; + document.DocumentInformation.CustomMetadata["Key"] = "DocumentKey"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDoc.Close(true); - diff --git a/Metadata/Adding-custom-schema-to-the-PDF-document/.NET/Adding-custom-schema-to-the-PDF-document/Program.cs b/Metadata/Adding-custom-schema-to-the-PDF-document/.NET/Adding-custom-schema-to-the-PDF-document/Program.cs index e9cfd55b..7ef63eb2 100644 --- a/Metadata/Adding-custom-schema-to-the-PDF-document/.NET/Adding-custom-schema-to-the-PDF-document/Program.cs +++ b/Metadata/Adding-custom-schema-to-the-PDF-document/.NET/Adding-custom-schema-to-the-PDF-document/Program.cs @@ -1,31 +1,23 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add a page to the document. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create XML Document container. -XmpMetadata metaData = new XmpMetadata(pdfDoc.DocumentInformation.XmpMetadata.XmlData); + //Create XML Document container. + XmpMetadata metaData = new XmpMetadata(document.DocumentInformation.XmpMetadata.XmlData); -//Create custom schema. -CustomSchema customSchema = new CustomSchema(metaData, "custom", "http://www.syncfusion.com"); -customSchema["Author"] = "Syncfusion"; -customSchema["creationDate"] = DateTime.Now.ToString(); -customSchema["DOCID"] = "SYNCSAM001"; + //Create custom schema. + CustomSchema customSchema = new CustomSchema(metaData, "custom", "http://www.syncfusion.com"); + customSchema["Author"] = "Syncfusion"; + customSchema["creationDate"] = DateTime.Now.ToString(); + customSchema["DOCID"] = "SYNCSAM001"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDoc.Close(true); - diff --git a/Metadata/Create-PDF-document-with-PDF-schema/.NET/Create-PDF-document-with-PDF-schema/Program.cs b/Metadata/Create-PDF-document-with-PDF-schema/.NET/Create-PDF-document-with-PDF-schema/Program.cs index f30e799c..a7af0da3 100644 --- a/Metadata/Create-PDF-document-with-PDF-schema/.NET/Create-PDF-document-with-PDF-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-PDF-schema/.NET/Create-PDF-document-with-PDF-schema/Program.cs @@ -1,31 +1,23 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create a PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add a page. -PdfPage page = pdfDoc.Pages.Add(); - -//Gets XMP object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//XMP PDF Schema. -PDFSchema pdfSchema = metaData.PDFSchema; + //Gets XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//Set the PDF Schema details of the document. -pdfSchema.Producer = "Syncfusion"; -pdfSchema.PDFVersion = "1.5"; -pdfSchema.Keywords = "Essential PDF"; + //XMP PDF Schema. + PDFSchema pdfSchema = metaData.PDFSchema; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); -} + //Set the PDF Schema details of the document. + pdfSchema.Producer = "Syncfusion"; + pdfSchema.PDFVersion = "1.5"; + pdfSchema.Keywords = "Essential PDF"; -//Close the document. -pdfDoc.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/Metadata/Create-PDF-document-with-XMP-basic-schema/.NET/Create-PDF-document-with-XMP-basic-schema/Program.cs b/Metadata/Create-PDF-document-with-XMP-basic-schema/.NET/Create-PDF-document-with-XMP-basic-schema/Program.cs index 68b65881..a84bfdf4 100644 --- a/Metadata/Create-PDF-document-with-XMP-basic-schema/.NET/Create-PDF-document-with-XMP-basic-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-XMP-basic-schema/.NET/Create-PDF-document-with-XMP-basic-schema/Program.cs @@ -1,38 +1,30 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create a PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Create a page. -PdfPage page = pdfDoc.Pages.Add(); - -//Get metaData object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; - -//XMP Basic Schema. -BasicSchema basic = metaData.BasicSchema; - -//Set the basic details of the document. -basic.Advisory.Add("advisory"); -basic.BaseURL = new Uri("http://google.com"); -basic.CreateDate = DateTime.Now; -basic.CreatorTool = "creator tool"; -basic.Identifier.Add("identifier"); -basic.Label = "label"; -basic.MetadataDate = DateTime.Now; -basic.ModifyDate = DateTime.Now; -basic.Nickname = "nickname"; -basic.Rating.Add(-25); - -//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. - pdfDoc.Save(outputFileStream); + //Create a page. + PdfPage page = document.Pages.Add(); + + //Get metaData object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; + + //XMP Basic Schema. + BasicSchema basic = metaData.BasicSchema; + + //Set the basic details of the document. + basic.Advisory.Add("advisory"); + basic.BaseURL = new Uri("http://google.com"); + basic.CreateDate = DateTime.Now; + basic.CreatorTool = "creator tool"; + basic.Identifier.Add("identifier"); + basic.Label = "label"; + basic.MetadataDate = DateTime.Now; + basic.ModifyDate = DateTime.Now; + basic.Nickname = "nickname"; + basic.Rating.Add(-25); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Create-PDF-document-with-basic-job-ticket-schema/.NET/Create-PDF-document-with-basic-job-ticket-schema/Program.cs b/Metadata/Create-PDF-document-with-basic-job-ticket-schema/.NET/Create-PDF-document-with-basic-job-ticket-schema/Program.cs index 860c5811..e4e5fc0f 100644 --- a/Metadata/Create-PDF-document-with-basic-job-ticket-schema/.NET/Create-PDF-document-with-basic-job-ticket-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-basic-job-ticket-schema/.NET/Create-PDF-document-with-basic-job-ticket-schema/Program.cs @@ -1,30 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Xmp; -//Create a document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add a page. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Gets XMP object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; + //Gets XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//XMP Rights Management Schema. -BasicJobTicketSchema basicJob = metaData.BasicJobTicketSchema; + //XMP Rights Management Schema. + BasicJobTicketSchema basicJob = metaData.BasicJobTicketSchema; -//Set the Rights Management Schema details of the document. -basicJob.JobRef.Add("PDF document creation"); + //Set the Rights Management Schema details of the document. + basicJob.JobRef.Add("PDF document creation"); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Create-PDF-document-with-custom-schema/.NET/Create-PDF-document-with-custom-schema/Program.cs b/Metadata/Create-PDF-document-with-custom-schema/.NET/Create-PDF-document-with-custom-schema/Program.cs index 5485a2d2..d10786ae 100644 --- a/Metadata/Create-PDF-document-with-custom-schema/.NET/Create-PDF-document-with-custom-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-custom-schema/.NET/Create-PDF-document-with-custom-schema/Program.cs @@ -1,30 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create Pdf document. -PdfDocument pdfDoc = new PdfDocument(); - -//Create a page in document. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a page in document. + PdfPage page = document.Pages.Add(); -//Get metaData object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; + //Get metaData object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//Create custom schema field. -CustomSchema customSchema = new CustomSchema(metaData, "custom", "http://www.syncfusion.com"); -customSchema["creationDate"] = DateTime.Now.ToString(); -customSchema["DOCID"] = "SYNCSAM001"; -customSchema["Encryption"] = "Standard"; -customSchema["Project"] = "Data processing"; + //Create custom schema field. + CustomSchema customSchema = new CustomSchema(metaData, "custom", "http://www.syncfusion.com"); + customSchema["creationDate"] = DateTime.Now.ToString(); + customSchema["DOCID"] = "SYNCSAM001"; + customSchema["Encryption"] = "Standard"; + customSchema["Project"] = "Data processing"; -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Create-PDF-document-with-dubline-core-schema-properties/.NET/Create-PDF-document-with-dubline-core-schema-properties/Program.cs b/Metadata/Create-PDF-document-with-dubline-core-schema-properties/.NET/Create-PDF-document-with-dubline-core-schema-properties/Program.cs index 1f312e87..099ddf99 100644 --- a/Metadata/Create-PDF-document-with-dubline-core-schema-properties/.NET/Create-PDF-document-with-dubline-core-schema-properties/Program.cs +++ b/Metadata/Create-PDF-document-with-dubline-core-schema-properties/.NET/Create-PDF-document-with-dubline-core-schema-properties/Program.cs @@ -1,34 +1,26 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Xmp; -//Create new PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add a page to the document. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Gets XMP object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; + //Gets XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//XMP Dublin core Schema. -DublinCoreSchema dublin = metaData.DublinCoreSchema; + //XMP Dublin core Schema. + DublinCoreSchema dublin = metaData.DublinCoreSchema; -//Set the Dublin Core Schema details of the document. -dublin.Creator.Add("Syncfusion"); -dublin.Description.Add("Title", "Essential PDF creator"); -dublin.Title.Add("Resource name", "Documentation"); -dublin.Type.Add("PDF"); -dublin.Publisher.Add("Essential PDF"); + //Set the Dublin Core Schema details of the document. + dublin.Creator.Add("Syncfusion"); + dublin.Description.Add("Title", "Essential PDF creator"); + dublin.Title.Add("Resource name", "Documentation"); + dublin.Type.Add("PDF"); + dublin.Publisher.Add("Essential PDF"); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - //Save the PDF document to file stream. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Create-PDF-document-with-pages-text-schema/.NET/Create-PDF-document-with-pages-text-schema/Program.cs b/Metadata/Create-PDF-document-with-pages-text-schema/.NET/Create-PDF-document-with-pages-text-schema/Program.cs index 6df3b49c..44fb8209 100644 --- a/Metadata/Create-PDF-document-with-pages-text-schema/.NET/Create-PDF-document-with-pages-text-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-pages-text-schema/.NET/Create-PDF-document-with-pages-text-schema/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create a Pdf document. -PdfDocument pdfDoc = new PdfDocument(); - -//Create a Page. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a Page. + PdfPage page = document.Pages.Add(); -//Gets XMP object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; + //Gets XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//XMP Page text Schema. -PagedTextSchema pagedText = metaData.PagedTextSchema; + //XMP Page text Schema. + PagedTextSchema pagedText = metaData.PagedTextSchema; -//Sets the Page text Schema details of the document. -pagedText.MaxPageSize.Width = 500; -pagedText.MaxPageSize.Height = 750; -pagedText.NPages = 1; -pagedText.PlateNames.Add("Sample page"); + //Sets the Page text Schema details of the document. + pagedText.MaxPageSize.Width = 500; + pagedText.MaxPageSize.Height = 750; + pagedText.NPages = 1; + pagedText.PlateNames.Add("Sample 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. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Create-PDF-document-with-right-management-schema/.NET/Create-PDF-document-with-right-management-schema/Program.cs b/Metadata/Create-PDF-document-with-right-management-schema/.NET/Create-PDF-document-with-right-management-schema/Program.cs index e503f909..52062a67 100644 --- a/Metadata/Create-PDF-document-with-right-management-schema/.NET/Create-PDF-document-with-right-management-schema/Program.cs +++ b/Metadata/Create-PDF-document-with-right-management-schema/.NET/Create-PDF-document-with-right-management-schema/Program.cs @@ -1,31 +1,23 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Xmp; -//Create PDF document. -PdfDocument pdfDoc = new PdfDocument(); - -//Add a page to the document. -PdfPage page = pdfDoc.Pages.Add(); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Gets XMP object. -XmpMetadata metaData = pdfDoc.DocumentInformation.XmpMetadata; + //Gets XMP object. + XmpMetadata metaData = document.DocumentInformation.XmpMetadata; -//XMP Rights Management Schema. -RightsManagementSchema rights = metaData.RightsManagementSchema; + //XMP Rights Management Schema. + RightsManagementSchema rights = metaData.RightsManagementSchema; -//Set the Rights Management Schema details of the document. -rights.Certificate = new Uri("http://syncfusion.com"); -rights.Owner.Add("Syncfusion"); -rights.Marked = true; + //Set the Rights Management Schema details of the document. + rights.Certificate = new Uri("http://syncfusion.com"); + rights.Owner.Add("Syncfusion"); + rights.Marked = 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. - pdfDoc.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDoc.Close(true); diff --git a/Metadata/Extracting-XMP-metadata-from-PDF-image/.NET/Extracting-XMP-metadata-from-PDF-image/Program.cs b/Metadata/Extracting-XMP-metadata-from-PDF-image/.NET/Extracting-XMP-metadata-from-PDF-image/Program.cs index 1e5d0fba..66a07641 100644 --- a/Metadata/Extracting-XMP-metadata-from-PDF-image/.NET/Extracting-XMP-metadata-from-PDF-image/Program.cs +++ b/Metadata/Extracting-XMP-metadata-from-PDF-image/.NET/Extracting-XMP-metadata-from-PDF-image/Program.cs @@ -1,26 +1,19 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Xmp; using Syncfusion.Pdf; using Syncfusion.Pdf.Exporting; -//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 pageBase = loadedDocument.Pages[0]; - -//Extracts all the images info from first page. -PdfImageInfo[] imagesInfo = pageBase.GetImagesInfo(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the first page. + PdfPageBase pageBase = loadedDocument.Pages[0]; -//Extracts the XMP metadata from PDF image. -XmpMetadata metadata = imagesInfo[0].Metadata; + //Extracts all the images info from first page. + PdfImageInfo[] imagesInfo = pageBase.GetImagesInfo(); -Console.WriteLine(metadata.XmlData); + //Extracts the XMP metadata from PDF image. + XmpMetadata metadata = imagesInfo[0].Metadata; -//Close the document. -loadedDocument.Close(true); \ No newline at end of file + Console.WriteLine(metadata.XmlData); +} \ No newline at end of file diff --git a/Metadata/Remove-custom-metadata-from-an-existing-PDF-document/.NET/Remove-custom-metadata-from-an-existing-PDF-document/Program.cs b/Metadata/Remove-custom-metadata-from-an-existing-PDF-document/.NET/Remove-custom-metadata-from-an-existing-PDF-document/Program.cs index dbd86e6f..e5b40b73 100644 --- a/Metadata/Remove-custom-metadata-from-an-existing-PDF-document/.NET/Remove-custom-metadata-from-an-existing-PDF-document/Program.cs +++ b/Metadata/Remove-custom-metadata-from-an-existing-PDF-document/.NET/Remove-custom-metadata-from-an-existing-PDF-document/Program.cs @@ -1,23 +1,12 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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); - -//Remove custom metadata using key name. -loadedDocument.DocumentInformation.CustomMetadata.Remove("Key"); - -//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. - loadedDocument.Save(outputFileStream); -} + //Remove custom metadata using key name. + loadedDocument.DocumentInformation.CustomMetadata.Remove("Key"); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Named Destination/Adding-named-destination-to-a-PDF-document/.NET/Adding-named-destination-to-a-PDF-document/Program.cs b/Named Destination/Adding-named-destination-to-a-PDF-document/.NET/Adding-named-destination-to-a-PDF-document/Program.cs index 98f5a550..f53c2e24 100644 --- a/Named Destination/Adding-named-destination-to-a-PDF-document/.NET/Adding-named-destination-to-a-PDF-document/Program.cs +++ b/Named Destination/Adding-named-destination-to-a-PDF-document/.NET/Adding-named-destination-to-a-PDF-document/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.Graphics; using Syncfusion.Pdf.Interactive; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); - -//Create an instance for named destination. -PdfNamedDestination destination = new PdfNamedDestination("TOC"); -destination.Destination = new PdfDestination(page); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the location. -destination.Destination.Location = new PointF(0, 500); + //Create an instance for named destination. + PdfNamedDestination destination = new PdfNamedDestination("TOC"); + destination.Destination = new PdfDestination(page); -//Set zoom factor to 400 percentage. -destination.Destination.Zoom = 4; + //Set the location. + destination.Destination.Location = new PointF(0, 500); -//Add the named destination to document. -document.NamedDestinationCollection.Add(destination); + //Set zoom factor to 400 percentage. + destination.Destination.Zoom = 4; -//Draw the text. -page.Graphics.DrawString("Hello World!!", new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, new PointF(0, 500)); + //Add the named destination to document. + document.NamedDestinationCollection.Add(destination); -//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 text. + page.Graphics.DrawString("Hello World!!", new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, new PointF(0, 500)); -//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/Named Destination/Adding-named-destination-to-an-existing-PDF-document/.NET/Adding-named-destination-to-an-existing-PDF-document/Program.cs b/Named Destination/Adding-named-destination-to-an-existing-PDF-document/.NET/Adding-named-destination-to-an-existing-PDF-document/Program.cs index 7700b2b0..ff9031b3 100644 --- a/Named Destination/Adding-named-destination-to-an-existing-PDF-document/.NET/Adding-named-destination-to-an-existing-PDF-document/Program.cs +++ b/Named Destination/Adding-named-destination-to-an-existing-PDF-document/.NET/Adding-named-destination-to-an-existing-PDF-document/Program.cs @@ -1,55 +1,44 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; 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 first page of the document -PdfPageBase page = loadedDocument.Pages[0]; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the document + PdfPageBase page = loadedDocument.Pages[0]; -//Create an instance for named destination. -PdfNamedDestination destination = new PdfNamedDestination("TOC"); + //Create an instance for named destination. + PdfNamedDestination destination = new PdfNamedDestination("TOC"); -//Add the destination page. -destination.Destination = new PdfDestination(page); + //Add the destination page. + destination.Destination = new PdfDestination(page); -//Set the location. -destination.Destination.Location = new PointF(0, 500); + //Set the location. + destination.Destination.Location = new PointF(0, 500); -//Set zoom factor to 400 percentage. -destination.Destination.Zoom = 4; + //Set zoom factor to 400 percentage. + destination.Destination.Zoom = 4; -//Add the namded destination to the PDF document. -loadedDocument.NamedDestinationCollection.Add(destination); + //Add the namded destination to the PDF document. + loadedDocument.NamedDestinationCollection.Add(destination); -//Create an instance for named destination. -PdfNamedDestination destination1 = new PdfNamedDestination("POC"); + //Create an instance for named destination. + PdfNamedDestination destination1 = new PdfNamedDestination("POC"); -//Add the destination page. -destination1.Destination = new PdfDestination(page); + //Add the destination page. + destination1.Destination = new PdfDestination(page); -//Set the location. -destination1.Destination.Location = new PointF(0, 100); + //Set the location. + destination1.Destination.Location = new PointF(0, 100); -//Set zoom factor to 400 percentage. -destination1.Destination.Zoom = 4; + //Set zoom factor to 400 percentage. + destination1.Destination.Zoom = 4; -//Add the namded destination to the PDF document. -loadedDocument.NamedDestinationCollection.Add(destination1); + //Add the namded destination to the PDF document. + loadedDocument.NamedDestinationCollection.Add(destination1); -//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/Named Destination/Adding-named-destination-to-the-bookmarks/.NET/Adding-named-destination-to-the-bookmarks/Program.cs b/Named Destination/Adding-named-destination-to-the-bookmarks/.NET/Adding-named-destination-to-the-bookmarks/Program.cs index 89b6cb08..ee365840 100644 --- a/Named Destination/Adding-named-destination-to-the-bookmarks/.NET/Adding-named-destination-to-the-bookmarks/Program.cs +++ b/Named Destination/Adding-named-destination-to-the-bookmarks/.NET/Adding-named-destination-to-the-bookmarks/Program.cs @@ -1,49 +1,41 @@ -// 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(); - -//Add a page to the document. -PdfPage page = document.Pages.Add(); - -//Create an instance for named destination. -PdfNamedDestination destination = new PdfNamedDestination("TOC"); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the page destination. -destination.Destination = new PdfDestination(page); + //Create an instance for named destination. + PdfNamedDestination destination = new PdfNamedDestination("TOC"); -//Set the location -destination.Destination.Location = new PointF(0, 500); + //Set the page destination. + destination.Destination = new PdfDestination(page); -//Set zoom factor to 400 percentage -destination.Destination.Zoom = 4; + //Set the location + destination.Destination.Location = new PointF(0, 500); -//Add the named destination to the collection -document.NamedDestinationCollection.Add(destination); + //Set zoom factor to 400 percentage + destination.Destination.Zoom = 4; -//Create a bookmark -PdfBookmark bookmark = document.Bookmarks.Add("TOC"); + //Add the named destination to the collection + document.NamedDestinationCollection.Add(destination); -//Assign the named destination to the bookmark -bookmark.NamedDestination = destination; + //Create a bookmark + PdfBookmark bookmark = document.Bookmarks.Add("TOC"); -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Assign the named destination to the bookmark + bookmark.NamedDestination = destination; -//Draw string. -page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(0,500)); + //Set the font. + PdfStandardFont 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. + page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Red, new PointF(0, 500)); -//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/Named Destination/Remove-and-modify-the-named-destination-in-a-PDF/.NET/Remove-and-modify-the-named-destination-in-a-PDF/Program.cs b/Named Destination/Remove-and-modify-the-named-destination-in-a-PDF/.NET/Remove-and-modify-the-named-destination-in-a-PDF/Program.cs index 44bc3fc5..3696fb5c 100644 --- a/Named Destination/Remove-and-modify-the-named-destination-in-a-PDF/.NET/Remove-and-modify-the-named-destination-in-a-PDF/Program.cs +++ b/Named Destination/Remove-and-modify-the-named-destination-in-a-PDF/.NET/Remove-and-modify-the-named-destination-in-a-PDF/Program.cs @@ -1,30 +1,19 @@ -// 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 the named destination collection. -PdfNamedDestinationCollection destinationCollection = loadedDocument.NamedDestinationCollection; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the named destination collection. + PdfNamedDestinationCollection destinationCollection = loadedDocument.NamedDestinationCollection; -//Remove the named destination by title. -destinationCollection.Remove("POC"); + //Remove the named destination by title. + destinationCollection.Remove("POC"); -//Modify the exiting named destination -PdfNamedDestination destination = destinationCollection[0]; -destination.Title = "Modified Named Destination"; + //Modify the exiting named destination + PdfNamedDestination destination = destinationCollection[0]; + destination.Title = "Modified Named Destination"; -//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/OCR/.NET/Adding-Line-Breaks-Using-OCR/.NET/Adding-Line-Breaks-Using-OCR/Program.cs b/OCR/.NET/Adding-Line-Breaks-Using-OCR/.NET/Adding-Line-Breaks-Using-OCR/Program.cs index 62391f1a..016c507f 100644 --- a/OCR/.NET/Adding-Line-Breaks-Using-OCR/.NET/Adding-Line-Breaks-Using-OCR/Program.cs +++ b/OCR/.NET/Adding-Line-Breaks-Using-OCR/.NET/Adding-Line-Breaks-Using-OCR/Program.cs @@ -5,10 +5,8 @@ using (OCRProcessor processor = new OCRProcessor()) { // Load the existing PDF document - using (FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open)) + using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(stream); - // Set OCR language to process processor.Settings.Language = Languages.English; @@ -18,13 +16,8 @@ processor.PerformOCR(pdfLoadedDocument, processor.TessDataPath, out OCRLayoutResult layoutResult); string ocrText = string.Join("\n", layoutResult.Pages[0].Lines.Select(line => line.Text)); - - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - pdfLoadedDocument.Save(outputFileStream); - } + //Save the PDF document + pdfLoadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. pdfLoadedDocument.Close(true); File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), ocrText); diff --git a/OCR/.NET/Get-image-rotation-angle-from-OCR/Get-image-rotation-angle-from-OCR/Program.cs b/OCR/.NET/Get-image-rotation-angle-from-OCR/Get-image-rotation-angle-from-OCR/Program.cs index c0d7c17a..1021e787 100644 --- a/OCR/.NET/Get-image-rotation-angle-from-OCR/Get-image-rotation-angle-from-OCR/Program.cs +++ b/OCR/.NET/Get-image-rotation-angle-from-OCR/Get-image-rotation-angle-from-OCR/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; @@ -9,10 +7,8 @@ //Initialize the OCR processor. using (OCRProcessor processor = new OCRProcessor()) { - //Get the stream from an image file. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Set the OCR language to process. - PdfLoadedDocument document = new PdfLoadedDocument(stream); + //Load the existing PDF document + PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Set the OCR language. processor.Settings.Language = Languages.English; //Set the Unicode font to preserve the Unicode characters in a PDF document. @@ -31,11 +27,6 @@ { document.Pages[0].Rotation = PdfPageRotateAngle.RotateAngle270; } } } - - //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")); } diff --git a/OCR/.NET/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Program.cs b/OCR/.NET/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Program.cs index 6981fe19..56248ba6 100644 --- a/OCR/.NET/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Program.cs +++ b/OCR/.NET/Get-the-OCR'ed-text-and-its-bounds-from-an-input-PDF/Get-the-OCR'ed-text-and-its-bounds-from-an-input-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.OCRProcessor; using Syncfusion.Pdf.Parsing; @@ -10,11 +8,8 @@ //Initialize the OCR processor by providing the path of tesseract. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from an existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Set OCR language to process. processor.Settings.Language = Languages.English; diff --git a/OCR/.NET/OCR-with-multiple-langauages/OCR with multiple languages/Program.cs b/OCR/.NET/OCR-with-multiple-langauages/OCR with multiple languages/Program.cs index 13c9aa7b..8884bfa3 100644 --- a/OCR/.NET/OCR-with-multiple-langauages/OCR with multiple languages/Program.cs +++ b/OCR/.NET/OCR-with-multiple-langauages/OCR with multiple languages/Program.cs @@ -1,28 +1,21 @@ - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; - // Initialize the OCR processor within a using block to ensure resources are properly disposed using (OCRProcessor ocrProcessor = new OCRProcessor()) { // Set the Unicode font for the OCR processor using a TrueType font file ocrProcessor.UnicodeFont = new Syncfusion.Pdf.Graphics.PdfTrueTypeFont( - new FileStream(Path.GetFullPath(@"Data/arialuni.ttf"), FileMode.Open), // Path to the TrueType font file - 12 // Font size - ); - - // Open the PDF file to be processed - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); + new FileStream(Path.GetFullPath(@"Data/arialuni.ttf"), FileMode.Open),12 ); - // Load the PDF document from the file stream - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); + // Load the PDF document + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); // Configure OCR settings OCRSettings ocrSettings = new OCRSettings(); // Specify the languages to be used for OCR - ocrSettings.Language = "eng+deu+ara+ell+fra"; // English, German, Arabic, Greek, French + ocrSettings.Language = "eng+deu+ara+ell+fra"; // Apply the OCR settings to the OCR processor ocrProcessor.Settings = ocrSettings; @@ -30,18 +23,11 @@ // Perform OCR on the loaded PDF document, providing the path to the tessdata directory ocrProcessor.PerformOCR(loadedDocument, "tessdata"); - // Create a file stream to save the OCR-processed PDF - FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create); - - // Save the OCR-processed document to the file stream - loadedDocument.Save(outputFileStream); + // Save the OCR-processed document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); // Close the loaded document and commit changes loadedDocument.Close(true); - - // Close the file streams - outputFileStream.Close(); - fileStream.Close(); } diff --git a/OCR/.NET/OCR_Image_to_PDF/OCR_Image_to_PDF/Program.cs b/OCR/.NET/OCR_Image_to_PDF/OCR_Image_to_PDF/Program.cs index 7780d7d3..c3c3e442 100644 --- a/OCR/.NET/OCR_Image_to_PDF/OCR_Image_to_PDF/Program.cs +++ b/OCR/.NET/OCR_Image_to_PDF/OCR_Image_to_PDF/Program.cs @@ -1,5 +1,4 @@ - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf; @@ -24,12 +23,8 @@ //Process OCR by providing the bitmap image. PdfDocument document = processor.PerformOCR(imageStream); - //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/OCR/.NET/Perform-OCR-AWS-Textract/Perform-OCR-AWS-Textract/Program.cs b/OCR/.NET/Perform-OCR-AWS-Textract/Perform-OCR-AWS-Textract/Program.cs index be83f400..9c7781ba 100644 --- a/OCR/.NET/Perform-OCR-AWS-Textract/Perform-OCR-AWS-Textract/Program.cs +++ b/OCR/.NET/Perform-OCR-AWS-Textract/Perform-OCR-AWS-Textract/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; namespace OCR.Test @@ -26,16 +24,12 @@ static void Main(string[] args) //Perform OCR with input document. string text = processor.PerformOCR(lDoc); - //Create file stream. - FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - - //Save the document into stream. - lDoc.Save(fileStream); + //Save the document + lDoc.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. lDoc.Close(); stream.Dispose(); - fileStream.Dispose(); } } } diff --git a/OCR/.NET/Perform-OCR-Azure-Vision/Perform-OCR-Azure-Vision/Program.cs b/OCR/.NET/Perform-OCR-Azure-Vision/Perform-OCR-Azure-Vision/Program.cs index bbb520da..dbd2361d 100644 --- a/OCR/.NET/Perform-OCR-Azure-Vision/Perform-OCR-Azure-Vision/Program.cs +++ b/OCR/.NET/Perform-OCR-Azure-Vision/Perform-OCR-Azure-Vision/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; namespace OCR.Test @@ -13,8 +11,7 @@ static void Main(string[] args) using (OCRProcessor processor = new OCRProcessor()) { //Load an existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Region.pdf"), FileMode.Open); - PdfLoadedDocument lDoc = new PdfLoadedDocument(stream); + PdfLoadedDocument lDoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Region.pdf")); //Set OCR language. processor.Settings.Language = Languages.English; @@ -26,18 +23,11 @@ static void Main(string[] args) //Perform OCR. processor.PerformOCR(lDoc); - //Create file stream. - FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite); - - //Save the document into stream. - lDoc.Save(outputStream); - - //If the position is not set to '0' then the PDF will be empty. - outputStream.Position = 0; + //Save the document + lDoc.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. lDoc.Close(true); - outputStream.Close(); } } } diff --git a/OCR/.NET/Perform-OCR-ImageEnhancement/OCR_ImageEnhancement/Program.cs b/OCR/.NET/Perform-OCR-ImageEnhancement/OCR_ImageEnhancement/Program.cs index e1c510d2..74ae03c7 100644 --- a/OCR/.NET/Perform-OCR-ImageEnhancement/OCR_ImageEnhancement/Program.cs +++ b/OCR/.NET/Perform-OCR-ImageEnhancement/OCR_ImageEnhancement/Program.cs @@ -1,5 +1,4 @@ - -using OCR_ImageEnhancement; +using OCR_ImageEnhancement; using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; @@ -8,8 +7,7 @@ using (OCRProcessor processor = new OCRProcessor()) { //Load an existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - PdfLoadedDocument document = new PdfLoadedDocument(stream); + PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Set OCR language. processor.Settings.Language = Languages.English; // Set the page segmentation mode for the OCR processor. @@ -19,12 +17,9 @@ processor.ImageProcessor = new ImageProcessor(); //Perform OCR with input document and tessdata (Language packs). string text = processor.PerformOCR(document, 0, 0, processor.TessDataPath); - //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); File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), text); diff --git a/OCR/.NET/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Program.cs index 354d8f3d..23684aed 100644 --- a/OCR/.NET/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Program.cs +++ b/OCR/.NET/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Perform-OCR-an-image-and-convert-it-to-a-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using System.Drawing; @@ -26,12 +24,8 @@ //Process OCR by providing the bitmap image. PdfDocument document = processor.PerformOCR(imageStream); - //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/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs index d10dfe9d..a0178c19 100644 --- a/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs +++ b/OCR/.NET/Perform-OCR-for-the-entire-PDF-document/Perform-OCR-for-the-entire-PDF-document/Program.cs @@ -1,29 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; // Initialize the OCR processor using (OCRProcessor processor = new OCRProcessor()) { // Load the existing PDF document - using (FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open)) - { - PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(stream); - - // Set OCR language to process - processor.Settings.Language = Languages.English; - - // Process OCR by providing the PDF document - processor.PerformOCR(pdfLoadedDocument); - - //Create file stream. - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) + using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - //Save the PDF document to file stream. - pdfLoadedDocument.Save(outputFileStream); + // Set OCR language to process + processor.Settings.Language = Languages.English; + + // Process OCR by providing the PDF document + processor.PerformOCR(pdfLoadedDocument); + + //Save the PDF document + pdfLoadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); + //Close the document. + pdfLoadedDocument.Close(true); } - //Close the document. - pdfLoadedDocument.Close(true); - } } \ No newline at end of file diff --git a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs index 46858aaa..6f51bbd3 100644 --- a/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs +++ b/OCR/.NET/Perform-OCR-on-image-file/Perform-OCR-on-image-file/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Graphics; using System.Drawing; diff --git a/OCR/.NET/Perform-OCR-on-particular-region-of-PDF-document/Perform-OCR-on-particular-region-of-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-on-particular-region-of-PDF-document/Perform-OCR-on-particular-region-of-PDF-document/Program.cs index b4333019..c1b47253 100644 --- a/OCR/.NET/Perform-OCR-on-particular-region-of-PDF-document/Perform-OCR-on-particular-region-of-PDF-document/Program.cs +++ b/OCR/.NET/Perform-OCR-on-particular-region-of-PDF-document/Perform-OCR-on-particular-region-of-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.OCRProcessor; using Syncfusion.Pdf.Parsing; @@ -9,11 +7,8 @@ //Initialize the OCR processor by providing the path of the tesseract. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from the existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. - PdfLoadedDocument document = new PdfLoadedDocument(stream); + PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Set OCR language to process. processor.Settings.Language = Languages.English; @@ -42,12 +37,8 @@ //Perform OCR with input document and tessdata (Language packs). processor.PerformOCR(document, tessdataPath); - //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/OCR/.NET/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Program.cs index f72fc9a1..96880edd 100644 --- a/OCR/.NET/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Program.cs +++ b/OCR/.NET/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Perform-OCR-on-the-rotated-page-of-the-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; using System.Diagnostics; using System.IO; @@ -10,12 +8,8 @@ //Initialize the OCR processor by providing the path of tesseract. using (OCRProcessor processor = new OCRProcessor(Path.GetFullPath())) //Get stream from an existing PDF document. -using (FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - - //Load the PDF document. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); - //Set OCR language to process. processor.Settings.Language = Languages.English; @@ -25,12 +19,8 @@ //Process OCR by providing the PDF document, data dictionary, and language. processor.PerformOCR(loadedDocument, tessdataPath); - //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/OCR/.NET/Perform-OCR-with-unicode-characters-in-a-PDF-document/Perform-OCR-with-unicode-characters-in-a-PDF-document/Program.cs b/OCR/.NET/Perform-OCR-with-unicode-characters-in-a-PDF-document/Perform-OCR-with-unicode-characters-in-a-PDF-document/Program.cs index 7f93fd5f..c49d43a6 100644 --- a/OCR/.NET/Perform-OCR-with-unicode-characters-in-a-PDF-document/Perform-OCR-with-unicode-characters-in-a-PDF-document/Program.cs +++ b/OCR/.NET/Perform-OCR-with-unicode-characters-in-a-PDF-document/Perform-OCR-with-unicode-characters-in-a-PDF-document/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; @@ -9,11 +7,8 @@ //Initialize the OCR processor by providing the path of tesseract. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from an existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/UnicodePDF.pdf"), FileMode.Open); - //Load the PDF document. - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/UnicodePDF.pdf")); //Sets Unicode font to preserve the Unicode characters in a PDF document. FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/ARIALUNI.ttf"), FileMode.Open); @@ -27,12 +22,8 @@ //Process OCR by providing the PDF document, data dictionary, and language string ocrText = processor.PerformOCR(loadedDocument, tessdataPath); - //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/OCR/.NET/Set-temp-folder-while-performing-OCR/Set-temp-folder-while-performing-OCR/Program.cs b/OCR/.NET/Set-temp-folder-while-performing-OCR/Set-temp-folder-while-performing-OCR/Program.cs index 7cf1ffd3..4f96a000 100644 --- a/OCR/.NET/Set-temp-folder-while-performing-OCR/Set-temp-folder-while-performing-OCR/Program.cs +++ b/OCR/.NET/Set-temp-folder-while-performing-OCR/Set-temp-folder-while-performing-OCR/Program.cs @@ -1,6 +1,4 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.OCRProcessor; +using Syncfusion.OCRProcessor; using Syncfusion.Pdf.Parsing; @@ -9,11 +7,8 @@ //Initialize the OCR processor by providing the path of the tesseract. using (OCRProcessor processor = new OCRProcessor()) { - //Get stream from an existing PDF document. - FileStream stream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. - PdfLoadedDocument document = new PdfLoadedDocument(stream); + PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Set OCR language to process. processor.Settings.Language = Languages.English; @@ -24,12 +19,8 @@ //Process OCR by providing the PDF document, data dictionary, and language. processor.PerformOCR(document, tessdataPath); - //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/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs index 485a076c..f72727eb 100644 --- a/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs +++ b/PDF Conformance/Convert-PDF-to-PDFA-conformance-document/.NET/Convert-PDF-to-PDFA-conformance-document/Program.cs @@ -1,15 +1,10 @@ -// See https://aka.ms/new-console-template for more information - -using SkiaSharp; +using SkiaSharp; using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get stream from the 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")); //Sample level font event handling loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont; @@ -60,13 +55,8 @@ void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args) //Convert the loaded document to PDF/A document loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B); -//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 to file stream. +loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. -docStream.Dispose(); loadedDocument.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Convert-PDFA-to-PDF-document/.NET/Convert-PDFA-to-PDF-document/Program.cs b/PDF Conformance/Convert-PDFA-to-PDF-document/.NET/Convert-PDFA-to-PDF-document/Program.cs index 5b3f2381..604e168c 100644 --- a/PDF Conformance/Convert-PDFA-to-PDF-document/.NET/Convert-PDFA-to-PDF-document/Program.cs +++ b/PDF Conformance/Convert-PDFA-to-PDF-document/.NET/Convert-PDFA-to-PDF-document/Program.cs @@ -1,22 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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 a PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); - -//Remove PDF/A conformance. -loadedDocument.RemoveConformance(); - -//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. - loadedDocument.Save(outputFileStream); -} + //Remove PDF/A conformance. + loadedDocument.RemoveConformance(); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/PDF Conformance/Creating-a-new-PDFA4F-document/.NET/Creating-a-new-PDFA4F-document/Program.cs b/PDF Conformance/Creating-a-new-PDFA4F-document/.NET/Creating-a-new-PDFA4F-document/Program.cs index 8e77dfd1..abbf8b91 100644 --- a/PDF Conformance/Creating-a-new-PDFA4F-document/.NET/Creating-a-new-PDFA4F-document/Program.cs +++ b/PDF Conformance/Creating-a-new-PDFA4F-document/.NET/Creating-a-new-PDFA4F-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.Pdf.Graphics; using Syncfusion.Pdf.Interactive; @@ -35,12 +33,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/PDF Conformance/Creating-the-new-PDFA1A-document/.NET/Creating-the-new-PDFA1A-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA1A-document/.NET/Creating-the-new-PDFA1A-document/Program.cs index 55c83dad..90b5f9ca 100644 --- a/PDF Conformance/Creating-the-new-PDFA1A-document/.NET/Creating-the-new-PDFA1A-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA1A-document/.NET/Creating-the-new-PDFA1A-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.Pdf.Graphics; //Create a new document with PDF/A-1a standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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. +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/PDF Conformance/Creating-the-new-PDFA1B-document/.NET/Creating-the-new-PDFA1B-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA1B-document/.NET/Creating-the-new-PDFA1B-document/Program.cs index c93969a6..9fa99774 100644 --- a/PDF Conformance/Creating-the-new-PDFA1B-document/.NET/Creating-the-new-PDFA1B-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA1B-document/.NET/Creating-the-new-PDFA1B-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.Pdf.Graphics; //Create a new document with PDF/A-1b standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/PDF Conformance/Creating-the-new-PDFA2A-document/.NET/Creating-the-new-PDFA2A-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA2A-document/.NET/Creating-the-new-PDFA2A-document/Program.cs index 74c18db5..22ec87b2 100644 --- a/PDF Conformance/Creating-the-new-PDFA2A-document/.NET/Creating-the-new-PDFA2A-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA2A-document/.NET/Creating-the-new-PDFA2A-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.Pdf.Graphics; //Create a new document with PDF/A-2a standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Creating-the-new-PDFA2B-document/.NET/Creating-the-new-PDFA2B-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA2B-document/.NET/Creating-the-new-PDFA2B-document/Program.cs index 22d7bcc9..780e6ced 100644 --- a/PDF Conformance/Creating-the-new-PDFA2B-document/.NET/Creating-the-new-PDFA2B-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA2B-document/.NET/Creating-the-new-PDFA2B-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.Pdf.Graphics; //Create a new document with PDF/A-2b standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/PDF Conformance/Creating-the-new-PDFA2U-document/.NET/Creating-the-new-PDFA2U-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA2U-document/.NET/Creating-the-new-PDFA2U-document/Program.cs index b2a21eb4..bf17389b 100644 --- a/PDF Conformance/Creating-the-new-PDFA2U-document/.NET/Creating-the-new-PDFA2U-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA2U-document/.NET/Creating-the-new-PDFA2U-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.Pdf.Graphics; //Create a new document with PDF/A-2u standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Creating-the-new-PDFA3A-document/.NET/Creating-the-new-PDFA3A-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA3A-document/.NET/Creating-the-new-PDFA3A-document/Program.cs index dcbfda4b..de717e24 100644 --- a/PDF Conformance/Creating-the-new-PDFA3A-document/.NET/Creating-the-new-PDFA3A-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA3A-document/.NET/Creating-the-new-PDFA3A-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.Pdf.Graphics; using Syncfusion.Pdf.Interactive; @@ -35,12 +33,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Creating-the-new-PDFA3B-document/.NET/Creating-the-new-PDFA3B-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA3B-document/.NET/Creating-the-new-PDFA3B-document/Program.cs index 3fa4d98b..d9b977d2 100644 --- a/PDF Conformance/Creating-the-new-PDFA3B-document/.NET/Creating-the-new-PDFA3B-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA3B-document/.NET/Creating-the-new-PDFA3B-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.Pdf.Graphics; using Syncfusion.Pdf.Interactive; @@ -35,12 +33,7 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); diff --git a/PDF Conformance/Creating-the-new-PDFA3U-document/.NET/Creating-the-new-PDFA3U-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA3U-document/.NET/Creating-the-new-PDFA3U-document/Program.cs index e528490f..b87a31c4 100644 --- a/PDF Conformance/Creating-the-new-PDFA3U-document/.NET/Creating-the-new-PDFA3U-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA3U-document/.NET/Creating-the-new-PDFA3U-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.Pdf.Graphics; using Syncfusion.Pdf.Interactive; @@ -35,12 +33,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Creating-the-new-PDFA4-document/.NET/Creating-the-new-PDFA4-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA4-document/.NET/Creating-the-new-PDFA4-document/Program.cs index 34b0eacf..8272c42b 100644 --- a/PDF Conformance/Creating-the-new-PDFA4-document/.NET/Creating-the-new-PDFA4-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA4-document/.NET/Creating-the-new-PDFA4-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.Pdf.Graphics; //Create a new document with the PDF/A-4 standard. @@ -21,12 +19,8 @@ //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 +document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); \ No newline at end of file diff --git a/PDF Conformance/Creating-the-new-PDFA4E-document/.NET/Creating-the-new-PDFA4E-document/Program.cs b/PDF Conformance/Creating-the-new-PDFA4E-document/.NET/Creating-the-new-PDFA4E-document/Program.cs index 9c6afa8f..68c7a3e9 100644 --- a/PDF Conformance/Creating-the-new-PDFA4E-document/.NET/Creating-the-new-PDFA4E-document/Program.cs +++ b/PDF Conformance/Creating-the-new-PDFA4E-document/.NET/Creating-the-new-PDFA4E-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.Interactive; @@ -24,12 +22,8 @@ //Add the annotation to the 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); \ No newline at end of file diff --git a/PDF Conformance/Font_Subsetting_in_PDFA_conversion/.NET/Font_Subsetting_in_PDFA_conversion/Program.cs b/PDF Conformance/Font_Subsetting_in_PDFA_conversion/.NET/Font_Subsetting_in_PDFA_conversion/Program.cs index 94137a32..32107421 100644 --- a/PDF Conformance/Font_Subsetting_in_PDFA_conversion/.NET/Font_Subsetting_in_PDFA_conversion/Program.cs +++ b/PDF Conformance/Font_Subsetting_in_PDFA_conversion/.NET/Font_Subsetting_in_PDFA_conversion/Program.cs @@ -6,8 +6,7 @@ using SkiaSharp; //Get stream from an existing 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")); //Sample level font event handling loadedDocument.SubstituteFont += LoadedDocument_SubstituteFont; @@ -23,16 +22,11 @@ // Convert to PDF/A conformance loadedDocument.ConvertToPDFA(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); -docStream.Close(); static void LoadedDocument_SubstituteFont(object sender, PdfFontEventArgs args) { diff --git a/PDF Conformance/Get-PDF-to-PDFA-conversion-progress/.NET/Get-PDF-to-PDFA-conversion-progress/Program.cs b/PDF Conformance/Get-PDF-to-PDFA-conversion-progress/.NET/Get-PDF-to-PDFA-conversion-progress/Program.cs index 87c4b894..351717b2 100644 --- a/PDF Conformance/Get-PDF-to-PDFA-conversion-progress/.NET/Get-PDF-to-PDFA-conversion-progress/Program.cs +++ b/PDF Conformance/Get-PDF-to-PDFA-conversion-progress/.NET/Get-PDF-to-PDFA-conversion-progress/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 an existing PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Subscribe to the PdfAConversionProgress event to track the PDF to PDF/A conversion process loadedDocument.PdfAConversionProgress += new PdfLoadedDocument.PdfAConversionProgressEventHandler(pdfAConversion_TrackProgress); @@ -15,13 +10,11 @@ loadedDocument.ConvertToPDFA(PdfConformanceLevel.Pdf_A1B); //Save the document -FileStream outputStream = new FileStream(Path.GetFullPath(@"Output.pdf"), FileMode.Create, FileAccess.Write); -loadedDocument.Save(outputStream); +loadedDocument.Save(Path.GetFullPath(@"Output.pdf")); //Close the document loadedDocument.Close(true); - - + //Event handler for Track PDF to PDF/A conversion process void pdfAConversion_TrackProgress(object sender, PdfAConversionProgressEventArgs arguments) { diff --git a/PDF Conformance/Get-the-conformance-level-of-the-existing-PDF-document/.NET/Program.cs b/PDF Conformance/Get-the-conformance-level-of-the-existing-PDF-document/.NET/Program.cs index 6ca28fda..73199bee 100644 --- a/PDF Conformance/Get-the-conformance-level-of-the-existing-PDF-document/.NET/Program.cs +++ b/PDF Conformance/Get-the-conformance-level-of-the-existing-PDF-document/.NET/Program.cs @@ -1,18 +1,11 @@ -// 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 the conformance level of the loaded document. -PdfConformanceLevel conformance = loadedDocument.Conformance; - -Console.WriteLine("Conformance level :" + conformance); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the conformance level of the loaded document. + PdfConformanceLevel conformance = loadedDocument.Conformance; -//Close the document. -loadedDocument.Close(true); + Console.WriteLine("Conformance level :" + conformance); +} diff --git a/PDF Document/Add_BaseUri_in_the_PDF_document/.NET/Add_BaseUri_in_the_PDF_document/Program.cs b/PDF Document/Add_BaseUri_in_the_PDF_document/.NET/Add_BaseUri_in_the_PDF_document/Program.cs index f22e833a..8bf22a91 100644 --- a/PDF Document/Add_BaseUri_in_the_PDF_document/.NET/Add_BaseUri_in_the_PDF_document/Program.cs +++ b/PDF Document/Add_BaseUri_in_the_PDF_document/.NET/Add_BaseUri_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; - -//Create a new instance of the PdfDocument class. -PdfDocument document = new PdfDocument(); - -//Set the Base URI. -document.BaseUri = "https://www.syncfusion.com/"; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Set the Base URI. + document.BaseUri = "https://www.syncfusion.com/"; -//Create a new page. -PdfPage page = document.Pages.Add(); + //Create a new page. + PdfPage page = document.Pages.Add(); -//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/PDF Document/Add_PDF_document_properties/.NET/Add_PDF_document_properties/Program.cs b/PDF Document/Add_PDF_document_properties/.NET/Add_PDF_document_properties/Program.cs index ee2d3ad5..2228cb64 100644 --- a/PDF Document/Add_PDF_document_properties/.NET/Add_PDF_document_properties/Program.cs +++ b/PDF Document/Add_PDF_document_properties/.NET/Add_PDF_document_properties/Program.cs @@ -1,37 +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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set document information. -document.DocumentInformation.Author = "Syncfusion"; -document.DocumentInformation.CreationDate = DateTime.Now; -document.DocumentInformation.Creator = "Essential PDF"; -document.DocumentInformation.Keywords = "PDF"; -document.DocumentInformation.Subject = "Document information DEMO"; -document.DocumentInformation.Title = "Essential PDF Sample"; +using (PdfDocument document = new PdfDocument()) +{ + //Set document information. + document.DocumentInformation.Author = "Syncfusion"; + document.DocumentInformation.CreationDate = DateTime.Now; + document.DocumentInformation.Creator = "Essential PDF"; + document.DocumentInformation.Keywords = "PDF"; + document.DocumentInformation.Subject = "Document information DEMO"; + document.DocumentInformation.Title = "Essential PDF Sample"; -//Add a page to the document. -PdfPage page = document.Pages.Add(); + //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; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw text to the page. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); + //Draw text to the page. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/PDF Document/Change-the-page-orientation-from-portrait-to-landscape/.NET/Change-the-page-orientation-from-portrait-to-landscape/Program.cs b/PDF Document/Change-the-page-orientation-from-portrait-to-landscape/.NET/Change-the-page-orientation-from-portrait-to-landscape/Program.cs index 757ecb7f..4c15cc47 100644 --- a/PDF Document/Change-the-page-orientation-from-portrait-to-landscape/.NET/Change-the-page-orientation-from-portrait-to-landscape/Program.cs +++ b/PDF Document/Change-the-page-orientation-from-portrait-to-landscape/.NET/Change-the-page-orientation-from-portrait-to-landscape/Program.cs @@ -1,35 +1,27 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the page size. -document.PageSettings.Size = PdfPageSize.A4; - -//Change the page orientation to landscape. -document.PageSettings.Orientation = PdfPageOrientation.Landscape; +using (PdfDocument document = new PdfDocument()) +{ + //Set the page size. + document.PageSettings.Size = PdfPageSize.A4; -//Add a page to the document. -PdfPage page = document.Pages.Add(); + //Change the page orientation to landscape. + document.PageSettings.Orientation = PdfPageOrientation.Landscape; -//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; -//Draw the text in PDF page. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Create file stream for output PDF document. -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 text in PDF page. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); -//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/PDF Document/Change_existing_PDF_properties/.NET/Change_existing_PDF_properties/Program.cs b/PDF Document/Change_existing_PDF_properties/.NET/Change_existing_PDF_properties/Program.cs index 80ea5e52..fdf8a2f2 100644 --- a/PDF Document/Change_existing_PDF_properties/.NET/Change_existing_PDF_properties/Program.cs +++ b/PDF Document/Change_existing_PDF_properties/.NET/Change_existing_PDF_properties/Program.cs @@ -1,29 +1,18 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(fileStreamPath); - -//Modify the document information. -document.DocumentInformation.Author = "Syncfusion"; -document.DocumentInformation.CreationDate = DateTime.Now; -document.DocumentInformation.Creator = "Essential PDF"; -document.DocumentInformation.Keywords = "PDF"; -document.DocumentInformation.Subject = "Document information DEMO"; -document.DocumentInformation.Title = "Essential PDF Sample"; -document.DocumentInformation.ModificationDate = DateTime.Now; -document.DocumentInformation.Producer = "Syncfusion PDF"; - -//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. - document.Save(outputFileStream); -} + //Modify the document information. + loadedDocument.DocumentInformation.Author = "Syncfusion"; + loadedDocument.DocumentInformation.CreationDate = DateTime.Now; + loadedDocument.DocumentInformation.Creator = "Essential PDF"; + loadedDocument.DocumentInformation.Keywords = "PDF"; + loadedDocument.DocumentInformation.Subject = "Document information DEMO"; + loadedDocument.DocumentInformation.Title = "Essential PDF Sample"; + loadedDocument.DocumentInformation.ModificationDate = DateTime.Now; + loadedDocument.DocumentInformation.Producer = "Syncfusion PDF"; -//Closes the PDF 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/PDF Document/Create-PDF-with-display-of-specific-panel/.NET/Create-PDF-with-display-of-specific-panel/Program.cs b/PDF Document/Create-PDF-with-display-of-specific-panel/.NET/Create-PDF-with-display-of-specific-panel/Program.cs index 9738740f..a2493afa 100644 --- a/PDF Document/Create-PDF-with-display-of-specific-panel/.NET/Create-PDF-with-display-of-specific-panel/Program.cs +++ b/PDF Document/Create-PDF-with-display-of-specific-panel/.NET/Create-PDF-with-display-of-specific-panel/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +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(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //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; -//Draw the text. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Show the attachments panel. -document.ViewerPreferences.PageMode = PdfPageMode.UseAttachments; + //Draw the text. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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); -} + //Show the attachments panel. + document.ViewerPreferences.PageMode = PdfPageMode.UseAttachments; -//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/PDF Document/Create-a-PDF-document-with-custom-page-size/.NET/Create-a-PDF-document-with-custom-page-size/Program.cs b/PDF Document/Create-a-PDF-document-with-custom-page-size/.NET/Create-a-PDF-document-with-custom-page-size/Program.cs index 782816ab..d9a77ffd 100644 --- a/PDF Document/Create-a-PDF-document-with-custom-page-size/.NET/Create-a-PDF-document-with-custom-page-size/Program.cs +++ b/PDF Document/Create-a-PDF-document-with-custom-page-size/.NET/Create-a-PDF-document-with-custom-page-size/Program.cs @@ -1,32 +1,24 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the custom page size. -document.PageSettings.Size = new Syncfusion.Drawing.SizeF(200, 300); +using (PdfDocument document = new PdfDocument()) +{ + //Set the custom page size. + document.PageSettings.Size = new Syncfusion.Drawing.SizeF(200, 300); -//Add a page to the document. -PdfPage page = document.Pages.Add(); + //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; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw the text. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); + //Draw the text. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/PDF Document/Create-a-PDF-document-with-save-progress/.NET/PDF-document-with-save-progress/Program.cs b/PDF Document/Create-a-PDF-document-with-save-progress/.NET/PDF-document-with-save-progress/Program.cs index 65de8d6e..1e743301 100644 --- a/PDF Document/Create-a-PDF-document-with-save-progress/.NET/PDF-document-with-save-progress/Program.cs +++ b/PDF Document/Create-a-PDF-document-with-save-progress/.NET/PDF-document-with-save-progress/Program.cs @@ -1,41 +1,34 @@ - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create a new PDF document. -PdfDocument document = new PdfDocument(); - -// Add multiple pages to the document. -for (int i = 0; i < 10; i++) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - // Add a new page. - PdfPage page = document.Pages.Add(); + // Add multiple pages to the document. + for (int i = 0; i < 10; i++) + { + // Add a new page. + 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; - // Set the font to Helvetica with size 20. - PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + // Set the font to Helvetica with size 20. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); - // Draw text on the page. - graphics.DrawString($"This is page {i + 1}", font, PdfBrushes.Black, new PointF(0, 0)); -} + // Draw text on the page. + graphics.DrawString($"This is page {i + 1}", font, PdfBrushes.Black, new PointF(0, 0)); + } -// Subscribe to the SaveProgress event. -document.SaveProgress += new PdfDocument.ProgressEventHandler(document_SaveProgress); + // Subscribe to the SaveProgress event. + document.SaveProgress += new PdfDocument.ProgressEventHandler(document_SaveProgress); -// Create a file stream to save the PDF document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - // Save the PDF document to the file stream. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -// Close the document. -document.Close(true); - // Event handler for the SaveProgress event. void document_SaveProgress(object sender, ProgressEventArgs arguments) { diff --git a/PDF Document/Create-a-PDF-document-with-standard-page-size/.NET/Create-a-PDF-document-with-standard-page-size/Program.cs b/PDF Document/Create-a-PDF-document-with-standard-page-size/.NET/Create-a-PDF-document-with-standard-page-size/Program.cs index 43ce962e..50813d2b 100644 --- a/PDF Document/Create-a-PDF-document-with-standard-page-size/.NET/Create-a-PDF-document-with-standard-page-size/Program.cs +++ b/PDF Document/Create-a-PDF-document-with-standard-page-size/.NET/Create-a-PDF-document-with-standard-page-size/Program.cs @@ -1,32 +1,25 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; -//Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Set the page size. -document.PageSettings.Size = PdfPageSize.A4; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Set the page size. + document.PageSettings.Size = PdfPageSize.A4; -//Add a page to the document. -PdfPage page = document.Pages.Add(); + //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; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw the text. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); + //Draw the text. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); \ No newline at end of file diff --git a/PDF Document/Create_PDF_with_Uniform_Resouce_Naming/.NET/Create_PDF_with_Uniform_Resouce_Naming/Program.cs b/PDF Document/Create_PDF_with_Uniform_Resouce_Naming/.NET/Create_PDF_with_Uniform_Resouce_Naming/Program.cs index 1383742d..94060db5 100644 --- a/PDF Document/Create_PDF_with_Uniform_Resouce_Naming/.NET/Create_PDF_with_Uniform_Resouce_Naming/Program.cs +++ b/PDF Document/Create_PDF_with_Uniform_Resouce_Naming/.NET/Create_PDF_with_Uniform_Resouce_Naming/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.Graphics; @@ -8,39 +6,33 @@ PdfDocument.EnableUniqueResourceNaming = false; //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 instance for PDF font. -PdfFont font1 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Create new instance for PDF font. + PdfFont font1 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw the text with Helvetica standard font. -graphics.DrawString("Hello World!!!", font1, PdfBrushes.BlueViolet, new PointF(50, 50)); + //Draw the text with Helvetica standard font. + graphics.DrawString("Hello World!!!", font1, PdfBrushes.BlueViolet, new PointF(50, 50)); -//Create new instance for PDF font from TTF file. -FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read); -PdfFont font2 = new PdfTrueTypeFont(fontStream, 20); + //Create new instance for PDF font from TTF file. + FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/Arial.ttf"), FileMode.Open, FileAccess.Read); + PdfFont font2 = new PdfTrueTypeFont(fontStream, 20); -//Draw the text with Arial font. -graphics.DrawString("Hello World!!!", font2, PdfBrushes.OrangeRed, new PointF(50, 100)); + //Draw the text with Arial font. + graphics.DrawString("Hello World!!!", font2, PdfBrushes.OrangeRed, new PointF(50, 100)); -//Create new instance for PDF Japanese font. -PdfFont font3 = new PdfCjkStandardFont(PdfCjkFontFamily.HeiseiMinchoW3, 20); + //Create new instance for PDF Japanese font. + PdfFont font3 = new PdfCjkStandardFont(PdfCjkFontFamily.HeiseiMinchoW3, 20); -//Draw the text with Japanese font. -graphics.DrawString("こんにちは世界", font3, PdfBrushes.GreenYellow, new PointF(50, 150)); + //Draw the text with Japanese font. + graphics.DrawString("こんにちは世界", font3, PdfBrushes.GreenYellow, new PointF(50, 150)); -//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 PDF document. -document.Close(true); diff --git a/PDF Document/Create_PDF_with_viewer_preference/.NET/Create_PDF_with_viewer_preference/Program.cs b/PDF Document/Create_PDF_with_viewer_preference/.NET/Create_PDF_with_viewer_preference/Program.cs index 3a47ac80..8167548b 100644 --- a/PDF Document/Create_PDF_with_viewer_preference/.NET/Create_PDF_with_viewer_preference/Program.cs +++ b/PDF Document/Create_PDF_with_viewer_preference/.NET/Create_PDF_with_viewer_preference/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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//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; + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Draw the text. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Draw the text. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); + //Hide viewer application's menu bar. + document.ViewerPreferences.HideMenubar = true; -//Hide viewer application's menu bar. -document.ViewerPreferences.HideMenubar = true; + //Hide viewer application's toolbar. + document.ViewerPreferences.HideToolbar = true; -//Hide viewer application's toolbar. -document.ViewerPreferences.HideToolbar = true; + //Shows user interface elements in the document's window (such as scroll bars and navigation controls). + document.ViewerPreferences.HideWindowUI = false; -//Shows user interface elements in the document's window (such as scroll bars and navigation controls). -document.ViewerPreferences.HideWindowUI = false; + //Show the attachments panel. + document.ViewerPreferences.PageMode = PdfPageMode.UseAttachments; -//Show the attachments panel. -document.ViewerPreferences.PageMode = PdfPageMode.UseAttachments; -//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/PDF Document/Create_sections_in_PDF_document/.NET/Create_sections_in_PDF_document/Program.cs b/PDF Document/Create_sections_in_PDF_document/.NET/Create_sections_in_PDF_document/Program.cs index afc0e48a..1e7c8c2d 100644 --- a/PDF Document/Create_sections_in_PDF_document/.NET/Create_sections_in_PDF_document/Program.cs +++ b/PDF Document/Create_sections_in_PDF_document/.NET/Create_sections_in_PDF_document/Program.cs @@ -1,35 +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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a section to PDF document. -PdfSection section = document.Sections.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a section to PDF document. + PdfSection section = document.Sections.Add(); -//Set the page size for section. -section.PageSettings.Size = PdfPageSize.A3; + //Set the page size for section. + section.PageSettings.Size = PdfPageSize.A3; -//Add pages to the section. -PdfPage page = section.Pages.Add(); + //Add pages to the section. + PdfPage page = section.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw text to the page. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); + //Draw text to the page. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/PDF Document/Find_corrupted_PDF_document/.NET/Find_corrupted_PDF_document/Program.cs b/PDF Document/Find_corrupted_PDF_document/.NET/Find_corrupted_PDF_document/Program.cs index 51fa29c0..3bb9fa93 100644 --- a/PDF Document/Find_corrupted_PDF_document/.NET/Find_corrupted_PDF_document/Program.cs +++ b/PDF Document/Find_corrupted_PDF_document/.NET/Find_corrupted_PDF_document/Program.cs @@ -1,14 +1,9 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; using System.Text; -//Get file stream from an existing PDF document. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Test.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - //Create a new instance for the PDF analyzer. -PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(fileStream); +PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(Path.GetFullPath(@"Data/Test.pdf"); //Get the syntax errors. SyntaxAnalyzerResult result = analyzer.AnalyzeSyntax(); diff --git a/PDF Document/Manage_memory_while_appending_PDF_document/.NET/Manage_memory_while_appending_PDF_document/Program.cs b/PDF Document/Manage_memory_while_appending_PDF_document/.NET/Manage_memory_while_appending_PDF_document/Program.cs index 96d1283d..63fc2812 100644 --- a/PDF Document/Manage_memory_while_appending_PDF_document/.NET/Manage_memory_while_appending_PDF_document/Program.cs +++ b/PDF Document/Manage_memory_while_appending_PDF_document/.NET/Manage_memory_while_appending_PDF_document/Program.cs @@ -1,13 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -//Get file stream from an existing PDF document -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStreamPath); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); //Create a new PDF document. PdfDocument document = new PdfDocument(); @@ -18,14 +13,10 @@ //Append the document with source document. document.Append(loadedDocument); -//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); - +loadedDocument.Close(true); diff --git a/PDF Document/Perform-incremental-update-for-the-PDF-document/.NET/Perform-incremental-update-for-the-PDF-document/Program.cs b/PDF Document/Perform-incremental-update-for-the-PDF-document/.NET/Perform-incremental-update-for-the-PDF-document/Program.cs index f0dd7556..314f46bf 100644 --- a/PDF Document/Perform-incremental-update-for-the-PDF-document/.NET/Perform-incremental-update-for-the-PDF-document/Program.cs +++ b/PDF Document/Perform-incremental-update-for-the-PDF-document/.NET/Perform-incremental-update-for-the-PDF-document/Program.cs @@ -1,26 +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); - -//Disable the incremental update. -loadedDocument.FileStructure.IncrementalUpdate = false; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Disable the incremental update. + loadedDocument.FileStructure.IncrementalUpdate = false; -//Set the compression level. -loadedDocument.Compression = PdfCompressionLevel.Best; + //Set the compression level. + loadedDocument.Compression = PdfCompressionLevel.Best; -//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/PDF Document/Remove-specific-keys-from-the-existing-document-information/.NET/Program.cs b/PDF Document/Remove-specific-keys-from-the-existing-document-information/.NET/Program.cs index 79b3a1fe..8d7366d2 100644 --- a/PDF Document/Remove-specific-keys-from-the-existing-document-information/.NET/Program.cs +++ b/PDF Document/Remove-specific-keys-from-the-existing-document-information/.NET/Program.cs @@ -4,8 +4,7 @@ namespace Remove_specific_keys_from_the_existing_document_information { internal class Program { static void Main(string[] args) { //Load an existing PDF document. - FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read); - PdfLoadedDocument document = new PdfLoadedDocument(fileStream); + PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); //Remove the document information properties. document.DocumentInformation.Remove("Title"); document.DocumentInformation.Remove("Author"); @@ -15,12 +14,9 @@ static void Main(string[] args) { document.DocumentInformation.Remove("Producer"); document.DocumentInformation.Remove("ModDate"); document.DocumentInformation.Remove("CreationDate"); - - //Creating the stream object. - MemoryStream stream = new MemoryStream(); - //Save the document into stream. - document.Save(stream); - File.WriteAllBytes(Path.GetFullPath(@"Output/Output.pdf"), stream.ToArray()); + + //Save the document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); //Close the document. document.Close(true); } diff --git a/PDF Document/Retrieve_BaseUri_from_the_existing_PDF/.NET/Retrieve_BaseUri_from_the_existing_PDF/Program.cs b/PDF Document/Retrieve_BaseUri_from_the_existing_PDF/.NET/Retrieve_BaseUri_from_the_existing_PDF/Program.cs index 243dd256..1ae0f6e6 100644 --- a/PDF Document/Retrieve_BaseUri_from_the_existing_PDF/.NET/Retrieve_BaseUri_from_the_existing_PDF/Program.cs +++ b/PDF Document/Retrieve_BaseUri_from_the_existing_PDF/.NET/Retrieve_BaseUri_from_the_existing_PDF/Program.cs @@ -1,16 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the Base URI. + string baseUri = loadedDocument.BaseUri; -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load a PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(fileStream); - -//Get the Base URI. -string baseUri = document.BaseUri; - -//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/PDF Document/Rotate_PDF_based_on_angle/.NET/Rotate_PDF_based_on_angle/Program.cs b/PDF Document/Rotate_PDF_based_on_angle/.NET/Rotate_PDF_based_on_angle/Program.cs index 8cef79a0..3a5dadba 100644 --- a/PDF Document/Rotate_PDF_based_on_angle/.NET/Rotate_PDF_based_on_angle/Program.cs +++ b/PDF Document/Rotate_PDF_based_on_angle/.NET/Rotate_PDF_based_on_angle/Program.cs @@ -1,35 +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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the page size. -document.PageSettings.Size = PdfPageSize.A4; +using (PdfDocument document = new PdfDocument()) +{ + //Set the page size. + document.PageSettings.Size = PdfPageSize.A4; -//Change the page orientation to 90°. -document.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; + //Change the page orientation to 90°. + document.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; -//Add a page to the document. -PdfPage page = document.Pages.Add(); + //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; -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); -//Draw text in the page. -graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); + //Draw text in the page. + graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); -//Save the document. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/PDF Templates/Add-a-template-from-an-existing-PDF-document/.NET/Add-a-template-from-an-existing-PDF-document/Program.cs b/PDF Templates/Add-a-template-from-an-existing-PDF-document/.NET/Add-a-template-from-an-existing-PDF-document/Program.cs index b9fbaf95..07317de9 100644 --- a/PDF Templates/Add-a-template-from-an-existing-PDF-document/.NET/Add-a-template-from-an-existing-PDF-document/Program.cs +++ b/PDF Templates/Add-a-template-from-an-existing-PDF-document/.NET/Add-a-template-from-an-existing-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 the first page of the document. -PdfPageBase page = loadedDocument.Pages[0]; - -//Create a page template. -PdfPageTemplate pageTemplate = new PdfPageTemplate(page); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the first page of the document. + PdfPageBase page = loadedDocument.Pages[0]; -//Sets the PdfPageTemplate name. -pageTemplate.Name = "pageTemplate"; + //Create a page template. + PdfPageTemplate pageTemplate = new PdfPageTemplate(page); -//Sets the PdfPageTemplate is visible. -pageTemplate.IsVisible = true; + //Sets the PdfPageTemplate name. + pageTemplate.Name = "pageTemplate"; -//Adds the page template. -loadedDocument.PdfPageTemplates.Add(pageTemplate); + //Sets the PdfPageTemplate is visible. + pageTemplate.IsVisible = 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); -} + //Adds the page template. + loadedDocument.PdfPageTemplates.Add(pageTemplate); -//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/PDF Templates/Add-the-contents-to-template-and-render-into-PDF-page/.NET/Add-the-contents-to-template-and-render-into-PDF-page/Program.cs b/PDF Templates/Add-the-contents-to-template-and-render-into-PDF-page/.NET/Add-the-contents-to-template-and-render-into-PDF-page/Program.cs index a741fc1f..74a0e75e 100644 --- a/PDF Templates/Add-the-contents-to-template-and-render-into-PDF-page/.NET/Add-the-contents-to-template-and-render-into-PDF-page/Program.cs +++ b/PDF Templates/Add-the-contents-to-template-and-render-into-PDF-page/.NET/Add-the-contents-to-template-and-render-into-PDF-page/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.Graphics; @@ -10,30 +8,30 @@ //Add a page to the PDF document. PdfPage pdfPage = pdfDocument.Pages.Add(); -//Create a PDF Template. -PdfTemplate template = new PdfTemplate(100, 50); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); + + //Create a PDF Template. + PdfTemplate template = new PdfTemplate(100, 50); -//Draw a rectangle on the template graphics. -template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new Syncfusion.Drawing.RectangleF(0, 0, 100, 50)); + //Draw a rectangle on the template graphics. + template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new Syncfusion.Drawing.RectangleF(0, 0, 100, 50)); -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Create the brush. -PdfBrush brush = new PdfSolidBrush(Color.Black); + //Create the brush. + PdfBrush brush = new PdfSolidBrush(Color.Black); -//Draw a string using the graphics of the template. -template.Graphics.DrawString("Hello World", font, brush, 5, 5); + //Draw a string using the graphics of the template. + template.Graphics.DrawString("Hello World", font, brush, 5, 5); -//Draw the template on the page graphics of the document. -pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); + //Draw the template on the page graphics of the document. + pdfPage.Graphics.DrawPdfTemplate(template, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/PDF Templates/Add-the-page-template-elements-in-a-PDF-document/.NET/Add-the-page-template-elements-in-a-PDF-document/Program.cs b/PDF Templates/Add-the-page-template-elements-in-a-PDF-document/.NET/Add-the-page-template-elements-in-a-PDF-document/Program.cs index 6039fa37..8eca649e 100644 --- a/PDF Templates/Add-the-page-template-elements-in-a-PDF-document/.NET/Add-the-page-template-elements-in-a-PDF-document/Program.cs +++ b/PDF Templates/Add-the-page-template-elements-in-a-PDF-document/.NET/Add-the-page-template-elements-in-a-PDF-document/Program.cs @@ -1,64 +1,55 @@ -// 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 a header and draw the image. -RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50); - -//Create template element. -PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Get stream from the image file. -FileStream imageStream = new FileStream(Path.GetFullPath(Path.GetFullPath(@"Data/Logo.jpg")), FileMode.Open, FileAccess.Read); + //Create a header and draw the image. + RectangleF bounds = new RectangleF(0, 0, document.Pages[0].GetClientSize().Width, 50); -//Load the image file. -PdfImage image = new PdfBitmap(imageStream); + //Create template element. + PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); -//Draw the image in the header. -header.Graphics.DrawImage(image, new Syncfusion.Drawing.PointF(0, 0), new SizeF(100, 50)); + //Get stream from the image file. + FileStream imageStream = new FileStream(Path.GetFullPath(Path.GetFullPath(@"Data/Logo.jpg")), FileMode.Open, FileAccess.Read); -//Add the header at the top. -pdfDocument.Template.Top = header; + //Load the image file. + PdfImage image = new PdfBitmap(imageStream); -//Create a Page template that can be used as footer. -PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); + //Draw the image in the header. + header.Graphics.DrawImage(image, new Syncfusion.Drawing.PointF(0, 0), new SizeF(100, 50)); -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); + //Add the header at the top. + document.Template.Top = header; -//Create the brush. -PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); + //Create a Page template that can be used as footer. + PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); -//Create page number field. -PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); -//Create page count field. -PdfPageCountField count = new PdfPageCountField(font, brush); + //Create the brush. + PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); -//Add the fields in composite fields. -PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); -compositeField.Bounds = footer.Bounds; + //Create page number field. + PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); -//Draw the composite field in footer. -compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(470, 40)); + //Create page count field. + PdfPageCountField count = new PdfPageCountField(font, brush); -//Add the footer template at the bottom. -pdfDocument.Template.Bottom = footer; + //Add the fields in composite fields. + PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); + compositeField.Bounds = footer.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); -} + //Draw the composite field in footer. + compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(470, 40)); -//Close the document. -pdfDocument.Close(true); \ No newline at end of file + //Add the footer template at the bottom. + document.Template.Bottom = footer; + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/PDF Templates/Create-template-from-an-existing-PDF-document/.NET/Create-template-from-an-existing-PDF-document/Program.cs b/PDF Templates/Create-template-from-an-existing-PDF-document/.NET/Create-template-from-an-existing-PDF-document/Program.cs index 115560e6..8f321605 100644 --- a/PDF Templates/Create-template-from-an-existing-PDF-document/.NET/Create-template-from-an-existing-PDF-document/Program.cs +++ b/PDF Templates/Create-template-from-an-existing-PDF-document/.NET/Create-template-from-an-existing-PDF-document/Program.cs @@ -1,43 +1,31 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +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. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create the template from the page. -PdfTemplate template = loadedPage.CreateTemplate(); + //Create the template from the page. + PdfTemplate template = loadedPage.CreateTemplate(); -//Create a new PDF document. -PdfDocument document = new PdfDocument(); + //Create a new PDF document. + PdfDocument document = new PdfDocument(); -//Set the document margin. -document.PageSettings.SetMargins(2); + //Set the document margin. + document.PageSettings.SetMargins(2); -//Add the page. -PdfPage page = document.Pages.Add(); + //Add the page. + PdfPage page = document.Pages.Add(); -//Create the graphics. -PdfGraphics graphics = page.Graphics; + //Create the graphics. + PdfGraphics graphics = page.Graphics; -//Draw the template. -graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty, new Syncfusion.Drawing.SizeF(page.Size.Width / 2, page.Size.Height)); + //Draw the template. + graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty, new Syncfusion.Drawing.SizeF(page.Size.Width / 2, page.Size.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); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the documents. -loadedDocument.Close(true); -document.Close(true); diff --git a/PDF Templates/Creating-the-document-overlays/.NET/Creating-the-document-overlays/Program.cs b/PDF Templates/Creating-the-document-overlays/.NET/Creating-the-document-overlays/Program.cs index a7e930eb..2607c22b 100644 --- a/PDF Templates/Creating-the-document-overlays/.NET/Creating-the-document-overlays/Program.cs +++ b/PDF Templates/Creating-the-document-overlays/.NET/Creating-the-document-overlays/Program.cs @@ -1,21 +1,13 @@ -// 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 the stream from an existing PDF document. -FileStream docStream1 = new FileStream(Path.GetFullPath(@"Data/File1.pdf"), FileMode.Open, FileAccess.Read); - //Load the PDF document. -PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(docStream1); - -//Get the stream from an existing PDF document. -FileStream docStream2 = new FileStream(Path.GetFullPath(@"Data/File2.pdf"), FileMode.Open, FileAccess.Read); +PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File1.pdf")); //Load the PDF document. -PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(docStream2); +PdfLoadedDocument loadedDocument2 = new PdfLoadedDocument(Path.GetFullPath(@"Data/File2.pdf")); //Create the new document. PdfDocument document = new PdfDocument(); @@ -42,12 +34,10 @@ //Draw the loaded template into new document. page2.Graphics.DrawPdfTemplate(template, new PointF(10, 10), new SizeF(400, 500)); -//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 +document.Close(true); +loadedDocument1.Close(true); +loadedDocument2.Close(true); diff --git a/PDF Templates/Render-the-template-in-an-existing-PDF-document/.NET/Render-the-template-in-an-existing-PDF-document/Program.cs b/PDF Templates/Render-the-template-in-an-existing-PDF-document/.NET/Render-the-template-in-an-existing-PDF-document/Program.cs index dad35916..b5ad5afb 100644 --- a/PDF Templates/Render-the-template-in-an-existing-PDF-document/.NET/Render-the-template-in-an-existing-PDF-document/Program.cs +++ b/PDF Templates/Render-the-template-in-an-existing-PDF-document/.NET/Render-the-template-in-an-existing-PDF-document/Program.cs @@ -1,42 +1,31 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +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 into Pdf document. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Load the page into Pdf document. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create a PDF Template. -PdfTemplate template = new PdfTemplate(100, 50); + //Create a PDF Template. + PdfTemplate template = new PdfTemplate(100, 50); -//Draw a rectangle on the template graphics. -template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new Syncfusion.Drawing.RectangleF(0, 0, 100, 50)); + //Draw a rectangle on the template graphics. + template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new Syncfusion.Drawing.RectangleF(0, 0, 100, 50)); -//Create the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Create the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Create the brush. -PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); + //Create the brush. + PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); -//Draw a string on the graphics of the template. -template.Graphics.DrawString("Hello World", font, brush, 5, 5); + //Draw a string on the graphics of the template. + template.Graphics.DrawString("Hello World", font, brush, 5, 5); -//Draw the template on the page graphics of the document. -loadedPage.Graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty); + //Draw the template on the page graphics of the document. + loadedPage.Graphics.DrawPdfTemplate(template, 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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Pages/Add-a-new-page-to-the-PDF-document/.NET/Add-a-new-page-to-the-PDF-document/Program.cs b/Pages/Add-a-new-page-to-the-PDF-document/.NET/Add-a-new-page-to-the-PDF-document/Program.cs index 0633665b..26199f49 100644 --- a/Pages/Add-a-new-page-to-the-PDF-document/.NET/Add-a-new-page-to-the-PDF-document/Program.cs +++ b/Pages/Add-a-new-page-to-the-PDF-document/.NET/Add-a-new-page-to-the-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.Graphics; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a new page. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page. + 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 a solid brush. -PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); + //Create a solid brush. + PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Draw the text. -graphics.DrawString("Hello world!", font, brush, new Syncfusion.Drawing.PointF(20, 20)); + //Draw the text. + graphics.DrawString("Hello world!", font, brush, new Syncfusion.Drawing.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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Pages/Add-margin-to-the-PDF-pages/.NET/Add-margin-to-the-PDF-pages/Program.cs b/Pages/Add-margin-to-the-PDF-pages/.NET/Add-margin-to-the-PDF-pages/Program.cs index 3e2b05d5..79a93287 100644 --- a/Pages/Add-margin-to-the-PDF-pages/.NET/Add-margin-to-the-PDF-pages/Program.cs +++ b/Pages/Add-margin-to-the-PDF-pages/.NET/Add-margin-to-the-PDF-pages/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; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set margin for all the pages. -document.PageSettings.Margins.All = 100; +using (PdfDocument document = new PdfDocument()) +{ + //Set margin for all the pages. + document.PageSettings.Margins.All = 100; -//Add a page. -PdfPage page = document.Pages.Add(); + //Add a page. + 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; -//Creates a solid brush. -PdfBrush brush = new PdfSolidBrush(Color.Black); + //Creates a solid brush. + PdfBrush brush = new PdfSolidBrush(Color.Black); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Draw the text. -graphics.DrawString("Hello world!", font, brush, new PointF(0, 0)); + //Draw the text. + graphics.DrawString("Hello world!", font, brush, 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); diff --git a/Pages/Adding-sections-with-different-page-settings/.NET/Adding-sections-with-different-page-settings/Program.cs b/Pages/Adding-sections-with-different-page-settings/.NET/Adding-sections-with-different-page-settings/Program.cs index 5817c95d..e1672d50 100644 --- a/Pages/Adding-sections-with-different-page-settings/.NET/Adding-sections-with-different-page-settings/Program.cs +++ b/Pages/Adding-sections-with-different-page-settings/.NET/Adding-sections-with-different-page-settings/Program.cs @@ -1,88 +1,80 @@ -// 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(); - -//Create a solid brush and standard font. -PdfBrush brush = new PdfSolidBrush(Color.Black); -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); +using (PdfDocument document = new PdfDocument()) +{ + //Create a solid brush and standard font. + PdfBrush brush = new PdfSolidBrush(Color.Black); + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Section - 1 -//Add new section to the document. -PdfSection section = document.Sections.Add(); + //Section - 1 + //Add new section to the document. + PdfSection section = document.Sections.Add(); -//Create page settings to the section. -section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0; -section.PageSettings.Size = PdfPageSize.A5; -section.PageSettings.Width = 300; -section.PageSettings.Height = 400; + //Create page settings to the section. + section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0; + section.PageSettings.Size = PdfPageSize.A5; + section.PageSettings.Width = 300; + section.PageSettings.Height = 400; -//Add page to the section and initialize graphics for the page. -PdfPage page = section.Pages.Add(); -PdfGraphics graphics = page.Graphics; + //Add page to the section and initialize graphics for the page. + PdfPage page = section.Pages.Add(); + PdfGraphics graphics = page.Graphics; -//Draw simple text on the page. -graphics.DrawString("Rotated by 0 degrees", font, brush, new PointF(20, 20)); + //Draw simple text on the page. + graphics.DrawString("Rotated by 0 degrees", font, brush, new PointF(20, 20)); -//Section - 2 -//Add new section to the document. -section = document.Sections.Add(); + //Section - 2 + //Add new section to the document. + section = document.Sections.Add(); -//Create page settings to the section. -section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; -section.PageSettings.Width = 300; -section.PageSettings.Height = 400; + //Create page settings to the section. + section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; + section.PageSettings.Width = 300; + section.PageSettings.Height = 400; -//Add page to the section and initialize graphics for the page. -page = section.Pages.Add(); -graphics = page.Graphics; + //Add page to the section and initialize graphics for the page. + page = section.Pages.Add(); + graphics = page.Graphics; -//Draw simple text on the page. -graphics.DrawString("Rotated by 90 degrees", font, brush, new PointF(20, 20)); + //Draw simple text on the page. + graphics.DrawString("Rotated by 90 degrees", font, brush, new PointF(20, 20)); -//Section - 3 -//Add new section to the document. -section = document.Sections.Add(); + //Section - 3 + //Add new section to the document. + section = document.Sections.Add(); -//Create page settings to the section. -section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180; -section.PageSettings.Width = 500; -section.PageSettings.Height = 200; + //Create page settings to the section. + section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180; + section.PageSettings.Width = 500; + section.PageSettings.Height = 200; -//Add page to the section and initialize graphics for the page. -page = section.Pages.Add(); -graphics = page.Graphics; + //Add page to the section and initialize graphics for the page. + page = section.Pages.Add(); + graphics = page.Graphics; -//Draw simple text on the page. -graphics.DrawString("Rotated by 180 degrees", font, brush, new PointF(20, 20)); + //Draw simple text on the page. + graphics.DrawString("Rotated by 180 degrees", font, brush, new PointF(20, 20)); -//Section - 4 -//Add new section to the document. -section = document.Sections.Add(); + //Section - 4 + //Add new section to the document. + section = document.Sections.Add(); -//Create page settings to the section. -section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle270; -section.PageSettings.Width = 300; -section.PageSettings.Height = 200; + //Create page settings to the section. + section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle270; + section.PageSettings.Width = 300; + section.PageSettings.Height = 200; -//Add page to the section and initialize graphics for the page. -page = section.Pages.Add(); -graphics = page.Graphics; + //Add page to the section and initialize graphics for the page. + page = section.Pages.Add(); + graphics = page.Graphics; -//Draw simple text on the page. -graphics.DrawString("Rotated by 270 degrees", font, brush, new PointF(20, 20)); + //Draw simple text on the page. + graphics.DrawString("Rotated by 270 degrees", font, brush, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Pages/Changing-page-numbers-in-a-PDF-document/.NET/Changing-page-numbers-in-a-PDF-document/Program.cs b/Pages/Changing-page-numbers-in-a-PDF-document/.NET/Changing-page-numbers-in-a-PDF-document/Program.cs index 982a2fb6..e42ba1d7 100644 --- a/Pages/Changing-page-numbers-in-a-PDF-document/.NET/Changing-page-numbers-in-a-PDF-document/Program.cs +++ b/Pages/Changing-page-numbers-in-a-PDF-document/.NET/Changing-page-numbers-in-a-PDF-document/Program.cs @@ -1,32 +1,21 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get file stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Create a page label. -PdfPageLabel pageLabel = new PdfPageLabel(); - -//Set the number style with upper case roman letters. -pageLabel.NumberStyle = PdfNumberStyle.UpperRoman; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create a page label. + PdfPageLabel pageLabel = new PdfPageLabel(); -//Set the staring number as 1. -pageLabel.StartNumber = 1; + //Set the number style with upper case roman letters. + pageLabel.NumberStyle = PdfNumberStyle.UpperRoman; -//Set the page label to PDF document. -loadedDocument.LoadedPageLabel = pageLabel; + //Set the staring number as 1. + pageLabel.StartNumber = 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. - loadedDocument.Save(outputFileStream); -} + //Set the page label to PDF document. + loadedDocument.LoadedPageLabel = pageLabel; -//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/Pages/Detect-empty-pages-from-PDF/.NET/Detect-empty-pages-from-PDF/Program.cs b/Pages/Detect-empty-pages-from-PDF/.NET/Detect-empty-pages-from-PDF/Program.cs index 20c73b4d..7f9f7398 100644 --- a/Pages/Detect-empty-pages-from-PDF/.NET/Detect-empty-pages-from-PDF/Program.cs +++ b/Pages/Detect-empty-pages-from-PDF/.NET/Detect-empty-pages-from-PDF/Program.cs @@ -1,30 +1,23 @@ -// 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 inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Gets the page. -PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; - -//Get the page is blank or not. -bool isEmpty = loadedPage.IsBlank; - -//Check whether page is blank or not. -if (isEmpty) -{ - Console.WriteLine("The page is blank"); -} -else +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) { - Console.WriteLine("The page is not blank"); + //Gets the page. + PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; + + //Get the page is blank or not. + bool isEmpty = loadedPage.IsBlank; + + //Check whether page is blank or not. + if (isEmpty) + { + Console.WriteLine("The page is blank"); + } + else + { + Console.WriteLine("The page is not blank"); + } } -//Close the document. -loadedDocument.Close(true); - diff --git a/Pages/Get-number-of-pages-from-PDF-document/.NET/Get-number-of-pages-from-PDF-document/Program.cs b/Pages/Get-number-of-pages-from-PDF-document/.NET/Get-number-of-pages-from-PDF-document/Program.cs index d97e95e3..27076fb7 100644 --- a/Pages/Get-number-of-pages-from-PDF-document/.NET/Get-number-of-pages-from-PDF-document/Program.cs +++ b/Pages/Get-number-of-pages-from-PDF-document/.NET/Get-number-of-pages-from-PDF-document/Program.cs @@ -1,19 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -using Syncfusion.Pdf.Parsing; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page count. + int pageCount = loadedDocument.Pages.Count; -//Get stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Get the page count. -int pageCount = loadedDocument.Pages.Count; - -//Close the document. -loadedDocument.Close(true); - -//Write the number of pages in a PDF document in console window. -Console.WriteLine("Number of pages in the PDF document is " + pageCount); -Console.ReadLine(); \ No newline at end of file + //Write the number of pages in a PDF document in console window. + Console.WriteLine("Number of pages in the PDF document is " + pageCount); +} \ No newline at end of file diff --git a/Pages/Import-pages-from-PDF-without-bookmarks/.NET/Import-pages-from-PDF-without-bookmarks/Program.cs b/Pages/Import-pages-from-PDF-without-bookmarks/.NET/Import-pages-from-PDF-without-bookmarks/Program.cs index 36371b04..8b479c2c 100644 --- a/Pages/Import-pages-from-PDF-without-bookmarks/.NET/Import-pages-from-PDF-without-bookmarks/Program.cs +++ b/Pages/Import-pages-from-PDF-without-bookmarks/.NET/Import-pages-from-PDF-without-bookmarks/Program.cs @@ -1,31 +1,19 @@ -// 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 inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Create the new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the page start and end index to be imported. -int startIndex = 0; -int endIndex = loadedDocument.Pages.Count - 1; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create the new PDF document. + PdfDocument document = new PdfDocument(); -//Import all the pages to the new PDF document without bookmarks. -document.ImportPageRange(loadedDocument, startIndex, endIndex, false); + //Set the page start and end index to be imported. + int startIndex = 0; + int endIndex = 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); -} + //Import all the pages to the new PDF document without bookmarks. + document.ImportPageRange(loadedDocument, startIndex, endIndex, false); -//Closes both document instances. -loadedDocument.Close(true); -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/Pages/Importing-pages-from-one-PDF-to-another-PDF/.NET/Importing-pages-from-one-PDF-to-another-PDF/Program.cs b/Pages/Importing-pages-from-one-PDF-to-another-PDF/.NET/Importing-pages-from-one-PDF-to-another-PDF/Program.cs index 450e678a..88beb1d1 100644 --- a/Pages/Importing-pages-from-one-PDF-to-another-PDF/.NET/Importing-pages-from-one-PDF-to-another-PDF/Program.cs +++ b/Pages/Importing-pages-from-one-PDF-to-another-PDF/.NET/Importing-pages-from-one-PDF-to-another-PDF/Program.cs @@ -1,31 +1,19 @@ -// 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 inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the page starting and end index. -int startIndex = 0; -int endIndex = loadedDocument.Pages.Count - 1; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Create a new PDF document. + PdfDocument document = new PdfDocument(); -//Import all the pages to the new PDF document. -document.ImportPageRange(loadedDocument, startIndex, endIndex); + //Set the page starting and end index. + int startIndex = 0; + int endIndex = 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); -} + //Import all the pages to the new PDF document. + document.ImportPageRange(loadedDocument, startIndex, endIndex); -//Closes both document instances. -loadedDocument.Close(true); -document.Close(true); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Pages/Insert-New-Page-in-Existing-PDF-with-Same-Size/.NET/Insert-New-Page-in-Existing-PDF-with-Same-Size/Program.cs b/Pages/Insert-New-Page-in-Existing-PDF-with-Same-Size/.NET/Insert-New-Page-in-Existing-PDF-with-Same-Size/Program.cs index 7feac55b..bde13957 100644 --- a/Pages/Insert-New-Page-in-Existing-PDF-with-Same-Size/.NET/Insert-New-Page-in-Existing-PDF-with-Same-Size/Program.cs +++ b/Pages/Insert-New-Page-in-Existing-PDF-with-Same-Size/.NET/Insert-New-Page-in-Existing-PDF-with-Same-Size/Program.cs @@ -4,10 +4,9 @@ using Syncfusion.Drawing; using System.Reflection.Metadata; -// Load the PDF document from a FileStream -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"))) { - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream); // Get the size of the first page PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; @@ -18,13 +17,6 @@ PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); // Draw the text on the page, centered page.Graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, 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. - loadedDocument.Save(outputFileStream); - } - // Close the loaded document - loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Pages/Insert-pages-in-a-PDF-document/.NET/Insert-pages-in-a-PDF-document/Program.cs b/Pages/Insert-pages-in-a-PDF-document/.NET/Insert-pages-in-a-PDF-document/Program.cs index 001e1d99..c878f0a6 100644 --- a/Pages/Insert-pages-in-a-PDF-document/.NET/Insert-pages-in-a-PDF-document/Program.cs +++ b/Pages/Insert-pages-in-a-PDF-document/.NET/Insert-pages-in-a-PDF-document/Program.cs @@ -1,22 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Insert a new page in the beginning of the document. -loadedDocument.Pages.Insert(0); - -//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. - loadedDocument.Save(outputFileStream); -} + //Insert a new page in the beginning of the document. + loadedDocument.Pages.Insert(0); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Pages/Inserting-duplicate-pages-in-the-existing-pdf/.NET/Inserting-duplicate-pages-in-the-existing-pdf/Program.cs b/Pages/Inserting-duplicate-pages-in-the-existing-pdf/.NET/Inserting-duplicate-pages-in-the-existing-pdf/Program.cs index 83150652..7fe665ef 100644 --- a/Pages/Inserting-duplicate-pages-in-the-existing-pdf/.NET/Inserting-duplicate-pages-in-the-existing-pdf/Program.cs +++ b/Pages/Inserting-duplicate-pages-in-the-existing-pdf/.NET/Inserting-duplicate-pages-in-the-existing-pdf/Program.cs @@ -1,30 +1,14 @@  using Syncfusion.Pdf; 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); - -//Gets the page - -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Inserts the duplicate page in the beginning of the document. - -loadedDocument.Pages.Insert(0, loadedPage); - - - -//Creating the stream object. - -MemoryStream stream = new MemoryStream(); - -//Save the document as stream. - -loadedDocument.Save(stream); - -File.WriteAllBytes(Path.GetFullPath("Output/Output.pdf"), stream.ToArray()); -//Close the document. - -loadedDocument.Close(true); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the page + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; + //Inserts the duplicate page in the beginning of the document. + loadedDocument.Pages.Insert(0, loadedPage); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Pages/Rearrange-pages-in-an-existing-PDF-document/.NET/Rearrange-pages-in-an-existing-PDF-document/Program.cs b/Pages/Rearrange-pages-in-an-existing-PDF-document/.NET/Rearrange-pages-in-an-existing-PDF-document/Program.cs index 19d49eec..8ce57dfa 100644 --- a/Pages/Rearrange-pages-in-an-existing-PDF-document/.NET/Rearrange-pages-in-an-existing-PDF-document/Program.cs +++ b/Pages/Rearrange-pages-in-an-existing-PDF-document/.NET/Rearrange-pages-in-an-existing-PDF-document/Program.cs @@ -1,22 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Rearrange the page by index. -loadedDocument.Pages.ReArrange(new int[] { 1, 0 }); - -//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. - loadedDocument.Save(outputFileStream); -} + //Rearrange the page by index. + loadedDocument.Pages.ReArrange(new int[] { 1, 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/Pages/Remove-pages-from-the-existing-PDF-document/.NET/Remove-pages-from-the-existing-PDF-document/Program.cs b/Pages/Remove-pages-from-the-existing-PDF-document/.NET/Remove-pages-from-the-existing-PDF-document/Program.cs index 88d593c3..123200d7 100644 --- a/Pages/Remove-pages-from-the-existing-PDF-document/.NET/Remove-pages-from-the-existing-PDF-document/Program.cs +++ b/Pages/Remove-pages-from-the-existing-PDF-document/.NET/Remove-pages-from-the-existing-PDF-document/Program.cs @@ -1,22 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -using Syncfusion.Pdf.Parsing; - -//Get stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Remove the first page in the PDF document. -loadedDocument.Pages.RemoveAt(0); - -//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. - loadedDocument.Save(outputFileStream); -} + //Remove the first page in the PDF document. + loadedDocument.Pages.RemoveAt(0); -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Pages/Rotate-an-existing-PDF-page/.NET/Rotate-an-existing-PDF-page/Program.cs b/Pages/Rotate-an-existing-PDF-page/.NET/Rotate-an-existing-PDF-page/Program.cs index efa568cb..89cea9fc 100644 --- a/Pages/Rotate-an-existing-PDF-page/.NET/Rotate-an-existing-PDF-page/Program.cs +++ b/Pages/Rotate-an-existing-PDF-page/.NET/Rotate-an-existing-PDF-page/Program.cs @@ -1,26 +1,15 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -//Get file stream from an existing PDF document. -FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream); - -//Gets the page. -PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Gets the page. + PdfPageBase loadedPage = loadedDocument.Pages[0] as PdfPageBase; -//Set the rotation for loaded page. -loadedPage.Rotation = PdfPageRotateAngle.RotateAngle90; + //Set the rotation for loaded page. + loadedPage.Rotation = PdfPageRotateAngle.RotateAngle90; -//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/Pages/Rotating-a-PDF-page/.NET/Rotating-a-PDF-page/Program.cs b/Pages/Rotating-a-PDF-page/.NET/Rotating-a-PDF-page/Program.cs index 653787ca..d34c7a95 100644 --- a/Pages/Rotating-a-PDF-page/.NET/Rotating-a-PDF-page/Program.cs +++ b/Pages/Rotating-a-PDF-page/.NET/Rotating-a-PDF-page/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(); - -//Add a section. -PdfSection section = document.Sections.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a section. + PdfSection section = document.Sections.Add(); -//Rotate a section/page to 90 degree. -section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; + //Rotate a section/page to 90 degree. + section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90; -//Add page to the section. -PdfPage page = section.Pages.Add(); + //Add page to the section. + PdfPage page = section.Pages.Add(); -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Create a solid brush. -PdfBrush brush = new PdfSolidBrush(Color.Black); + //Create a solid brush. + PdfBrush brush = new PdfSolidBrush(Color.Black); -//Set the font. -PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); + //Set the font. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); -//Draws the text. -graphics.DrawString("Rotated by 90 degree", font, brush, new PointF(20, 20)); + //Draws the text. + graphics.DrawString("Rotated by 90 degree", font, brush, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Pages/Setting-Section-Page-Numbers-With-Custom-Styles/.NET/Setting-Section-Page-Numbers-With-Custom-Styles/Program.cs b/Pages/Setting-Section-Page-Numbers-With-Custom-Styles/.NET/Setting-Section-Page-Numbers-With-Custom-Styles/Program.cs index 9126dbb6..47eb5e3e 100644 --- a/Pages/Setting-Section-Page-Numbers-With-Custom-Styles/.NET/Setting-Section-Page-Numbers-With-Custom-Styles/Program.cs +++ b/Pages/Setting-Section-Page-Numbers-With-Custom-Styles/.NET/Setting-Section-Page-Numbers-With-Custom-Styles/Program.cs @@ -2,54 +2,42 @@ using Syncfusion.Pdf.Graphics; using Syncfusion.Drawing; -class Program +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - static void Main(string[] args) - { - //Create a new document. - PdfDocument document = new PdfDocument(); - - //Add a section to the document. - PdfSection section = document.Sections.Add(); - - //Set the font for the page number. - PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + //Add a section to the document. + PdfSection section = document.Sections.Add(); - //Create a section page number field. - PdfSectionPageNumberField sectionPageNumber = new PdfSectionPageNumberField(); + //Set the font for the page number. + PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); - //Set the page number style to LowerRoman (i, ii, iii, etc.). - sectionPageNumber.NumberStyle = PdfNumberStyle.LowerRoman; - sectionPageNumber.Font = font; + //Create a section page number field. + PdfSectionPageNumberField sectionPageNumber = new PdfSectionPageNumberField(); - //Add pages to the section and draw the page number field in the footer. - for (int i = 0; i < 3; i++) - { - //Add a new page to the section. - PdfPage page = section.Pages.Add(); + //Set the page number style to LowerRoman (i, ii, iii, etc.). + sectionPageNumber.NumberStyle = PdfNumberStyle.LowerRoman; + sectionPageNumber.Font = font; - //Get the page's client size to calculate the footer position. - SizeF pageSize = page.GetClientSize(); - - //Define the position for the page number in the footer (bottom-right). - PointF footerPosition = new PointF(pageSize.Width - 50, pageSize.Height - 20); + //Add pages to the section and draw the page number field in the footer. + for (int i = 0; i < 3; i++) + { + //Add a new page to the section. + PdfPage page = section.Pages.Add(); - //Draw the section page number at the calculated footer position. - sectionPageNumber.Draw(page.Graphics, footerPosition); + //Get the page's client size to calculate the footer position. + SizeF pageSize = page.GetClientSize(); - // You can add other content to the main body of the page here. - // For example, let's draw text at the top, leaving space for the footer. - page.Graphics.DrawString("This is the main content of a page with a footer.", font, PdfBrushes.Black, new PointF(10, 10)); - } + //Define the position for the page number in the footer (bottom-right). + PointF footerPosition = new PointF(pageSize.Width - 50, pageSize.Height - 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 the section page number at the calculated footer position. + sectionPageNumber.Draw(page.Graphics, footerPosition); - //Close the document. - document.Close(true); + // You can add other content to the main body of the page here. + // For example, let's draw text at the top, leaving space for the footer. + page.Graphics.DrawString("This is the main content of a page with a footer.", font, PdfBrushes.Black, new PointF(10, 10)); } + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Pages/Span-text-element-to-multiple-pages-in-a-PDF/.NET/Span-text-element-to-multiple-pages-in-a-PDF/Program.cs b/Pages/Span-text-element-to-multiple-pages-in-a-PDF/.NET/Span-text-element-to-multiple-pages-in-a-PDF/Program.cs index e0c5a802..4a618752 100644 --- a/Pages/Span-text-element-to-multiple-pages-in-a-PDF/.NET/Span-text-element-to-multiple-pages-in-a-PDF/Program.cs +++ b/Pages/Span-text-element-to-multiple-pages-in-a-PDF/.NET/Span-text-element-to-multiple-pages-in-a-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.Graphics; using System.Text; @@ -38,12 +36,8 @@ //Draw the second paragraph from the first paragraph’s end position. result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom + paragraphGap, page.GetClientSize().Width / 2, page.GetClientSize().Height), 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/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs index fd9d340b..83c98267 100644 --- a/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs +++ b/Pages/Splitting-PDF-file-into-individual-pages/.NET/Splitting-PDF-file-into-individual-pages/Program.cs @@ -1,30 +1,19 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; -// Create the FileStream object to read the input PDF file -using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +//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)) + // Iterate over the pages of the loaded document + for (int pageIndex = 0; pageIndex < loadedDocument.PageCount; pageIndex++) { - // Iterate over the pages of the loaded document - for (int pageIndex = 0; pageIndex < loadedDocument.PageCount; pageIndex++) + // Create a new PdfDocument object to hold the output + using (PdfDocument outputDocument = new PdfDocument()) { - // Create a new PdfDocument object to hold the output - using (PdfDocument outputDocument = new PdfDocument()) - { - // Import the page from the loadedDocument to the outputDocument - outputDocument.ImportPage(loadedDocument, pageIndex); - - // Create the FileStream object to write the output PDF file - using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/" + pageIndex + ".pdf"), FileMode.Create, FileAccess.Write)) - { - // Save the outputDocument into the outputFileStream - outputDocument.Save(outputFileStream); - } - } + // Import the page from the loadedDocument to the outputDocument + outputDocument.ImportPage(loadedDocument, pageIndex); + //Save the PDF document + outputDocument.Save(Path.GetFullPath(@"Output/" + pageIndex + ".pdf")); } } } \ No newline at end of file diff --git a/Portfolio/Create-a-portfolio-and-attach-variety-of-documents/.NET/Create-a-portfolio-and-attach-variety-of-documents/Program.cs b/Portfolio/Create-a-portfolio-and-attach-variety-of-documents/.NET/Create-a-portfolio-and-attach-variety-of-documents/Program.cs index f1e15b01..14d980d7 100644 --- a/Portfolio/Create-a-portfolio-and-attach-variety-of-documents/.NET/Create-a-portfolio-and-attach-variety-of-documents/Program.cs +++ b/Portfolio/Create-a-portfolio-and-attach-variety-of-documents/.NET/Create-a-portfolio-and-attach-variety-of-documents/Program.cs @@ -1,38 +1,29 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; -//Create a new instance of PdfDocument class. -PdfDocument document = new PdfDocument(); - -//Create a new portfolio. -document.PortfolioInformation = new PdfPortfolioInformation(); - -//Set the view mode of the portfolio. -document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile; - -//Get stream from the attachment PDF file. -FileStream pdfStream = new FileStream(Path.GetFullPath(@"Data/CorporateBrochure.pdf"), FileMode.Open, FileAccess.Read); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Create a new portfolio. + document.PortfolioInformation = new PdfPortfolioInformation(); -//Create the attachment. -PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream); + //Set the view mode of the portfolio. + document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile; -//Set the file name. -pdfFile.FileName = "CorporateBrochure.pdf"; + //Get stream from the attachment PDF file. + FileStream pdfStream = new FileStream(Path.GetFullPath(@"Data/CorporateBrochure.pdf"), FileMode.Open, FileAccess.Read); -//Set the startup document to view. -document.PortfolioInformation.StartupDocument = pdfFile; + //Create the attachment. + PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream); -//Add the attachment to the document. -document.Attachments.Add(pdfFile); + //Set the file name. + pdfFile.FileName = "CorporateBrochure.pdf"; -//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 startup document to view. + document.PortfolioInformation.StartupDocument = pdfFile; -//Close the document. -document.Close(true); \ No newline at end of file + //Add the attachment to the document. + document.Attachments.Add(pdfFile); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Portfolio/Extracting-the-files-from-PDF-portfolio/.NET/Extracting-the-files-from-PDF-portfolio/Program.cs b/Portfolio/Extracting-the-files-from-PDF-portfolio/.NET/Extracting-the-files-from-PDF-portfolio/Program.cs index 8e9e4604..a58b3610 100644 --- a/Portfolio/Extracting-the-files-from-PDF-portfolio/.NET/Extracting-the-files-from-PDF-portfolio/Program.cs +++ b/Portfolio/Extracting-the-files-from-PDF-portfolio/.NET/Extracting-the-files-from-PDF-portfolio/Program.cs @@ -1,13 +1,8 @@ -// 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); +PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); string outputFileName = ""; @@ -21,13 +16,7 @@ outputFileName = attachment.FileName; } - -//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/Portfolio/Remove-the-files-from-PDF-portfolio/.NET/Remove-the-files-from-PDF-portfolio/Program.cs b/Portfolio/Remove-the-files-from-PDF-portfolio/.NET/Remove-the-files-from-PDF-portfolio/Program.cs index 2fd660b8..8e531a47 100644 --- a/Portfolio/Remove-the-files-from-PDF-portfolio/.NET/Remove-the-files-from-PDF-portfolio/Program.cs +++ b/Portfolio/Remove-the-files-from-PDF-portfolio/.NET/Remove-the-files-from-PDF-portfolio/Program.cs @@ -1,22 +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/Sample.pdf"), FileMode.Open, FileAccess.Read); +using Syncfusion.Pdf.Parsing; //Load the PDF document. -PdfLoadedDocument document = new PdfLoadedDocument(docStream); - -//Remove the file from the Portfolio. -document.Attachments.RemoveAt(0); - -//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/Sample.pdf"))) { - //Save the PDF document to file stream. - document.Save(outputFileStream); -} + //Remove the file from the Portfolio. + loadedDocument.Attachments.RemoveAt(0); -//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/Security/Change-password-of-the-PDF-document/.NET/Change-password-of-the-PDF-document/Program.cs b/Security/Change-password-of-the-PDF-document/.NET/Change-password-of-the-PDF-document/Program.cs index 5166af02..fc4920bc 100644 --- a/Security/Change-password-of-the-PDF-document/.NET/Change-password-of-the-PDF-document/Program.cs +++ b/Security/Change-password-of-the-PDF-document/.NET/Change-password-of-the-PDF-document/Program.cs @@ -1,22 +1,13 @@ -// See https://aka.ms/new-console-template for more information - -//Get stream from an existing PDF document. -using Syncfusion.Pdf.Parsing; - -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, "password"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"), "password"); //Change the user password . loadedDocument.Security.UserPassword = "NewPassword"; -//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/Security/Change-the-permission-of-the-PDF-document/.NET/Change-the-permission-of-the-PDF-document/Program.cs b/Security/Change-the-permission-of-the-PDF-document/.NET/Change-the-permission-of-the-PDF-document/Program.cs index 9c33f4d0..850fe149 100644 --- a/Security/Change-the-permission-of-the-PDF-document/.NET/Change-the-permission-of-the-PDF-document/Program.cs +++ b/Security/Change-the-permission-of-the-PDF-document/.NET/Change-the-permission-of-the-PDF-document/Program.cs @@ -1,23 +1,14 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; -//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, "syncfusion"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"), "syncfusion"); //Change the permission. loadedDocument.Security.Permissions = PdfPermissionsFlags.CopyContent | PdfPermissionsFlags.AssembleDocument; -//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/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs index 8d969eb5..f63c0d74 100644 --- a/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs +++ b/Security/Decrypting-encrypted-PDF-document/.NET/Decrypting-encrypted-PDF-document/Program.cs @@ -4,10 +4,8 @@ using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; -using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read)) -{ - // Load the encrypted PDF document from the input stream - PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream, "syncfusion"); + // Load the encrypted PDF document + PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"), "syncfusion"); // Set the document permissions to default (removes any restrictions) loadedDocument.Security.Permissions = PdfPermissionsFlags.Default; @@ -16,11 +14,7 @@ loadedDocument.Security.OwnerPassword = string.Empty; loadedDocument.Security.UserPassword = string.Empty; - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) - { - // Save the decrypted PDF document to the output stream - loadedDocument.Save(outputStream); - } - // Close the loaded PDF document and release resources + // Save the decrypted PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); + // Close the loaded PDF document loadedDocument.Close(true); -} diff --git a/Security/Determine-whether-the-PDF-is-protected-or-not/.NET/Determine-whether-the-PDF-is-protected-or-not/Program.cs b/Security/Determine-whether-the-PDF-is-protected-or-not/.NET/Determine-whether-the-PDF-is-protected-or-not/Program.cs index a1ea7de7..c14fc7c6 100644 --- a/Security/Determine-whether-the-PDF-is-protected-or-not/.NET/Determine-whether-the-PDF-is-protected-or-not/Program.cs +++ b/Security/Determine-whether-the-PDF-is-protected-or-not/.NET/Determine-whether-the-PDF-is-protected-or-not/Program.cs @@ -1,15 +1,10 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Parsing; try { - //Get stream from an existing 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")); //Write whether document is protected or not in console window. Console.WriteLine("The PDF document is password protected one"); @@ -22,5 +17,4 @@ Console.WriteLine("Cannot open an encrypted document without password"); } } - Console.ReadLine(); \ No newline at end of file diff --git a/Security/Encrypt-PDF-with-AES-using-owner-password/.NET/Encrypt-PDF-with-AES-using-owner-password/Program.cs b/Security/Encrypt-PDF-with-AES-using-owner-password/.NET/Encrypt-PDF-with-AES-using-owner-password/Program.cs index c302f119..a99591a1 100644 --- a/Security/Encrypt-PDF-with-AES-using-owner-password/.NET/Encrypt-PDF-with-AES-using-owner-password/Program.cs +++ b/Security/Encrypt-PDF-with-AES-using-owner-password/.NET/Encrypt-PDF-with-AES-using-owner-password/Program.cs @@ -1,48 +1,39 @@ -// 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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Document security. -PdfSecurity security = document.Security; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; + //Document security. + PdfSecurity security = document.Security; -//Set the owner password for security. -security.OwnerPassword = "syncfusion"; + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; -//It allows printing and accessibility copy content. -security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.AccessibilityCopyContent; -security.UserPassword = "password"; + //Set the owner password for security. + security.OwnerPassword = "syncfusion"; -//Draw the text. -graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); + //It allows printing and accessibility copy content. + security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.AccessibilityCopyContent; + security.UserPassword = "password"; -//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 text. + graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Security/Encrypt-PDF-with-AES-using-user-password/.NET/Encrypt-PDF-with-AES-using-user-password/Program.cs b/Security/Encrypt-PDF-with-AES-using-user-password/.NET/Encrypt-PDF-with-AES-using-user-password/Program.cs index 4dc6cfdb..47284f35 100644 --- a/Security/Encrypt-PDF-with-AES-using-user-password/.NET/Encrypt-PDF-with-AES-using-user-password/Program.cs +++ b/Security/Encrypt-PDF-with-AES-using-user-password/.NET/Encrypt-PDF-with-AES-using-user-password/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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Document security. -PdfSecurity security = document.Security; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; -security.UserPassword = "password"; + //Document security. + PdfSecurity security = document.Security; -//Draw the text. -graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; + security.UserPassword = "password"; -//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 text. + graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Security/Encrypt-PDF-with-RC4-using-owner-password/.NET/Encrypt-PDF-with-RC4-using-owner-password/Program.cs b/Security/Encrypt-PDF-with-RC4-using-owner-password/.NET/Encrypt-PDF-with-RC4-using-owner-password/Program.cs index 39302934..4aea1b0f 100644 --- a/Security/Encrypt-PDF-with-RC4-using-owner-password/.NET/Encrypt-PDF-with-RC4-using-owner-password/Program.cs +++ b/Security/Encrypt-PDF-with-RC4-using-owner-password/.NET/Encrypt-PDF-with-RC4-using-owner-password/Program.cs @@ -1,44 +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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics to the document. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Create PDF graphics to the document. + PdfGraphics graphics = page.Graphics; -//Document security. -PdfSecurity security = document.Security; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key128Bit; -security.Algorithm = PdfEncryptionAlgorithm.RC4; -security.OwnerPassword = "syncfusion"; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//It allows printing and accessibility copy content. -security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.AccessibilityCopyContent; -security.UserPassword = "password"; -graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); + //Document security. + PdfSecurity security = document.Security; -//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); -} + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key128Bit; + security.Algorithm = PdfEncryptionAlgorithm.RC4; + security.OwnerPassword = "syncfusion"; -//Close the document. -document.Close(true); \ No newline at end of file + //It allows printing and accessibility copy content. + security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.AccessibilityCopyContent; + security.UserPassword = "password"; + graphics.DrawString("This document is protected with owner password", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Security/Encrypt-PDF-with-RC4-using-user-password/.NET/Encrypt-PDF-with-RC4-using-user-password/Program.cs b/Security/Encrypt-PDF-with-RC4-using-user-password/.NET/Encrypt-PDF-with-RC4-using-user-password/Program.cs index 3ee9e9e5..0bfd924c 100644 --- a/Security/Encrypt-PDF-with-RC4-using-user-password/.NET/Encrypt-PDF-with-RC4-using-user-password/Program.cs +++ b/Security/Encrypt-PDF-with-RC4-using-user-password/.NET/Encrypt-PDF-with-RC4-using-user-password/Program.cs @@ -1,42 +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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Document security. -PdfSecurity security = document.Security; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key128Bit; -security.Algorithm = PdfEncryptionAlgorithm.RC4; -security.UserPassword = "password"; + //Document security. + PdfSecurity security = document.Security; -//Draw the text. -graphics.DrawString("Encrypted with RC4 128bit", font, brush, new PointF(0, 40)); + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key128Bit; + security.Algorithm = PdfEncryptionAlgorithm.RC4; + security.UserPassword = "password"; -//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 text. + graphics.DrawString("Encrypted with RC4 128bit", font, brush, new PointF(0, 40)); + //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/Security/Encrypt-all-contents-except-metadata-of-the-PDF/.NET/Encrypt-all-contents-except-metadata-of-the-PDF/Program.cs b/Security/Encrypt-all-contents-except-metadata-of-the-PDF/.NET/Encrypt-all-contents-except-metadata-of-the-PDF/Program.cs index 675b7b8e..e38c1fde 100644 --- a/Security/Encrypt-all-contents-except-metadata-of-the-PDF/.NET/Encrypt-all-contents-except-metadata-of-the-PDF/Program.cs +++ b/Security/Encrypt-all-contents-except-metadata-of-the-PDF/.NET/Encrypt-all-contents-except-metadata-of-the-PDF/Program.cs @@ -1,45 +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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Document security. -PdfSecurity security = document.Security; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; + //Document security. + PdfSecurity security = document.Security; -//Specifies encryption option. -security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata; -security.UserPassword = "password"; + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; -//Draw the text. -graphics.DrawString("Encrypted all contents except metadata with AES 256bit", font, brush, new PointF(0, 40)); + //Specifies encryption option. + security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata; + security.UserPassword = "password"; -//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 text. + graphics.DrawString("Encrypted all contents except metadata with AES 256bit", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Security/Encrypt-all-contents-of-the-PDF-document/.NET/Encrypt-all-contents-of-the-PDF-document/Program.cs b/Security/Encrypt-all-contents-of-the-PDF-document/.NET/Encrypt-all-contents-of-the-PDF-document/Program.cs index d18b247c..db01e9c9 100644 --- a/Security/Encrypt-all-contents-of-the-PDF-document/.NET/Encrypt-all-contents-of-the-PDF-document/Program.cs +++ b/Security/Encrypt-all-contents-of-the-PDF-document/.NET/Encrypt-all-contents-of-the-PDF-document/Program.cs @@ -1,45 +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.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; - -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Document security. -PdfSecurity security = document.Security; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies encryption option. -security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents; -security.UserPassword = "password"; + //Document security. + PdfSecurity security = document.Security; -//Draw the text. -graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; -//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); -} + //Specifies encryption option. + security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents; + security.UserPassword = "password"; -//Close the document. -document.Close(true); \ No newline at end of file + //Draw the text. + graphics.DrawString("Encrypted with AES 256bit", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Security/Encrypt-only-attachment-in-the-PDF-document/.NET/Encrypt-only-attachment-in-the-PDF-document/Program.cs b/Security/Encrypt-only-attachment-in-the-PDF-document/.NET/Encrypt-only-attachment-in-the-PDF-document/Program.cs index d5498f78..ad3e92b3 100644 --- a/Security/Encrypt-only-attachment-in-the-PDF-document/.NET/Encrypt-only-attachment-in-the-PDF-document/Program.cs +++ b/Security/Encrypt-only-attachment-in-the-PDF-document/.NET/Encrypt-only-attachment-in-the-PDF-document/Program.cs @@ -1,56 +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; using Syncfusion.Pdf.Security; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; - -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document. + PdfPage page = document.Pages.Add(); -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Document security. -PdfSecurity security = document.Security; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Specifies encryption option. -security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; -security.UserPassword = "password"; + //Document security. + PdfSecurity security = document.Security; -//Draw the text. -graphics.DrawString("Encrypted only attachments with AES 256bit", font, brush, new PointF(0, 40)); + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; -//Creates an attachment. -FileStream textFileStream = new FileStream(Path.GetFullPath(@"Data/input.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -PdfAttachment attachment = new PdfAttachment("input.txt", textFileStream); -attachment.ModificationDate = DateTime.Now; -attachment.Description = "Input.txt"; -attachment.MimeType = "application/txt"; + //Specifies encryption option. + security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; + security.UserPassword = "password"; -//Add the attachment to the document. -document.Attachments.Add(attachment); + //Draw the text. + graphics.DrawString("Encrypted only attachments with AES 256bit", font, brush, new PointF(0, 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. - document.Save(outputFileStream); -} + //Creates an attachment. + FileStream textFileStream = new FileStream(Path.GetFullPath(@"Data/input.txt"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + PdfAttachment attachment = new PdfAttachment("input.txt", textFileStream); + attachment.ModificationDate = DateTime.Now; + attachment.Description = "Input.txt"; + attachment.MimeType = "application/txt"; -//Close the document. -document.Close(true); \ No newline at end of file + //Add the attachment to the document. + document.Attachments.Add(attachment); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Security/Load-an-encrypt-only-attachment-document/.NET/Load-an-encrypt-only-attachment-document/Program.cs b/Security/Load-an-encrypt-only-attachment-document/.NET/Load-an-encrypt-only-attachment-document/Program.cs index c3335fd4..4b848287 100644 --- a/Security/Load-an-encrypt-only-attachment-document/.NET/Load-an-encrypt-only-attachment-document/Program.cs +++ b/Security/Load-an-encrypt-only-attachment-document/.NET/Load-an-encrypt-only-attachment-document/Program.cs @@ -1,13 +1,8 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Interactive; +using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing; -//Get the 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, "password"); +PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"), "password"); //Accessing the attachments. foreach (PdfAttachment attachment in document.Attachments) diff --git a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs index cac0bb52..420c453b 100644 --- a/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs +++ b/Security/Protect-an-existing-PDF-document/.NET/Protect-an-existing-PDF-document/Program.cs @@ -1,16 +1,11 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; -// Load the PDF document from a file stream -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 - PdfLoadedDocument document = new PdfLoadedDocument(inputFileStream); - - // Gets a security object for the document - PdfSecurity security = document.Security; + //Gets a security object for the document + PdfSecurity security = loadedDocument.Security; // Configure key size and encryption algorithm security.KeySize = PdfEncryptionKeySize.Key256Bit; @@ -19,14 +14,7 @@ // Assign owner and user passwords security.OwnerPassword = "owner123"; security.UserPassword = "user123"; - - //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); + + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Security/Protect-attachments-in-existing-PDF-document/.NET/Protect-attachments-in-existing-PDF-document/Program.cs b/Security/Protect-attachments-in-existing-PDF-document/.NET/Protect-attachments-in-existing-PDF-document/Program.cs index 4d84e4ca..faa08029 100644 --- a/Security/Protect-attachments-in-existing-PDF-document/.NET/Protect-attachments-in-existing-PDF-document/Program.cs +++ b/Security/Protect-attachments-in-existing-PDF-document/.NET/Protect-attachments-in-existing-PDF-document/Program.cs @@ -1,33 +1,22 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; -//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); - -//PDF document security. -PdfSecurity security = document.Security; +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //PDF document security. + PdfSecurity security = loadedDocument.Security; -//Specifies encryption key size, algorithm and permission. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AES; + //Specifies encryption key size, algorithm and permission. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AES; -//Provide user password. -security.UserPassword = "password"; + //Provide user password. + security.UserPassword = "password"; -//Specifies encryption option. -security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; + //Specifies encryption option. + security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; -//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/Security/Remove-password-from-user-password-PDF-document/.NET/Remove-password-from-user-password-PDF-document/Program.cs b/Security/Remove-password-from-user-password-PDF-document/.NET/Remove-password-from-user-password-PDF-document/Program.cs index 87601011..19c6685d 100644 --- a/Security/Remove-password-from-user-password-PDF-document/.NET/Remove-password-from-user-password-PDF-document/Program.cs +++ b/Security/Remove-password-from-user-password-PDF-document/.NET/Remove-password-from-user-password-PDF-document/Program.cs @@ -1,22 +1,11 @@ -// See https://aka.ms/new-console-template for more information +using Syncfusion.Pdf.Parsing; -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, "password"); - -//Change the user password. -loadedDocument.Security.UserPassword = string.Empty; - -//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. - loadedDocument.Save(outputFileStream); -} + //Change the user password. + loadedDocument.Security.UserPassword = string.Empty; -//Close the document. -loadedDocument.Close(true); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} diff --git a/Security/Secure_data _with _AES_GCM/.NET/Secure_data _with _AES_GCM/Program.cs b/Security/Secure_data _with _AES_GCM/.NET/Secure_data _with _AES_GCM/Program.cs index 83ed0bc8..609de813 100644 --- a/Security/Secure_data _with _AES_GCM/.NET/Secure_data _with _AES_GCM/Program.cs +++ b/Security/Secure_data _with _AES_GCM/.NET/Secure_data _with _AES_GCM/Program.cs @@ -3,42 +3,35 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -//Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Set the document version as 2.0 -document.FileStructure.Version = PdfVersion.Version2_0; - -//Add a page to the document. -PdfPage page = document.Pages.Add(); - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Set the document version as 2.0 + document.FileStructure.Version = PdfVersion.Version2_0; -//Set the font. -PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Bold); + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the brush. -PdfBrush brush = PdfBrushes.Black; + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Document security. -PdfSecurity security = document.Security; + //Set the font. + PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Bold); -//Specifies key size and encryption algorithm. -security.KeySize = PdfEncryptionKeySize.Key256Bit; -security.Algorithm = PdfEncryptionAlgorithm.AESGCM; -security.OwnerPassword = "ownerPassword"; -security.UserPassword = "userPassword"; + //Set the brush. + PdfBrush brush = PdfBrushes.Black; -//Draw the text. -graphics.DrawString("Encrypted document with AES-GCM 256bit", font, brush, new PointF(0, 40)); + //Document security. + PdfSecurity security = document.Security; -//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); -} + //Specifies key size and encryption algorithm. + security.KeySize = PdfEncryptionKeySize.Key256Bit; + security.Algorithm = PdfEncryptionAlgorithm.AESGCM; + security.OwnerPassword = "ownerPassword"; + security.UserPassword = "userPassword"; -//Close the documents. -document.Close(true); \ No newline at end of file + //Draw the text. + graphics.DrawString("Encrypted document with AES-GCM 256bit", font, brush, new PointF(0, 40)); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Security/Set-user-password-when-accessing-the-attachment/.NET/Set-user-password-when-accessing-the-attachment/Program.cs b/Security/Set-user-password-when-accessing-the-attachment/.NET/Set-user-password-when-accessing-the-attachment/Program.cs index 0a3a2bd5..b5077548 100644 --- a/Security/Set-user-password-when-accessing-the-attachment/.NET/Set-user-password-when-accessing-the-attachment/Program.cs +++ b/Security/Set-user-password-when-accessing-the-attachment/.NET/Set-user-password-when-accessing-the-attachment/Program.cs @@ -1,13 +1,8 @@ -// 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); +PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); document.OnPdfPassword += Document_OnPdfPassword; diff --git a/Security/Troubleshooting/.NET/Removing_restrictions_for_security/Program.cs b/Security/Troubleshooting/.NET/Removing_restrictions_for_security/Program.cs index 287bb607..09df12eb 100644 --- a/Security/Troubleshooting/.NET/Removing_restrictions_for_security/Program.cs +++ b/Security/Troubleshooting/.NET/Removing_restrictions_for_security/Program.cs @@ -1,11 +1,9 @@ -// Open a FileStream for reading the PDF file. -using Syncfusion.Pdf.Parsing; +using Syncfusion.Pdf.Parsing; using Syncfusion.Pdf.Security; using System.Security.Cryptography; -FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/OwnerPasswordOnly.pdf"), FileMode.Open, FileAccess.Read); // Load the PDF document from the FileStream with the specified owner password. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream, "12345"); +PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/OwnerPasswordOnly.pdf"), "12345"); // Access the security settings of the loaded PDF document. PdfSecurity security = loadedDocument.Security; // Disable incremental update for the file structure. @@ -16,11 +14,8 @@ security.Algorithm = PdfEncryptionAlgorithm.AES; // Set the encryption key size to 256 Bit. security.KeySize = PdfEncryptionKeySize.Key256Bit; -// Create a MemoryStream to store the modified PDF document. -MemoryStream stream = new MemoryStream(); -// Save the modified PDF document to the MemoryStream. -loadedDocument.Save(stream); + +// Save the modified PDF document +loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); // Close the loaded PDF document. loadedDocument.Close(true); -// Write the contents of the MemoryStream. -File.WriteAllBytes((@"Output/Output.pdf"), stream.ToArray()); diff --git a/Shapes/Dash-pattern-in-shapes/.NET/Dash-pattern-in-shapes/Program.cs b/Shapes/Dash-pattern-in-shapes/.NET/Dash-pattern-in-shapes/Program.cs index 0c602104..f746cb2e 100644 --- a/Shapes/Dash-pattern-in-shapes/.NET/Dash-pattern-in-shapes/Program.cs +++ b/Shapes/Dash-pattern-in-shapes/.NET/Dash-pattern-in-shapes/Program.cs @@ -2,33 +2,28 @@ 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 PdfGraphics object to draw on the page -PdfGraphics graphics = page.Graphics; + // Create a PdfGraphics object to draw on the page + PdfGraphics graphics = page.Graphics; -// Create a custom dashed line pattern (5-point dash, 2-point gap) -float[] dashPattern = { 5, 2 }; // Dash length, gap length + // Create a custom dashed line pattern (5-point dash, 2-point gap) + float[] dashPattern = { 5, 2 }; // Dash length, gap length -// Create a PdfPen with the dash pattern and color -PdfPen dashPen = new PdfPen(PdfBrushes.Black, 2); // 2 is the line width + // Create a PdfPen with the dash pattern and color + PdfPen dashPen = new PdfPen(PdfBrushes.Black, 2); // 2 is the line width -// Set the DashStyle to Custom before applying DashPattern -dashPen.DashStyle = PdfDashStyle.Custom; // Use Custom style to enable DashPattern -dashPen.DashPattern = dashPattern; + // Set the DashStyle to Custom before applying DashPattern + dashPen.DashStyle = PdfDashStyle.Custom; // Use Custom style to enable DashPattern + dashPen.DashPattern = dashPattern; -// Draw a line with the custom dash pattern -graphics.DrawLine(dashPen, new Syncfusion.Drawing.PointF(10, 10), new PointF(300, 10)); + // Draw a line with the custom dash pattern + graphics.DrawLine(dashPen, new Syncfusion.Drawing.PointF(10, 10), new PointF(300, 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); -} -//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/Shapes/Draw-a-bazier-in-an-existing-PDF-document/.NET/Draw-a-bazier-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-bazier-in-an-existing-PDF-document/.NET/Draw-a-bazier-in-an-existing-PDF-document/Program.cs index aa30d6dc..028040d5 100644 --- a/Shapes/Draw-a-bazier-in-an-existing-PDF-document/.NET/Draw-a-bazier-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-bazier-in-an-existing-PDF-document/.NET/Draw-a-bazier-in-an-existing-PDF-document/Program.cs @@ -1,31 +1,20 @@ -// 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 inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Initialize pen to draw the bezier. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); + //Initialize pen to draw the bezier. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); -//Draw the bezier on PDF document. -loadedPage.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 10)); + //Draw the bezier on PDF document. + loadedPage.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 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. - loadedDocument.Save(outputFileStream); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -loadedDocument.Close(true); diff --git a/Shapes/Draw-a-bazier-in-new-PDF-document/.NET/Draw-a-bazier-in-new-PDF-document/Program.cs b/Shapes/Draw-a-bazier-in-new-PDF-document/.NET/Draw-a-bazier-in-new-PDF-document/Program.cs index e2f60ed8..3d3af25f 100644 --- a/Shapes/Draw-a-bazier-in-new-PDF-document/.NET/Draw-a-bazier-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-a-bazier-in-new-PDF-document/.NET/Draw-a-bazier-in-new-PDF-document/Program.cs @@ -1,27 +1,19 @@ -// 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(); -//Initialize pen to draw the bezier. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); + //Initialize pen to draw the bezier. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 1f); -//Draw the bezier on PDF document. -page.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 10)); + //Draw the bezier on PDF document. + page.Graphics.DrawBezier(pen, new PointF(10, 10), new PointF(10, 50), new PointF(50, 80), new PointF(80, 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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Shapes/Draw-a-curve-in-an-existing-PDF-document/.NET/Draw-a-curve-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-curve-in-an-existing-PDF-document/.NET/Draw-a-curve-in-an-existing-PDF-document/Program.cs index fea35ace..8483648f 100644 --- a/Shapes/Draw-a-curve-in-an-existing-PDF-document/.NET/Draw-a-curve-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-curve-in-an-existing-PDF-document/.NET/Draw-a-curve-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; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing; -//Get the 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 into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Get the graphics of PdfLoadedPage. -PdfGraphics graphics = loadedPage.Graphics; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create new instance of PdfBezierCurve. -PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(100, 100)); + //Get the graphics of PdfLoadedPage. + PdfGraphics graphics = loadedPage.Graphics; -//Draw the bezier curve on PDF document. -bezier.Draw(graphics, new PointF(10, 10)); + //Create new instance of PdfBezierCurve. + PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(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. - loadedDocument.Save(outputFileStream); -} + //Draw the bezier curve on PDF document. + bezier.Draw(graphics, new PointF(10, 10)); -//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/Shapes/Draw-a-curve-in-new-PDF-document/.NET/Draw-a-curve-in-new-PDF-document/Program.cs b/Shapes/Draw-a-curve-in-new-PDF-document/.NET/Draw-a-curve-in-new-PDF-document/Program.cs index 26b9eca6..9bc18df7 100644 --- a/Shapes/Draw-a-curve-in-new-PDF-document/.NET/Draw-a-curve-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-a-curve-in-new-PDF-document/.NET/Draw-a-curve-in-new-PDF-document/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(); - -//Initialize PdfGraphics for PdfPage. -PdfGraphics graphics = page.Graphics; +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create new instance of PdfBezierCurve. -PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(100, 100)); + //Initialize PdfGraphics for PdfPage. + PdfGraphics graphics = page.Graphics; -//Draw the bezier curve on PDF document. -bezier.Draw(graphics, new PointF(10, 10)); + //Create new instance of PdfBezierCurve. + PdfBezierCurve bezier = new PdfBezierCurve(new PointF(0, 0), new PointF(100, 50), new PointF(50, 50), new PointF(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); -} + //Draw the bezier curve on PDF document. + bezier.Draw(graphics, new PointF(10, 10)); -//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/Shapes/Draw-a-line-in-an-existing-PDF-document/.NET/Draw-a-line-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-line-in-an-existing-PDF-document/.NET/Draw-a-line-in-an-existing-PDF-document/Program.cs index 623add55..035076dc 100644 --- a/Shapes/Draw-a-line-in-an-existing-PDF-document/.NET/Draw-a-line-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-line-in-an-existing-PDF-document/.NET/Draw-a-line-in-an-existing-PDF-document/Program.cs @@ -1,35 +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.Parsing; -//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 into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize pen to draw the line. -PdfPen pen = new PdfPen(PdfBrushes.Black, 5f); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Create the line points. -PointF point1 = new PointF(10, 10); -PointF point2 = new PointF(10, 100); + //Initialize pen to draw the line. + PdfPen pen = new PdfPen(PdfBrushes.Black, 5f); -//Draw the line on PDF document. -loadedPage.Graphics.DrawLine(pen, point1, point2); + //Create the line points. + PointF point1 = new PointF(10, 10); + PointF point2 = new PointF(10, 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. - loadedDocument.Save(outputFileStream); -} + //Draw the line on PDF document. + loadedPage.Graphics.DrawLine(pen, point1, point2); -//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/Shapes/Draw-a-line-in-new-PDF-document/.NET/Draw-a-line-in-new-PDF-document/Program.cs b/Shapes/Draw-a-line-in-new-PDF-document/.NET/Draw-a-line-in-new-PDF-document/Program.cs index 394c8e65..cbc5b4c9 100644 --- a/Shapes/Draw-a-line-in-new-PDF-document/.NET/Draw-a-line-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-a-line-in-new-PDF-document/.NET/Draw-a-line-in-new-PDF-document/Program.cs @@ -1,31 +1,23 @@ -// 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(); - -//Initialize pen to draw the line. -PdfPen pen = new PdfPen(PdfBrushes.Black, 5f); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Create the line points. -PointF point1 = new PointF(10, 10); -PointF point2 = new PointF(10, 100); + //Initialize pen to draw the line. + PdfPen pen = new PdfPen(PdfBrushes.Black, 5f); -//Draw the line on PDF document. -page.Graphics.DrawLine(pen, point1, point2); + //Create the line points. + PointF point1 = new PointF(10, 10); + PointF point2 = new PointF(10, 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); -} + //Draw the line on PDF document. + page.Graphics.DrawLine(pen, point1, point2); -//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/Shapes/Draw-a-pie-in-an-existing-PDF-document/.NET/Draw-a-pie-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-pie-in-an-existing-PDF-document/.NET/Draw-a-pie-in-an-existing-PDF-document/Program.cs index 5c8b8620..dc6654f3 100644 --- a/Shapes/Draw-a-pie-in-an-existing-PDF-document/.NET/Draw-a-pie-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-pie-in-an-existing-PDF-document/.NET/Draw-a-pie-in-an-existing-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.Graphics; using Syncfusion.Pdf.Parsing; -//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 into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize the pen for drawing pie. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 5f); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Set the line join style of the pen. -pen.LineJoin = PdfLineJoin.Round; + //Initialize the pen for drawing pie. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 5f); -//Set the bounds for pie. -RectangleF rectangle = new RectangleF(10, 50, 200, 200); + //Set the line join style of the pen. + pen.LineJoin = PdfLineJoin.Round; -//Draw the pie on PDF document -loadedPage.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); + //Set the bounds for pie. + RectangleF rectangle = new RectangleF(10, 50, 200, 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. - loadedDocument.Save(outputFileStream); -} + //Draw the pie on PDF document + loadedPage.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); -//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/Shapes/Draw-a-pie-in-new-PDF-document/.NET/Draw-a-pie-in-new-PDF-document/Program.cs b/Shapes/Draw-a-pie-in-new-PDF-document/.NET/Draw-a-pie-in-new-PDF-document/Program.cs index 51fe44bb..b53134ef 100644 --- a/Shapes/Draw-a-pie-in-new-PDF-document/.NET/Draw-a-pie-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-a-pie-in-new-PDF-document/.NET/Draw-a-pie-in-new-PDF-document/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(); - -//Initialize the pen for drawing pie. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 5f); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the line join style of the pen. -pen.LineJoin = PdfLineJoin.Round; + //Initialize the pen for drawing pie. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 5f); -//Set the bounds for pie. -RectangleF rectangle = new RectangleF(10, 50, 200, 200); + //Set the line join style of the pen. + pen.LineJoin = PdfLineJoin.Round; -//Draw the pie on PDF document. -page.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); + //Set the bounds for pie. + RectangleF rectangle = new RectangleF(10, 50, 200, 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); -} + //Draw the pie on PDF document. + page.Graphics.DrawPie(pen, PdfBrushes.Green, rectangle, 180, 60); -//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/Shapes/Draw-a-polygon-in-an-existing-PDF-document/.NET/Draw-a-polygon-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-polygon-in-an-existing-PDF-document/.NET/Draw-a-polygon-in-an-existing-PDF-document/Program.cs index ea1655a0..0c6a45eb 100644 --- a/Shapes/Draw-a-polygon-in-an-existing-PDF-document/.NET/Draw-a-polygon-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-polygon-in-an-existing-PDF-document/.NET/Draw-a-polygon-in-an-existing-PDF-document/Program.cs @@ -1,42 +1,31 @@ -// 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; -//Load the PDF document as stream. -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize PdfPen to draw the polygon. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 10f); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Initialize PdfLinearGradientBrush for drawing the polygon. -PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(10, 100), new PointF(100, 200), new PdfColor(Color.Red), new PdfColor(Color.Green)); + //Initialize PdfPen to draw the polygon. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 10f); -//Create the polygon points. -PointF p1 = new PointF(10, 100); -PointF p2 = new PointF(10, 200); -PointF p3 = new PointF(100, 100); -PointF p4 = new PointF(100, 200); -PointF p5 = new PointF(55, 150); -PointF[] points = { p1, p2, p3, p4, p5 }; + //Initialize PdfLinearGradientBrush for drawing the polygon. + PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(10, 100), new PointF(100, 200), new PdfColor(Color.Red), new PdfColor(Color.Green)); -//Draw the polygon on PDF document. -loadedPage.Graphics.DrawPolygon(pen, brush, points); + //Create the polygon points. + PointF p1 = new PointF(10, 100); + PointF p2 = new PointF(10, 200); + PointF p3 = new PointF(100, 100); + PointF p4 = new PointF(100, 200); + PointF p5 = new PointF(55, 150); + PointF[] points = { p1, p2, p3, p4, p5 }; -//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 the polygon on PDF document. + loadedPage.Graphics.DrawPolygon(pen, brush, points); -//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/Shapes/Draw-a-rectangle-in-a-new-PDF-document/.NET/Draw-a-rectangle-in-a-new-PDF-document/Program.cs b/Shapes/Draw-a-rectangle-in-a-new-PDF-document/.NET/Draw-a-rectangle-in-a-new-PDF-document/Program.cs index b88d27bf..b20b0386 100644 --- a/Shapes/Draw-a-rectangle-in-a-new-PDF-document/.NET/Draw-a-rectangle-in-a-new-PDF-document/Program.cs +++ b/Shapes/Draw-a-rectangle-in-a-new-PDF-document/.NET/Draw-a-rectangle-in-a-new-PDF-document/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(); -//Initialize PdfSolidBrush for drawing the rectangle. -PdfSolidBrush brush = new PdfSolidBrush(Color.Green); + //Initialize PdfSolidBrush for drawing the rectangle. + PdfSolidBrush brush = new PdfSolidBrush(Color.Green); -//Set the bounds for rectangle. -RectangleF bounds = new RectangleF(10, 10, 100, 50); + //Set the bounds for rectangle. + RectangleF bounds = new RectangleF(10, 10, 100, 50); -//Draw the rectangle on PDF document. -page.Graphics.DrawRectangle(brush, bounds); + //Draw the rectangle on PDF document. + page.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. - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Shapes/Draw-a-rectangle-in-an-existing-PDF-document/.NET/Draw-a-rectangle-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-a-rectangle-in-an-existing-PDF-document/.NET/Draw-a-rectangle-in-an-existing-PDF-document/Program.cs index ee404453..f779608a 100644 --- a/Shapes/Draw-a-rectangle-in-an-existing-PDF-document/.NET/Draw-a-rectangle-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-a-rectangle-in-an-existing-PDF-document/.NET/Draw-a-rectangle-in-an-existing-PDF-document/Program.cs @@ -1,34 +1,23 @@ -// See https://aka.ms/new-console-template for more informatio - -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 inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - //Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize PdfSolidBrush for drawing the rectangle. -PdfSolidBrush brush = new PdfSolidBrush(Color.Green); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Set the bounds for rectangle. -RectangleF bounds = new RectangleF(10, 10, 100, 50); + //Initialize PdfSolidBrush for drawing the rectangle. + PdfSolidBrush brush = new PdfSolidBrush(Color.Green); -//Draw the rectangle on PDF document. -loadedPage.Graphics.DrawRectangle(brush, bounds); + //Set the bounds for rectangle. + RectangleF bounds = new RectangleF(10, 10, 100, 50); -//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 the rectangle on PDF document. + loadedPage.Graphics.DrawRectangle(brush, bounds); -//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/Shapes/Draw-an-arc-in-an-existing-PDF-document/.NET/Draw-an-arc-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-an-arc-in-an-existing-PDF-document/.NET/Draw-an-arc-in-an-existing-PDF-document/Program.cs index 04f77594..52feb184 100644 --- a/Shapes/Draw-an-arc-in-an-existing-PDF-document/.NET/Draw-an-arc-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-an-arc-in-an-existing-PDF-document/.NET/Draw-an-arc-in-an-existing-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.Graphics; using Syncfusion.Pdf.Parsing; -//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 into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize the pen for drawing an arc. -PdfPen pen = new PdfPen(Color.Brown, 10f); +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Set the line join style of the pen. -pen.LineCap = PdfLineCap.Square; + //Initialize the pen for drawing an arc. + PdfPen pen = new PdfPen(Color.Brown, 10f); -//Set the bounds for arc. -RectangleF bounds = new RectangleF(20, 40, 200, 200); + //Set the line join style of the pen. + pen.LineCap = PdfLineCap.Square; -//Draw the arc on PDF document. -loadedPage.Graphics.DrawArc(pen, bounds, 270, 90); + //Set the bounds for arc. + RectangleF bounds = new RectangleF(20, 40, 200, 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. - loadedDocument.Save(outputFileStream); -} + //Draw the arc on PDF document. + loadedPage.Graphics.DrawArc(pen, bounds, 270, 90); -//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/Shapes/Draw-an-arc-in-new-PDF-document/.NET/Draw-an-arc-in-new-PDF-document/Program.cs b/Shapes/Draw-an-arc-in-new-PDF-document/.NET/Draw-an-arc-in-new-PDF-document/Program.cs index 1ab73712..801444a6 100644 --- a/Shapes/Draw-an-arc-in-new-PDF-document/.NET/Draw-an-arc-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-an-arc-in-new-PDF-document/.NET/Draw-an-arc-in-new-PDF-document/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(); - -//Initialize the pen for drawing an arc. -PdfPen pen = new PdfPen(Color.Brown, 10f); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Set the line join style of the pen. -pen.LineCap = PdfLineCap.Square; + //Initialize the pen for drawing an arc. + PdfPen pen = new PdfPen(Color.Brown, 10f); -//Set the bounds for arc. -RectangleF bounds = new RectangleF(20, 40, 200, 200); + //Set the line join style of the pen. + pen.LineCap = PdfLineCap.Square; -//Draw the arc on PDF document. -page.Graphics.DrawArc(pen, bounds, 270, 90); + //Set the bounds for arc. + RectangleF bounds = new RectangleF(20, 40, 200, 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); -} + //Draw the arc on PDF document. + page.Graphics.DrawArc(pen, bounds, 270, 90); -//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/Shapes/Draw-an-ellipse-in-an-existing-PDF-document/.NET/Draw-an-ellipse-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-an-ellipse-in-an-existing-PDF-document/.NET/Draw-an-ellipse-in-an-existing-PDF-document/Program.cs index 98e213b5..d58406c0 100644 --- a/Shapes/Draw-an-ellipse-in-an-existing-PDF-document/.NET/Draw-an-ellipse-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-an-ellipse-in-an-existing-PDF-document/.NET/Draw-an-ellipse-in-an-existing-PDF-document/Program.cs @@ -1,31 +1,20 @@ -// 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 inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open); - -//Load the PDF document. -PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream); - -//Get the page into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; - -//Initialize PdfSolidBrush for drawing the ellipse. -PdfSolidBrush brush = new PdfSolidBrush(Color.Red); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Draw ellipse on the page. -loadedPage.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 200, 100)); + //Initialize PdfSolidBrush for drawing the ellipse. + PdfSolidBrush brush = new PdfSolidBrush(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. - loadedDocument.Save(outputFileStream); -} + //Draw ellipse on the page. + loadedPage.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 200, 100)); -//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/Shapes/Draw-an-ellipse-in-new-PDF-document/.NET/Draw-an-ellipse-in-new-PDF-document/Program.cs b/Shapes/Draw-an-ellipse-in-new-PDF-document/.NET/Draw-an-ellipse-in-new-PDF-document/Program.cs index eecd80b2..d8205c6a 100644 --- a/Shapes/Draw-an-ellipse-in-new-PDF-document/.NET/Draw-an-ellipse-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-an-ellipse-in-new-PDF-document/.NET/Draw-an-ellipse-in-new-PDF-document/Program.cs @@ -1,27 +1,19 @@ -// 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(); -//Initialize PdfSolidBrush for drawing the ellipse. -PdfSolidBrush brush = new PdfSolidBrush(Color.Red); + //Initialize PdfSolidBrush for drawing the ellipse. + PdfSolidBrush brush = new PdfSolidBrush(Color.Red); -//Draw ellipse on the page. -page.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 200, 100)); + //Draw ellipse on the page. + page.Graphics.DrawEllipse(brush, new RectangleF(10, 10, 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/Shapes/Draw-large-shapes-across-multiple-pages/.NET/Draw-large-shapes-across-multiple-pages/Program.cs b/Shapes/Draw-large-shapes-across-multiple-pages/.NET/Draw-large-shapes-across-multiple-pages/Program.cs index 9c646475..e78686f2 100644 --- a/Shapes/Draw-large-shapes-across-multiple-pages/.NET/Draw-large-shapes-across-multiple-pages/Program.cs +++ b/Shapes/Draw-large-shapes-across-multiple-pages/.NET/Draw-large-shapes-across-multiple-pages/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; -//Create Document. -PdfDocument document = new PdfDocument(); - -//Add new page. -PdfPage page = document.Pages.Add(); - -//Set bounds for ellipse. -RectangleF rect = new RectangleF(0, 0, 100, 1000); +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) +{ + //Add new page. + PdfPage page = document.Pages.Add(); -//Create ellipse. -PdfEllipse ellipse = new PdfEllipse(rect); + //Set bounds for ellipse. + RectangleF rect = new RectangleF(0, 0, 100, 1000); -//Set layout property to make the ellipse break across the pages. -PdfLayoutFormat format = new PdfLayoutFormat(); -format.Break = PdfLayoutBreakType.FitPage; -format.Layout = PdfLayoutType.Paginate; -ellipse.Brush = PdfBrushes.Brown; + //Create ellipse. + PdfEllipse ellipse = new PdfEllipse(rect); -//Draw ellipse. -ellipse.Draw(page, 20, 20, format); + //Set layout property to make the ellipse break across the pages. + PdfLayoutFormat format = new PdfLayoutFormat(); + format.Break = PdfLayoutBreakType.FitPage; + format.Layout = PdfLayoutType.Paginate; + ellipse.Brush = PdfBrushes.Brown; -//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 ellipse. + ellipse.Draw(page, 20, 20, format); -//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/Shapes/Draw-path-in-a-new-PDF-document/.NET/Draw-path-in-a-new-PDF-document/Program.cs b/Shapes/Draw-path-in-a-new-PDF-document/.NET/Draw-path-in-a-new-PDF-document/Program.cs index 4f7793f4..26cb8904 100644 --- a/Shapes/Draw-path-in-a-new-PDF-document/.NET/Draw-path-in-a-new-PDF-document/Program.cs +++ b/Shapes/Draw-path-in-a-new-PDF-document/.NET/Draw-path-in-a-new-PDF-document/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(); - -//Initialize a new PDF path. -PdfPath path = new PdfPath(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to the document. + PdfPage page = document.Pages.Add(); -//Add line path points. -path.AddLine(new PointF(10, 100), new PointF(10, 200)); -path.AddLine(new PointF(10, 200), new PointF(100, 100)); -path.AddLine(new PointF(100, 100), new PointF(100, 200)); -path.AddLine(new PointF(100, 200), new PointF(10, 100)); + //Initialize a new PDF path. + PdfPath path = new PdfPath(); -//Draw the PDF path on page. -page.Graphics.DrawPath(PdfPens.Black, path); + //Add line path points. + path.AddLine(new PointF(10, 100), new PointF(10, 200)); + path.AddLine(new PointF(10, 200), new PointF(100, 100)); + path.AddLine(new PointF(100, 100), new PointF(100, 200)); + path.AddLine(new PointF(100, 200), new PointF(10, 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); -} + //Draw the PDF path on page. + page.Graphics.DrawPath(PdfPens.Black, 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/Shapes/Draw-path-in-an-existing-PDF-document/.NET/Draw-path-in-an-existing-PDF-document/Program.cs b/Shapes/Draw-path-in-an-existing-PDF-document/.NET/Draw-path-in-an-existing-PDF-document/Program.cs index 5d713cec..d2c09f45 100644 --- a/Shapes/Draw-path-in-an-existing-PDF-document/.NET/Draw-path-in-an-existing-PDF-document/Program.cs +++ b/Shapes/Draw-path-in-an-existing-PDF-document/.NET/Draw-path-in-an-existing-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.Graphics; using Syncfusion.Pdf.Parsing; -//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 into PdfLoadedPage. -PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get the page into PdfLoadedPage. + PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; -//Initialize a new PDF path. -PdfPath path = new PdfPath(); + //Initialize a new PDF path. + PdfPath path = new PdfPath(); -//Add line path points. -path.AddLine(new PointF(10, 100), new PointF(10, 200)); -path.AddLine(new PointF(10, 200), new PointF(100, 100)); -path.AddLine(new PointF(100, 100), new PointF(100, 200)); -path.AddLine(new PointF(100, 200), new PointF(10, 100)); + //Add line path points. + path.AddLine(new PointF(10, 100), new PointF(10, 200)); + path.AddLine(new PointF(10, 200), new PointF(100, 100)); + path.AddLine(new PointF(100, 100), new PointF(100, 200)); + path.AddLine(new PointF(100, 200), new PointF(10, 100)); -//Draw the PDF path on page. -loadedPage.Graphics.DrawPath(PdfPens.Black, path); - -//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 the PDF path on page. + loadedPage.Graphics.DrawPath(PdfPens.Black, path); -//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/Shapes/Draw-polygon-in-new-PDF-document/.NET/Draw-polygon-in-new-PDF-document/Program.cs b/Shapes/Draw-polygon-in-new-PDF-document/.NET/Draw-polygon-in-new-PDF-document/Program.cs index 5c27b016..8c050025 100644 --- a/Shapes/Draw-polygon-in-new-PDF-document/.NET/Draw-polygon-in-new-PDF-document/Program.cs +++ b/Shapes/Draw-polygon-in-new-PDF-document/.NET/Draw-polygon-in-new-PDF-document/Program.cs @@ -1,39 +1,31 @@ -// 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(); -//Initialize PdfPen to draw the polygon. -PdfPen pen = new PdfPen(PdfBrushes.Brown, 10f); + //Initialize PdfPen to draw the polygon. + PdfPen pen = new PdfPen(PdfBrushes.Brown, 10f); -//Initialize PdfLinearGradientBrush for drawing the polygon. -PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(10, 100), new PointF(100, 200), new PdfColor(Color.Red), new PdfColor(Color.Green)); + //Initialize PdfLinearGradientBrush for drawing the polygon. + PdfLinearGradientBrush brush = new PdfLinearGradientBrush(new PointF(10, 100), new PointF(100, 200), new PdfColor(Color.Red), new PdfColor(Color.Green)); -//Create the polygon points. -PointF p1 = new PointF(10, 100); -PointF p2 = new PointF(10, 200); -PointF p3 = new PointF(100, 100); -PointF p4 = new PointF(100, 200); -PointF p5 = new PointF(55, 150); -PointF[] points = { p1, p2, p3, p4, p5 }; + //Create the polygon points. + PointF p1 = new PointF(10, 100); + PointF p2 = new PointF(10, 200); + PointF p3 = new PointF(100, 100); + PointF p4 = new PointF(100, 200); + PointF p5 = new PointF(55, 150); + PointF[] points = { p1, p2, p3, p4, p5 }; -//Draw the polygon on PDF document. -page.Graphics.DrawPolygon(pen, brush, points); + //Draw the polygon on PDF document. + page.Graphics.DrawPolygon(pen, brush, points); -//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/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs index 52729580..c341cd72 100644 --- a/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs +++ b/Shapes/Multi-color-radial-gradient-fill-in-PDF/.NET/Multi-color-radial-gradient-fill-in-PDF/Program.cs @@ -2,30 +2,30 @@ 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(); -// Get graphics context of the added page. -PdfGraphics graphics = page.Graphics; + // Get graphics context of the added page. + PdfGraphics graphics = page.Graphics; -// Define the rectangle dimensions. -float rectWidth = 416; -float rectHeight = 145; + // Define the rectangle dimensions. + float rectWidth = 416; + float rectHeight = 145; -// Calculate the top-center position. -float pageWidth = page.GetClientSize().Width; -float rectX = (pageWidth - rectWidth) / 2; // Centered horizontally -float rectY = 50; // Distance from the top + // Calculate the top-center position. + float pageWidth = page.GetClientSize().Width; + float rectX = (pageWidth - rectWidth) / 2; // Centered horizontally + float rectY = 50; // Distance from the top -// Define the rectangle path. -PdfPath path = new PdfPath(); -path.AddRectangle(new RectangleF(rectX, rectY, rectWidth, rectHeight)); + // Define the rectangle path. + PdfPath path = new PdfPath(); + path.AddRectangle(new RectangleF(rectX, rectY, rectWidth, rectHeight)); -// Define gradient colors using RGB (byte values from 0 to 255). -List finalGradientColors = new List + // Define gradient colors using RGB (byte values from 0 to 255). + List finalGradientColors = new List { new PdfColor(0, 63, 255), // Blue new PdfColor(0, 200, 83), // Green @@ -33,38 +33,33 @@ new PdfColor(255, 0, 139) // Magenta }; -// Define positions for the gradient colors. -List finalGradientPositions = new List { 0, 0.2f, 0.8f, 1 }; + // Define positions for the gradient colors. + List finalGradientPositions = new List { 0, 0.2f, 0.8f, 1 }; -// Create a color blend object for the gradient. -PdfColorBlend gradientColorBlend = new PdfColorBlend -{ - Colors = finalGradientColors.ToArray(), - Positions = finalGradientPositions.ToArray() -}; + // Create a color blend object for the gradient. + PdfColorBlend gradientColorBlend = new PdfColorBlend + { + Colors = finalGradientColors.ToArray(), + Positions = finalGradientPositions.ToArray() + }; -// Calculate the center point and radius for the radial gradient. -PointF center = new PointF(rectX + rectWidth / 2, rectY + rectHeight / 2); -float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; + // Calculate the center point and radius for the radial gradient. + PointF center = new PointF(rectX + rectWidth / 2, rectY + rectHeight / 2); + float radius = (float)Math.Sqrt((rectWidth * rectWidth) + (rectHeight * rectHeight)) / 2; -// Create and configure the radial gradient brush. -PdfRadialGradientBrush rectangleGradientBrush = new PdfRadialGradientBrush( - center, 0, center, radius, - finalGradientColors[0], - finalGradientColors[finalGradientColors.Count - 1] -) -{ - InterpolationColors = gradientColorBlend -}; + // Create and configure the radial gradient brush. + PdfRadialGradientBrush rectangleGradientBrush = new PdfRadialGradientBrush( + center, 0, center, radius, + finalGradientColors[0], + finalGradientColors[finalGradientColors.Count - 1] + ) + { + InterpolationColors = gradientColorBlend + }; -// Draw the gradient-filled rectangle. -graphics.DrawPath(rectangleGradientBrush, path); + // Draw the gradient-filled rectangle. + graphics.DrawPath(rectangleGradientBrush, path); -//Create file stream. -using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) -{ - document.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -// Close the document and release resources. -document.Close(true); diff --git a/Table/PdfGrid/Add-a-hyperlink-in-a-table-cell/.NET/Add-a-hyperlink-in-a-table-cell/Program.cs b/Table/PdfGrid/Add-a-hyperlink-in-a-table-cell/.NET/Add-a-hyperlink-in-a-table-cell/Program.cs index 3e64de64..28a2e435 100644 --- a/Table/PdfGrid/Add-a-hyperlink-in-a-table-cell/.NET/Add-a-hyperlink-in-a-table-cell/Program.cs +++ b/Table/PdfGrid/Add-a-hyperlink-in-a-table-cell/.NET/Add-a-hyperlink-in-a-table-cell/Program.cs @@ -1,54 +1,46 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; 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(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a new page. + PdfPage page = document.Pages.Add(); -//Initialize the UriAnnotation to pass it in the grid cell. -RectangleF rectangle = new RectangleF(10, 40, 30, 30); -PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "http://www.google.com"); + //Initialize the UriAnnotation to pass it in the grid cell. + RectangleF rectangle = new RectangleF(10, 40, 30, 30); + PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(rectangle, "http://www.google.com"); -//Set the annotation text. -uriAnnotation.Text = "Uri Annotation"; + //Set the annotation text. + uriAnnotation.Text = "Uri Annotation"; -//Create a new pdf grid. -PdfGrid grid = new PdfGrid(); + //Create a new pdf grid. + PdfGrid grid = new PdfGrid(); -//Add columns to the grid. -grid.Columns.Add(3); + //Add columns to the grid. + grid.Columns.Add(3); -//Add rows. -PdfGridRow row = grid.Rows.Add(); -row.Cells[0].Value = "First Cell"; + //Add rows. + PdfGridRow row = grid.Rows.Add(); + row.Cells[0].Value = "First Cell"; -//Assign the UriAnnotation as a hyperlink in the grid cell. -row.Cells[1].Value = uriAnnotation; -row.Cells[2].Value = "Third Cell"; + //Assign the UriAnnotation as a hyperlink in the grid cell. + row.Cells[1].Value = uriAnnotation; + row.Cells[2].Value = "Third Cell"; -//Create the grid cell style. -PdfGridCellStyle cellStyle = new PdfGridCellStyle(); -cellStyle.TextBrush = PdfBrushes.Blue; + //Create the grid cell style. + PdfGridCellStyle cellStyle = new PdfGridCellStyle(); + cellStyle.TextBrush = PdfBrushes.Blue; -//Apply the cell style to the annotation cell. -row.Cells[1].Style = cellStyle; + //Apply the cell style to the annotation cell. + row.Cells[1].Style = cellStyle; -//Draw the grid. -grid.Draw(page, new PointF(0, 0)); + //Draw the grid. + grid.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); diff --git a/Table/PdfGrid/Add-column-spanning-in-a-PDF-table/.NET/Add-column-spanning-in-a-PDF-table/Program.cs b/Table/PdfGrid/Add-column-spanning-in-a-PDF-table/.NET/Add-column-spanning-in-a-PDF-table/Program.cs index 0af86085..a72603af 100644 --- a/Table/PdfGrid/Add-column-spanning-in-a-PDF-table/.NET/Add-column-spanning-in-a-PDF-table/Program.cs +++ b/Table/PdfGrid/Add-column-spanning-in-a-PDF-table/.NET/Add-column-spanning-in-a-PDF-table/Program.cs @@ -1,50 +1,42 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create the page. -PdfPage page = document.Pages.Add(); - -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); - -//Create and customize the string formats. -PdfStringFormat format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -format.LineAlignment = PdfVerticalAlignment.Middle; - -//Add columns to PdfGrid. -pdfGrid.Columns.Add(5); - -//Add rows to PdfGrid. -for (int i = 0; i < pdfGrid.Columns.Count; i++) +using (PdfDocument document = new PdfDocument()) { - PdfGridRow row = pdfGrid.Rows.Add(); - row.Height = 20; -} - -//Add ColumnSpan. -PdfGridCell gridCell = pdfGrid.Rows[1].Cells[0]; -gridCell.ColumnSpan = 2; -gridCell.StringFormat = format; -gridCell.Value = "Column Span"; -gridCell.Style.BackgroundBrush = PdfBrushes.Yellow; - -//Draw the PdfGrid. -pdfGrid.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); -} - -//Close the document. -document.Close(true); + //Create the page. + PdfPage page = document.Pages.Add(); + + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + + //Create and customize the string formats. + PdfStringFormat format = new PdfStringFormat(); + format.Alignment = PdfTextAlignment.Center; + format.LineAlignment = PdfVerticalAlignment.Middle; + + //Add columns to PdfGrid. + pdfGrid.Columns.Add(5); + + //Add rows to PdfGrid. + for (int i = 0; i < pdfGrid.Columns.Count; i++) + { + PdfGridRow row = pdfGrid.Rows.Add(); + row.Height = 20; + } + + //Add ColumnSpan. + PdfGridCell gridCell = pdfGrid.Rows[1].Cells[0]; + gridCell.ColumnSpan = 2; + gridCell.StringFormat = format; + gridCell.Value = "Column Span"; + gridCell.Style.BackgroundBrush = PdfBrushes.Yellow; + + //Draw the PdfGrid. + pdfGrid.Draw(page, new PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfGrid/Add-different-cell-styles-to-a-cell-in-a-PDF-table/.NET/Add-different-cell-styles-to-a-cell-in-a-PDF-table/Program.cs b/Table/PdfGrid/Add-different-cell-styles-to-a-cell-in-a-PDF-table/.NET/Add-different-cell-styles-to-a-cell-in-a-PDF-table/Program.cs index e1e3b18b..b29e71d8 100644 --- a/Table/PdfGrid/Add-different-cell-styles-to-a-cell-in-a-PDF-table/.NET/Add-different-cell-styles-to-a-cell-in-a-PDF-table/Program.cs +++ b/Table/PdfGrid/Add-different-cell-styles-to-a-cell-in-a-PDF-table/.NET/Add-different-cell-styles-to-a-cell-in-a-PDF-table/Program.cs @@ -1,94 +1,86 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add a PDF page. -PdfPage pdfPage = pdfDocument.Pages.Add(); - -//Create a new PdfGrid instance. -PdfGrid pdfGrid = new PdfGrid(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a PDF page. + PdfPage pdfPage = document.Pages.Add(); -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + //Create a new PdfGrid instance. + PdfGrid pdfGrid = new PdfGrid(); -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -//Add list to IEnumerable. -IEnumerable dataTable = data; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); -//Assign data source to PdfGrid. -pdfGrid.DataSource = dataTable; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign row height and column width. -pdfGrid.Rows[1].Height = 50; -pdfGrid.Columns[1].Width = 100; + //Assign data source to PdfGrid. + pdfGrid.DataSource = dataTable; -//Initialize PdfGridCellStyle and set background color. -PdfGridCellStyle gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.BackgroundBrush = PdfBrushes.Yellow; + //Assign row height and column width. + pdfGrid.Rows[1].Height = 50; + pdfGrid.Columns[1].Width = 100; -//Assign background color to a PdfGridCell. -PdfGridCell gridCell = pdfGrid.Rows[0].Cells[0]; -gridCell.Style = gridCellStyle; + //Initialize PdfGridCellStyle and set background color. + PdfGridCellStyle gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.BackgroundBrush = PdfBrushes.Yellow; -//Initialize PdfGridCellStyle and set background image. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open); -gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.BackgroundImage = PdfImage.FromStream(imageStream); + //Assign background color to a PdfGridCell. + PdfGridCell gridCell = pdfGrid.Rows[0].Cells[0]; + gridCell.Style = gridCellStyle; -//Assign background image to a PdfGridCell. -gridCell = pdfGrid.Rows[1].Cells[1]; -gridCell.Style = gridCellStyle; -gridCell.ImagePosition = PdfGridImagePosition.Fit; + //Initialize PdfGridCellStyle and set background image. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open); + gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.BackgroundImage = PdfImage.FromStream(imageStream); -//Initialize PdfGridCellStyle and set the border color. -gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.Borders.All = PdfPens.Red; + //Assign background image to a PdfGridCell. + gridCell = pdfGrid.Rows[1].Cells[1]; + gridCell.Style = gridCellStyle; + gridCell.ImagePosition = PdfGridImagePosition.Fit; -//Assign the border color to a PdfGridCell. -gridCell = pdfGrid.Rows[2].Cells[2]; -gridCell.Style = gridCellStyle; + //Initialize PdfGridCellStyle and set the border color. + gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.Borders.All = PdfPens.Red; -//Initialize PdfGridCellStyle and set text color. -gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.TextBrush = PdfBrushes.DarkBlue; + //Assign the border color to a PdfGridCell. + gridCell = pdfGrid.Rows[2].Cells[2]; + gridCell.Style = gridCellStyle; -//Assign text color to a PdfGridCell. -gridCell = pdfGrid.Rows[0].Cells[2]; -gridCell.Style = gridCellStyle; + //Initialize PdfGridCellStyle and set text color. + gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.TextBrush = PdfBrushes.DarkBlue; -//Set the column span. -pdfGrid.Rows[2].Cells[0].ColumnSpan = 2; + //Assign text color to a PdfGridCell. + gridCell = pdfGrid.Rows[0].Cells[2]; + gridCell.Style = gridCellStyle; -//Initialize PdfStringFormat and set the properties. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + //Set the column span. + pdfGrid.Rows[2].Cells[0].ColumnSpan = 2; -//Set the PdfStringFormat to PdfGridCell. -gridCell = pdfGrid.Rows[2].Cells[0]; -gridCell.StringFormat = stringFormat; + //Initialize PdfStringFormat and set the properties. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -//Draw the table in the PDF page. -pdfGrid.Draw(pdfPage, new PointF(10, 10)); + //Set the PdfStringFormat to PdfGridCell. + gridCell = pdfGrid.Rows[2].Cells[0]; + gridCell.StringFormat = stringFormat; -//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 table in the PDF page. + pdfGrid.Draw(pdfPage, new PointF(10, 10)); -//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/Table/PdfGrid/Add-different-font-style-for-particular-table-cell/.NET/Add-different-font-style-for-particular-table-cell/Program.cs b/Table/PdfGrid/Add-different-font-style-for-particular-table-cell/.NET/Add-different-font-style-for-particular-table-cell/Program.cs index 0000b0ea..5e3acc05 100644 --- a/Table/PdfGrid/Add-different-font-style-for-particular-table-cell/.NET/Add-different-font-style-for-particular-table-cell/Program.cs +++ b/Table/PdfGrid/Add-different-font-style-for-particular-table-cell/.NET/Add-different-font-style-for-particular-table-cell/Program.cs @@ -1,65 +1,55 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; using Syncfusion.Drawing; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add a row. -PdfGridRow row1 = pdfGrid.Rows.Add(); + //Add a row. + PdfGridRow row1 = pdfGrid.Rows.Add(); -//Add columns. -pdfGrid.Columns.Add(3); + //Add columns. + pdfGrid.Columns.Add(3); -//Set the value to the specific cell. -row1.Cells[0].Value = "Employee Details"; -row1.Cells[0].ColumnSpan = 3; + //Set the value to the specific cell. + row1.Cells[0].Value = "Employee Details"; + row1.Cells[0].ColumnSpan = 3; -//Add a row. -PdfGridRow row2 = pdfGrid.Rows.Add(); -row2.Cells[0].Value = "Employee ID"; -row2.Cells[1].Value = "Employee Name"; -row2.Cells[2].Value = "Employee Address"; + //Add a row. + PdfGridRow row2 = pdfGrid.Rows.Add(); + row2.Cells[0].Value = "Employee ID"; + row2.Cells[1].Value = "Employee Name"; + row2.Cells[2].Value = "Employee Address"; -//Add a row. -PdfGridRow row3 = pdfGrid.Rows.Add(); -row3.Cells[0].Value = "E01"; -row3.Cells[1].Value = "Simons Bistro"; -row3.Height = 50; + //Add a row. + PdfGridRow row3 = pdfGrid.Rows.Add(); + row3.Cells[0].Value = "E01"; + row3.Cells[1].Value = "Simons Bistro"; + row3.Height = 50; -//Call the event handler to add the string to a particular cell. -pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout; + //Call the event handler to add the string to a particular cell. + pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout; -//Create and customize the string formats. -PdfStringFormat format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -pdfGrid.Rows[0].Cells[0].StringFormat = format; + //Create and customize the string formats. + PdfStringFormat format = new PdfStringFormat(); + format.Alignment = PdfTextAlignment.Center; + pdfGrid.Rows[0].Cells[0].StringFormat = format; -//Draw the PdfGrid. -pdfGrid.Draw(pdfPage, PointF.Empty); + //Draw the PdfGrid. + pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDocument.Close(true); - - - //Event handler to add differnt font styles. static void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args) { diff --git a/Table/PdfGrid/Add-different-styles-to-a-row-in-PDF-table/.NET/Add-different-styles-to-a-row-in-PDF-table/Program.cs b/Table/PdfGrid/Add-different-styles-to-a-row-in-PDF-table/.NET/Add-different-styles-to-a-row-in-PDF-table/Program.cs index 189f46e6..20377b52 100644 --- a/Table/PdfGrid/Add-different-styles-to-a-row-in-PDF-table/.NET/Add-different-styles-to-a-row-in-PDF-table/Program.cs +++ b/Table/PdfGrid/Add-different-styles-to-a-row-in-PDF-table/.NET/Add-different-styles-to-a-row-in-PDF-table/Program.cs @@ -1,80 +1,72 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add a new page. -PdfPage pdfPage = pdfDocument.Pages.Add(); - -//Create a new PdfGrid instance. -PdfGrid pdfGrid = new PdfGrid(); - -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); - -//Add list to IEnumerable. -IEnumerable dataTable = data; - -//Assign data source to PdfGrid. -pdfGrid.DataSource = dataTable; - -//Assign row height and column width. -pdfGrid.Rows[1].Height = 50; -pdfGrid.Columns[1].Width = 100; - -//Initialize PdfStringFormat and set the properties. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -stringFormat.CharacterSpacing = 2f; - -//Initialize PdfGridCellStyle. Set background color and string format -PdfGridCellStyle gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.BackgroundBrush = PdfBrushes.Yellow; -gridCellStyle.StringFormat = stringFormat; - -//Initialize PdfGridRow and apply PdfGridCellStyle to the row. -PdfGridRow gridRow = pdfGrid.Rows[0]; -gridRow.ApplyStyle(gridCellStyle); - -//Initialize PdfGridCellStyle and set background image. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open); -gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.BackgroundImage = PdfImage.FromStream(imageStream); - -//Initialize PdfGridRow and apply PdfGridCellStyle to the row. -gridRow = pdfGrid.Rows[1]; -gridRow.ApplyStyle(gridCellStyle); - -//Initialize PdfGridCellStyle. Set the border color and text color. -gridCellStyle = new PdfGridCellStyle(); -gridCellStyle.Borders.All = PdfPens.Red; -gridCellStyle.TextBrush = PdfBrushes.DarkBlue; - -//Initialize PdfGridRow and apply PdfGridCellStyle to the row. -gridRow = pdfGrid.Rows[2]; -gridRow.ApplyStyle(gridCellStyle); - -//Draw the table in the PDF page. -pdfGrid.Draw(pdfPage, new PointF(10, 10)); - -//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. - pdfDocument.Save(outputFileStream); + //Add a new page. + PdfPage pdfPage = document.Pages.Add(); + + //Create a new PdfGrid instance. + PdfGrid pdfGrid = new PdfGrid(); + + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); + + //Add list to IEnumerable. + IEnumerable dataTable = data; + + //Assign data source to PdfGrid. + pdfGrid.DataSource = dataTable; + + //Assign row height and column width. + pdfGrid.Rows[1].Height = 50; + pdfGrid.Columns[1].Width = 100; + + //Initialize PdfStringFormat and set the properties. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + stringFormat.CharacterSpacing = 2f; + + //Initialize PdfGridCellStyle. Set background color and string format + PdfGridCellStyle gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.BackgroundBrush = PdfBrushes.Yellow; + gridCellStyle.StringFormat = stringFormat; + + //Initialize PdfGridRow and apply PdfGridCellStyle to the row. + PdfGridRow gridRow = pdfGrid.Rows[0]; + gridRow.ApplyStyle(gridCellStyle); + + //Initialize PdfGridCellStyle and set background image. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Autumn Leaves.jpg"), FileMode.Open); + gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.BackgroundImage = PdfImage.FromStream(imageStream); + + //Initialize PdfGridRow and apply PdfGridCellStyle to the row. + gridRow = pdfGrid.Rows[1]; + gridRow.ApplyStyle(gridCellStyle); + + //Initialize PdfGridCellStyle. Set the border color and text color. + gridCellStyle = new PdfGridCellStyle(); + gridCellStyle.Borders.All = PdfPens.Red; + gridCellStyle.TextBrush = PdfBrushes.DarkBlue; + + //Initialize PdfGridRow and apply PdfGridCellStyle to the row. + gridRow = pdfGrid.Rows[2]; + gridRow.ApplyStyle(gridCellStyle); + + //Draw the table in the PDF page. + pdfGrid.Draw(pdfPage, new PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/Table/PdfGrid/Add-multiple-tables-in-a-PDF-document/.NET/Add-multiple-tables-in-a-PDF-document/Program.cs b/Table/PdfGrid/Add-multiple-tables-in-a-PDF-document/.NET/Add-multiple-tables-in-a-PDF-document/Program.cs index 2be23785..91c1bf0f 100644 --- a/Table/PdfGrid/Add-multiple-tables-in-a-PDF-document/.NET/Add-multiple-tables-in-a-PDF-document/Program.cs +++ b/Table/PdfGrid/Add-multiple-tables-in-a-PDF-document/.NET/Add-multiple-tables-in-a-PDF-document/Program.cs @@ -1,64 +1,56 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; //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 new PdfGrid instance. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid instance. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Draw grid on the page of PDF document and store the grid position in PdfGridLayoutResult. -PdfGridLayoutResult pdfGridLayoutResult = pdfGrid.Draw(page, new PointF(10, 10)); + //Draw grid on the page of PDF document and store the grid position in PdfGridLayoutResult. + PdfGridLayoutResult pdfGridLayoutResult = pdfGrid.Draw(page, new PointF(10, 10)); -//Initialize PdfGrid and list. -pdfGrid = new PdfGrid(); -data = new List(); + //Initialize PdfGrid and list. + pdfGrid = new PdfGrid(); + data = new List(); -//Add values to the list. -Object grid2row1 = new { Name = "Andrew", Age = "21", Sex = "Male" }; -Object grid2row2 = new { Name = "Steven", Age = "22", Sex = "Female" }; -Object grid2row3 = new { Name = "Michael", Age = "24", Sex = "Male" }; -data.Add(grid2row1); -data.Add(grid2row2); -data.Add(grid2row3); + //Add values to the list. + Object grid2row1 = new { Name = "Andrew", Age = "21", Sex = "Male" }; + Object grid2row2 = new { Name = "Steven", Age = "22", Sex = "Female" }; + Object grid2row3 = new { Name = "Michael", Age = "24", Sex = "Male" }; + data.Add(grid2row1); + data.Add(grid2row2); + data.Add(grid2row3); -//Add list to IEnumerable. -dataTable = data; + //Add list to IEnumerable. + dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Draw the grid on page using previous result. -pdfGrid.Draw(page, new PointF(10, pdfGridLayoutResult.Bounds.Bottom + 20)); + //Draw the grid on page using previous result. + pdfGrid.Draw(page, new PointF(10, pdfGridLayoutResult.Bounds.Bottom + 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Add-row-spanning-in-a-PDF-table/.NET/Add-row-spanning-in-a-PDF-table/Program.cs b/Table/PdfGrid/Add-row-spanning-in-a-PDF-table/.NET/Add-row-spanning-in-a-PDF-table/Program.cs index daccd2af..64795ae5 100644 --- a/Table/PdfGrid/Add-row-spanning-in-a-PDF-table/.NET/Add-row-spanning-in-a-PDF-table/Program.cs +++ b/Table/PdfGrid/Add-row-spanning-in-a-PDF-table/.NET/Add-row-spanning-in-a-PDF-table/Program.cs @@ -1,50 +1,42 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Create the page. -PdfPage page = document.Pages.Add(); - -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); - -//Create and customize the string formats. -PdfStringFormat format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -format.LineAlignment = PdfVerticalAlignment.Middle; - -//Add columns to PdfGrid. -pdfGrid.Columns.Add(5); - -//Add rows to PdfGrid. -for (int i = 0; i < pdfGrid.Columns.Count; i++) +using (PdfDocument document = new PdfDocument()) { - PdfGridRow row = pdfGrid.Rows.Add(); - row.Height = 20; + //Create the page. + PdfPage page = document.Pages.Add(); + + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + + //Create and customize the string formats. + PdfStringFormat format = new PdfStringFormat(); + format.Alignment = PdfTextAlignment.Center; + format.LineAlignment = PdfVerticalAlignment.Middle; + + //Add columns to PdfGrid. + pdfGrid.Columns.Add(5); + + //Add rows to PdfGrid. + for (int i = 0; i < pdfGrid.Columns.Count; i++) + { + PdfGridRow row = pdfGrid.Rows.Add(); + row.Height = 20; + } + + //Add RowSpan. + PdfGridCell gridCell = pdfGrid.Rows[1].Cells[3]; + gridCell.RowSpan = 3; + gridCell.StringFormat = format; + gridCell.Value = "Row Span"; + gridCell.Style.BackgroundBrush = PdfBrushes.Yellow; + + //Draw the PdfGrid. + pdfGrid.Draw(page, new PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Add RowSpan. -PdfGridCell gridCell = pdfGrid.Rows[1].Cells[3]; -gridCell.RowSpan = 3; -gridCell.StringFormat = format; -gridCell.Value = "Row Span"; -gridCell.Style.BackgroundBrush = PdfBrushes.Yellow; - -//Draw the PdfGrid. -pdfGrid.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); -} - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Add-string-formatting-for-a-cell-in-table/.NET/Add-string-formatting-for-a-cell-in-table/Program.cs b/Table/PdfGrid/Add-string-formatting-for-a-cell-in-table/.NET/Add-string-formatting-for-a-cell-in-table/Program.cs index 5c9867c8..1d95e65f 100644 --- a/Table/PdfGrid/Add-string-formatting-for-a-cell-in-table/.NET/Add-string-formatting-for-a-cell-in-table/Program.cs +++ b/Table/PdfGrid/Add-string-formatting-for-a-cell-in-table/.NET/Add-string-formatting-for-a-cell-in-table/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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the PdfDocument. -PdfPage page = document.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the PdfDocument. + PdfPage page = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid grid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid grid = new PdfGrid(); -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -grid.DataSource = dataTable; + //Assign data source. + grid.DataSource = dataTable; -//Create and customize the string formats. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -stringFormat.CharacterSpacing = 2f; + //Create and customize the string formats. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + stringFormat.CharacterSpacing = 2f; -//Apply string format to a cell -grid.Rows[2].Cells[1].StringFormat = stringFormat; + //Apply string format to a cell + grid.Rows[2].Cells[1].StringFormat = stringFormat; -//Draw the PdfGrid on page -grid.Draw(page, new PointF(10, 10)); + //Draw the PdfGrid on page + grid.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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Add-string-formatting-for-a-row-in-table/.NET/Add-string-formatting-for-a-row-in-table/Program.cs b/Table/PdfGrid/Add-string-formatting-for-a-row-in-table/.NET/Add-string-formatting-for-a-row-in-table/Program.cs index 8cdd997d..4f0d9a0d 100644 --- a/Table/PdfGrid/Add-string-formatting-for-a-row-in-table/.NET/Add-string-formatting-for-a-row-in-table/Program.cs +++ b/Table/PdfGrid/Add-string-formatting-for-a-row-in-table/.NET/Add-string-formatting-for-a-row-in-table/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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the PdfDocument. -PdfPage page = document.Pages.Add(); - -//Create a new PdfGrid. -PdfGrid grid = new PdfGrid(); - -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); - -//Add list to IEnumerable. -IEnumerable dataTable = data; - -//Assign data source. -grid.DataSource = dataTable; - -//create and customize the string formats. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -stringFormat.CharacterSpacing = 2f; - -//Assign string format to a row. -for (int i = 0; i < grid.Columns.Count; i++) -{ - grid.Rows[2].Cells[i].StringFormat = stringFormat; -} - -//Draw the PdfGrid on page. -grid.Draw(page, new PointF(10, 10)); - -//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); -} - -//Close the document. -document.Close(true); + //Add page to the PdfDocument. + PdfPage page = document.Pages.Add(); + + //Create a new PdfGrid. + PdfGrid grid = new PdfGrid(); + + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); + + //Add list to IEnumerable. + IEnumerable dataTable = data; + + //Assign data source. + grid.DataSource = dataTable; + + //create and customize the string formats. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + stringFormat.CharacterSpacing = 2f; + + //Assign string format to a row. + for (int i = 0; i < grid.Columns.Count; i++) + { + grid.Rows[2].Cells[i].StringFormat = stringFormat; + } + + //Draw the PdfGrid on page. + grid.Draw(page, new PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfGrid/Add-string-formatting-to-a-column-in-table/.NET/Add-string-formatting-to-a-column-in-table/Program.cs b/Table/PdfGrid/Add-string-formatting-to-a-column-in-table/.NET/Add-string-formatting-to-a-column-in-table/Program.cs index dcd8d645..cac2d821 100644 --- a/Table/PdfGrid/Add-string-formatting-to-a-column-in-table/.NET/Add-string-formatting-to-a-column-in-table/Program.cs +++ b/Table/PdfGrid/Add-string-formatting-to-a-column-in-table/.NET/Add-string-formatting-to-a-column-in-table/Program.cs @@ -1,52 +1,44 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add page to the document. -PdfPage page = document.Pages.Add(); - -//Create a new PdfGrid. -PdfGrid grid = new PdfGrid(); - -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); - -//Add list to IEnumerable. -IEnumerable dataTable = data; - -//Assign data source. -grid.DataSource = dataTable; - -//create and customize the string formats. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -stringFormat.CharacterSpacing = 2f; - -//Apply string formatting to a column -grid.Columns[1].Format = stringFormat; - -//Draw the PdfGrid on page -grid.Draw(page, new PointF(10, 10)); - -//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); -} - -//Close the document. -document.Close(true); + //Add page to the document. + PdfPage page = document.Pages.Add(); + + //Create a new PdfGrid. + PdfGrid grid = new PdfGrid(); + + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); + + //Add list to IEnumerable. + IEnumerable dataTable = data; + + //Assign data source. + grid.DataSource = dataTable; + + //create and customize the string formats. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + stringFormat.CharacterSpacing = 2f; + + //Apply string formatting to a column + grid.Columns[1].Format = stringFormat; + + //Draw the PdfGrid on page + grid.Draw(page, new PointF(10, 10)); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfGrid/Add-the-background-image-in-a-PDF-table-cell/.NET/Add-the-background-image-in-a-PDF-table-cell/Program.cs b/Table/PdfGrid/Add-the-background-image-in-a-PDF-table-cell/.NET/Add-the-background-image-in-a-PDF-table-cell/Program.cs index bf3afe26..d2c9880f 100644 --- a/Table/PdfGrid/Add-the-background-image-in-a-PDF-table-cell/.NET/Add-the-background-image-in-a-PDF-table-cell/Program.cs +++ b/Table/PdfGrid/Add-the-background-image-in-a-PDF-table-cell/.NET/Add-the-background-image-in-a-PDF-table-cell/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.Grid; using Syncfusion.Pdf; using Syncfusion.Drawing; diff --git a/Table/PdfGrid/Add-the-data-directly-to-the-table-in-a-PDF/.NET/Add-the-data-directly-to-the-table-in-a-PDF/Program.cs b/Table/PdfGrid/Add-the-data-directly-to-the-table-in-a-PDF/.NET/Add-the-data-directly-to-the-table-in-a-PDF/Program.cs index 5cf3f39f..f233ea89 100644 --- a/Table/PdfGrid/Add-the-data-directly-to-the-table-in-a-PDF/.NET/Add-the-data-directly-to-the-table-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Add-the-data-directly-to-the-table-in-a-PDF/.NET/Add-the-data-directly-to-the-table-in-a-PDF/Program.cs @@ -1,43 +1,35 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add page to the PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); - -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); - -//Add three columns. -pdfGrid.Columns.Add(3); - -//Add header. -pdfGrid.Headers.Add(1); -PdfGridRow pdfGridHeader = pdfGrid.Headers[0]; -pdfGridHeader.Cells[0].Value = "Employee ID"; -pdfGridHeader.Cells[1].Value = "Employee Name"; -pdfGridHeader.Cells[2].Value = "Salary"; - -//Add rows. -PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); -pdfGridRow.Cells[0].Value = "E01"; -pdfGridRow.Cells[1].Value = "Clay"; -pdfGridRow.Cells[2].Value = "$10,000"; - -//Draw the PdfGrid. -pdfGrid.Draw(pdfPage, PointF.Empty); - -//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. - pdfDocument.Save(outputFileStream); -} - -//Close the document. -pdfDocument.Close(true); \ No newline at end of file + //Add page to the PDF document. + PdfPage pdfPage = document.Pages.Add(); + + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + + //Add three columns. + pdfGrid.Columns.Add(3); + + //Add header. + pdfGrid.Headers.Add(1); + PdfGridRow pdfGridHeader = pdfGrid.Headers[0]; + pdfGridHeader.Cells[0].Value = "Employee ID"; + pdfGridHeader.Cells[1].Value = "Employee Name"; + pdfGridHeader.Cells[2].Value = "Salary"; + + //Add rows. + PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); + pdfGridRow.Cells[0].Value = "E01"; + pdfGridRow.Cells[1].Value = "Clay"; + pdfGridRow.Cells[2].Value = "$10,000"; + + //Draw the PdfGrid. + pdfGrid.Draw(pdfPage, PointF.Empty); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfGrid/Apply-built-in-style-to-table-with-table-option/.NET/Apply-built-in-style-to-table-with-table-option/Program.cs b/Table/PdfGrid/Apply-built-in-style-to-table-with-table-option/.NET/Apply-built-in-style-to-table-with-table-option/Program.cs index a2fbcdcb..d3c19dfa 100644 --- a/Table/PdfGrid/Apply-built-in-style-to-table-with-table-option/.NET/Apply-built-in-style-to-table-with-table-option/Program.cs +++ b/Table/PdfGrid/Apply-built-in-style-to-table-with-table-option/.NET/Apply-built-in-style-to-table-with-table-option/Program.cs @@ -1,55 +1,47 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; //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 PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to list -List data = new List(); + //Add values to list + List data = new List(); -Object row1 = new { ID = "E01", Name = "Clay" }; -Object row2 = new { ID = "E02", Name = "Thomas" }; -Object row3 = new { ID = "E03", Name = "George" }; -Object row4 = new { ID = "E04", Name = "Steffen" }; -Object row5 = new { ID = "E05", Name = "Mathew" }; + Object row1 = new { ID = "E01", Name = "Clay" }; + Object row2 = new { ID = "E02", Name = "Thomas" }; + Object row3 = new { ID = "E03", Name = "George" }; + Object row4 = new { ID = "E04", Name = "Steffen" }; + Object row5 = new { ID = "E05", Name = "Mathew" }; -data.Add(row1); -data.Add(row2); -data.Add(row3); -data.Add(row4); -data.Add(row5); + data.Add(row1); + data.Add(row2); + data.Add(row3); + data.Add(row4); + data.Add(row5); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -PdfGridBuiltinStyleSettings tableStyleOption = new PdfGridBuiltinStyleSettings(); -tableStyleOption.ApplyStyleForBandedRows = true; -tableStyleOption.ApplyStyleForHeaderRow = true; + PdfGridBuiltinStyleSettings tableStyleOption = new PdfGridBuiltinStyleSettings(); + tableStyleOption.ApplyStyleForBandedRows = true; + tableStyleOption.ApplyStyleForHeaderRow = true; -//Apply built-in table style. -pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent4, tableStyleOption); + //Apply built-in table style. + pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent4, tableStyleOption); -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); + //Draw grid to the page of PDF document. + pdfGrid.Draw(page, new Syncfusion.Drawing.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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Table/PdfGrid/Apply-string-formatting-for-whole-table-in-a-PDF/.NET/Apply-string-formatting-for-whole-table-in-a-PDF/Program.cs b/Table/PdfGrid/Apply-string-formatting-for-whole-table-in-a-PDF/.NET/Apply-string-formatting-for-whole-table-in-a-PDF/Program.cs index 21f37b04..5e3e29f9 100644 --- a/Table/PdfGrid/Apply-string-formatting-for-whole-table-in-a-PDF/.NET/Apply-string-formatting-for-whole-table-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Apply-string-formatting-for-whole-table-in-a-PDF/.NET/Apply-string-formatting-for-whole-table-in-a-PDF/Program.cs @@ -1,56 +1,48 @@ -// 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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); +using (PdfDocument document = new PdfDocument()) +{ + //Add page to the document + PdfPage page = document.Pages.Add(); -//Add page to the document -PdfPage page = document.Pages.Add(); + //Create a new PdfGrid. + PdfGrid grid = new PdfGrid(); -//Create a new PdfGrid. -PdfGrid grid = new PdfGrid(); + //Add values to list. + List data = new List(); + Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; + Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; + Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; -//Add values to list. -List data = new List(); -Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" }; -Object grid1row2 = new { ID = "E02", Name = "Thomas", Salary = "$10,500" }; -Object grid1row3 = new { ID = "E03", Name = "Simon", Salary = "$12,000" }; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Assign data source. + grid.DataSource = dataTable; -//Assign data source. -grid.DataSource = dataTable; + //Create and customize the string formats. + PdfStringFormat stringFormat = new PdfStringFormat(); + stringFormat.Alignment = PdfTextAlignment.Center; + stringFormat.LineAlignment = PdfVerticalAlignment.Middle; + stringFormat.CharacterSpacing = 2f; -//Create and customize the string formats. -PdfStringFormat stringFormat = new PdfStringFormat(); -stringFormat.Alignment = PdfTextAlignment.Center; -stringFormat.LineAlignment = PdfVerticalAlignment.Middle; -stringFormat.CharacterSpacing = 2f; + //Apply string formatting for whole table. + for (int i = 0; i < grid.Columns.Count; i++) + { + grid.Columns[i].Format = stringFormat; + } -//Apply string formatting for whole table. -for (int i = 0; i < grid.Columns.Count; i++) -{ - grid.Columns[i].Format = stringFormat; -} + //Draw the PdfGrid on page. + grid.Draw(page, new PointF(10, 10)); -//Draw the PdfGrid on page. -grid.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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Apply-word-wrap-in-the-PDF-table-cell/.NET/Apply-word-wrap-in-the-PDF-table-cell/Program.cs b/Table/PdfGrid/Apply-word-wrap-in-the-PDF-table-cell/.NET/Apply-word-wrap-in-the-PDF-table-cell/Program.cs index d3968a06..6fdd32d2 100644 --- a/Table/PdfGrid/Apply-word-wrap-in-the-PDF-table-cell/.NET/Apply-word-wrap-in-the-PDF-table-cell/Program.cs +++ b/Table/PdfGrid/Apply-word-wrap-in-the-PDF-table-cell/.NET/Apply-word-wrap-in-the-PDF-table-cell/Program.cs @@ -1,60 +1,52 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; 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 PdfGrid. -PdfGrid grid = new PdfGrid(); + //Create a PdfGrid. + PdfGrid grid = new PdfGrid(); -//Add values to the list. -List data = new List(); + //Add values to the list. + List data = new List(); -object row1 = new { CustomerID = "ALFKI", CompanyName = "Alfreds Futterkiste", ContactName = "Maria Anders", Address = "Obere Str. 57", City = "Berlin", PostalCode = "12209", Country = "Germany" }; -object row2 = new { CustomerID = "ANATR", CompanyName = "Ana Trujillo Emparedados yhelados", ContactName = "Ana Trujillo", Address = "Avda. de la Constitucion 2222", City = "Mexico D.F.", PostalCode = "05021", Country = "Mexico" }; -object row3 = new { CustomerID = "ANTON", CompanyName = "Antonio Moreno Taqueria", ContactName = "Antonio Moreno", Address = "Mataderos 2312", City = "Mexico D.F.", PostalCode = "05023", Country = "Mexico" }; + object row1 = new { CustomerID = "ALFKI", CompanyName = "Alfreds Futterkiste", ContactName = "Maria Anders", Address = "Obere Str. 57", City = "Berlin", PostalCode = "12209", Country = "Germany" }; + object row2 = new { CustomerID = "ANATR", CompanyName = "Ana Trujillo Emparedados yhelados", ContactName = "Ana Trujillo", Address = "Avda. de la Constitucion 2222", City = "Mexico D.F.", PostalCode = "05021", Country = "Mexico" }; + object row3 = new { CustomerID = "ANTON", CompanyName = "Antonio Moreno Taqueria", ContactName = "Antonio Moreno", Address = "Mataderos 2312", City = "Mexico D.F.", PostalCode = "05023", Country = "Mexico" }; -data.Add(row1); -data.Add(row2); -data.Add(row3); + data.Add(row1); + data.Add(row2); + data.Add(row3); -//Add list to the IEnumerable -IEnumerable dataTable = data; + //Add list to the IEnumerable + IEnumerable dataTable = data; -//Assign data source. -grid.DataSource = dataTable; + //Assign data source. + grid.DataSource = dataTable; -//Create a new instance for string format. -PdfStringFormat format = new PdfStringFormat(); + //Create a new instance for string format. + PdfStringFormat format = new PdfStringFormat(); -//Set a word wrap to string format. -format.WordWrap = PdfWordWrapType.Word; + //Set a word wrap to string format. + format.WordWrap = PdfWordWrapType.Word; -//Set the word wrapping in the PDF table cell. -foreach (PdfGridRow row in grid.Headers) -{ - foreach (PdfGridCell cell in row.Cells) + //Set the word wrapping in the PDF table cell. + foreach (PdfGridRow row in grid.Headers) { - cell.Style.StringFormat = format; + foreach (PdfGridCell cell in row.Cells) + { + cell.Style.StringFormat = format; + } } -} -//Draw a grid to the resultant page of the first grid. -grid.Draw(page, new PointF(10, 20)); + //Draw a grid to the resultant page of the first grid. + grid.Draw(page, new PointF(10, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Applying-Customizing-Styles-in-PDF-Grid/.NET/Applying-Customizing-Styles-in-PDF-Grid/Program.cs b/Table/PdfGrid/Applying-Customizing-Styles-in-PDF-Grid/.NET/Applying-Customizing-Styles-in-PDF-Grid/Program.cs index ef0b599a..8ddade83 100644 --- a/Table/PdfGrid/Applying-Customizing-Styles-in-PDF-Grid/.NET/Applying-Customizing-Styles-in-PDF-Grid/Program.cs +++ b/Table/PdfGrid/Applying-Customizing-Styles-in-PDF-Grid/.NET/Applying-Customizing-Styles-in-PDF-Grid/Program.cs @@ -5,44 +5,40 @@ using Syncfusion.Drawing; //Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Add a page. -PdfPage page = document.Pages.Add(); -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); -//Create a DataTable. -DataTable dataTable = new DataTable(); -//Add columns to the DataTable -dataTable.Columns.Add("ID"); -dataTable.Columns.Add("Name"); -//Add rows to the DataTable. -dataTable.Rows.Add(new object[] { "E01", "Clay" }); -dataTable.Rows.Add(new object[] { "E02", "Thomas" }); -//Assign data source. -pdfGrid.DataSource = dataTable; +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + //Create a DataTable. + DataTable dataTable = new DataTable(); + //Add columns to the DataTable + dataTable.Columns.Add("ID"); + dataTable.Columns.Add("Name"); + //Add rows to the DataTable. + dataTable.Rows.Add(new object[] { "E01", "Clay" }); + dataTable.Rows.Add(new object[] { "E02", "Thomas" }); + //Assign data source. + pdfGrid.DataSource = dataTable; -//Create Cell Style -PdfGridCellStyle headerStyle = new PdfGridCellStyle(); -headerStyle.TextBrush = PdfBrushes.Red; -headerStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.LightBlue); -//Apply style to the header row -pdfGrid.Headers[0].ApplyStyle(headerStyle); + //Create Cell Style + PdfGridCellStyle headerStyle = new PdfGridCellStyle(); + headerStyle.TextBrush = PdfBrushes.Red; + headerStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.LightBlue); + //Apply style to the header row + pdfGrid.Headers[0].ApplyStyle(headerStyle); -//Create Cell Style -PdfGridCellStyle rowStyle = new PdfGridCellStyle(); -rowStyle.TextBrush = PdfBrushes.Cyan; -rowStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.YellowGreen); -//Apply style to the first row -pdfGrid.Rows[0].ApplyStyle(rowStyle); + //Create Cell Style + PdfGridCellStyle rowStyle = new PdfGridCellStyle(); + rowStyle.TextBrush = PdfBrushes.Cyan; + rowStyle.BackgroundBrush = new PdfSolidBrush(Syncfusion.Drawing.Color.YellowGreen); + //Apply style to the first row + pdfGrid.Rows[0].ApplyStyle(rowStyle); -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new PointF(10, 10)); + //Draw grid to the page of PDF document. + pdfGrid.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); -} -//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/PdfGrid/Automatically-adjust-the-table-width-in-a-PDF/.NET/Automatically-adjust-the-table-width-in-a-PDF/Program.cs b/Table/PdfGrid/Automatically-adjust-the-table-width-in-a-PDF/.NET/Automatically-adjust-the-table-width-in-a-PDF/Program.cs index cba8a81b..e3be4539 100644 --- a/Table/PdfGrid/Automatically-adjust-the-table-width-in-a-PDF/.NET/Automatically-adjust-the-table-width-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Automatically-adjust-the-table-width-in-a-PDF/.NET/Automatically-adjust-the-table-width-in-a-PDF/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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add new section to the document. -PdfSection section = document.Sections.Add(); - -//Add a page to the section. -PdfPage page = section.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add new section to the document. + PdfSection section = document.Sections.Add(); -//Initialize PdfGrid. -PdfGrid grid = new PdfGrid(); + //Add a page to the section. + PdfPage page = section.Pages.Add(); -//Add values to list. -List data = new List(); -Object grid1row1 = new { Employee_ID = "E01", Employee_Name = "Clay", Employee_Role = "Sales Representative", Employee_DateOfBirth = "12/8/1948" }; -Object grid1row2 = new { Employee_ID = "E02", Employee_Name = "Thomas", Employee_Role = "Sales Representative", Employee_DateOfBirth = "7/2/1963" }; -Object grid1row3 = new { Employee_ID = "E03", Employee_Name = "Ash", Employee_Role = "Sales Manager", Employee_DateOfBirth = "3/4/1955" }; -Object grid1row4 = new { Employee_ID = "E04", Employee_Name = "Andrew", Employee_Role = "Vice President, Sales", Employee_DateOfBirth = "2/19/1952" }; + //Initialize PdfGrid. + PdfGrid grid = new PdfGrid(); -data.Add(grid1row1); -data.Add(grid1row2); -data.Add(grid1row3); -data.Add(grid1row4); + //Add values to list. + List data = new List(); + Object grid1row1 = new { Employee_ID = "E01", Employee_Name = "Clay", Employee_Role = "Sales Representative", Employee_DateOfBirth = "12/8/1948" }; + Object grid1row2 = new { Employee_ID = "E02", Employee_Name = "Thomas", Employee_Role = "Sales Representative", Employee_DateOfBirth = "7/2/1963" }; + Object grid1row3 = new { Employee_ID = "E03", Employee_Name = "Ash", Employee_Role = "Sales Manager", Employee_DateOfBirth = "3/4/1955" }; + Object grid1row4 = new { Employee_ID = "E04", Employee_Name = "Andrew", Employee_Role = "Vice President, Sales", Employee_DateOfBirth = "2/19/1952" }; -//Add list to IEnumerable. -IEnumerable dataTable = data; + data.Add(grid1row1); + data.Add(grid1row2); + data.Add(grid1row3); + data.Add(grid1row4); -//Assign data source to grid. -grid.DataSource = dataTable; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Apply the table style. -grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable5DarkAccent5); + //Assign data source to grid. + grid.DataSource = dataTable; -//Allow the horizontal overflow for PdfGrid. -grid.Style.AllowHorizontalOverflow = true; + //Apply the table style. + grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable5DarkAccent5); -//Draw the PdfGrid on page. -grid.Draw(page, PointF.Empty); + //Allow the horizontal overflow for PdfGrid. + grid.Style.AllowHorizontalOverflow = 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 PdfGrid on page. + grid.Draw(page, 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/PdfGrid/Cell-customization-in-PdfGrid/.NET/Cell-customization-in-PdfGrid/Program.cs b/Table/PdfGrid/Cell-customization-in-PdfGrid/.NET/Cell-customization-in-PdfGrid/Program.cs index 7029a052..a9c75ddb 100644 --- a/Table/PdfGrid/Cell-customization-in-PdfGrid/.NET/Cell-customization-in-PdfGrid/Program.cs +++ b/Table/PdfGrid/Cell-customization-in-PdfGrid/.NET/Cell-customization-in-PdfGrid/Program.cs @@ -1,74 +1,66 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create the parent grid. -PdfGrid parentPdfGrid = new PdfGrid(); + //Create the parent grid. + PdfGrid parentPdfGrid = new PdfGrid(); -//Add the rows. -PdfGridRow row1 = parentPdfGrid.Rows.Add(); -PdfGridRow row2 = parentPdfGrid.Rows.Add(); -row2.Height = 58; + //Add the rows. + PdfGridRow row1 = parentPdfGrid.Rows.Add(); + PdfGridRow row2 = parentPdfGrid.Rows.Add(); + row2.Height = 58; -//Add the columns. -parentPdfGrid.Columns.Add(3); + //Add the columns. + parentPdfGrid.Columns.Add(3); -//Set the value to the specific cell. -parentPdfGrid.Rows[0].Cells[0].Value = "Nested Table"; -parentPdfGrid.Rows[0].Cells[1].RowSpan = 2; -parentPdfGrid.Rows[0].Cells[1].ColumnSpan = 2; + //Set the value to the specific cell. + parentPdfGrid.Rows[0].Cells[0].Value = "Nested Table"; + parentPdfGrid.Rows[0].Cells[1].RowSpan = 2; + parentPdfGrid.Rows[0].Cells[1].ColumnSpan = 2; -//Create the child table. -PdfGrid childPdfGrid = new PdfGrid(); + //Create the child table. + PdfGrid childPdfGrid = new PdfGrid(); -//Set the column and rows for child grid. -childPdfGrid.Columns.Add(5); + //Set the column and rows for child grid. + childPdfGrid.Columns.Add(5); -for (int i = 0; i < 5; i++) -{ - PdfGridRow row = childPdfGrid.Rows.Add(); - for (int j = 0; j < 5; j++) + for (int i = 0; i < 5; i++) { - row.Cells[j].Value = String.Format("Cell [{0} {1}]", j, i); + PdfGridRow row = childPdfGrid.Rows.Add(); + for (int j = 0; j < 5; j++) + { + row.Cells[j].Value = String.Format("Cell [{0} {1}]", j, i); + } } -} - -//Set the value as another PdfGrid in a cell. -parentPdfGrid.Rows[0].Cells[1].Value = childPdfGrid; -//Specify the style for the PdfGridCell. -PdfGridCellStyle pdfGridCellStyle = new PdfGridCellStyle(); -pdfGridCellStyle.TextPen = PdfPens.Red; -pdfGridCellStyle.Borders.All = PdfPens.Red; + //Set the value as another PdfGrid in a cell. + parentPdfGrid.Rows[0].Cells[1].Value = childPdfGrid; -//Load image as stream. -FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Image.jpg"), FileMode.Open, FileAccess.Read); -pdfGridCellStyle.BackgroundImage = new PdfBitmap(imageStream); -PdfGridCell pdfGridCell = parentPdfGrid.Rows[1].Cells[0]; + //Specify the style for the PdfGridCell. + PdfGridCellStyle pdfGridCellStyle = new PdfGridCellStyle(); + pdfGridCellStyle.TextPen = PdfPens.Red; + pdfGridCellStyle.Borders.All = PdfPens.Red; -//Apply style. -pdfGridCell.Style = pdfGridCellStyle; + //Load image as stream. + FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Image.jpg"), FileMode.Open, FileAccess.Read); + pdfGridCellStyle.BackgroundImage = new PdfBitmap(imageStream); + PdfGridCell pdfGridCell = parentPdfGrid.Rows[1].Cells[0]; -//Set image position for the background image in the style. -pdfGridCell.ImagePosition = PdfGridImagePosition.Fit; + //Apply style. + pdfGridCell.Style = pdfGridCellStyle; -//Draw the PdfGrid. -parentPdfGrid.Draw(pdfPage, Syncfusion.Drawing.PointF.Empty); + //Set image position for the background image in the style. + pdfGridCell.ImagePosition = PdfGridImagePosition.Fit; -//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 PdfGrid. + parentPdfGrid.Draw(pdfPage, Syncfusion.Drawing.PointF.Empty); -//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/Table/PdfGrid/Changing-Margins-from-the-Second-Page-onwards/.NET/Changing-Margins-from-the-Second-Page-onwards/Program.cs b/Table/PdfGrid/Changing-Margins-from-the-Second-Page-onwards/.NET/Changing-Margins-from-the-Second-Page-onwards/Program.cs index 5c82d426..cc8d811e 100644 --- a/Table/PdfGrid/Changing-Margins-from-the-Second-Page-onwards/.NET/Changing-Margins-from-the-Second-Page-onwards/Program.cs +++ b/Table/PdfGrid/Changing-Margins-from-the-Second-Page-onwards/.NET/Changing-Margins-from-the-Second-Page-onwards/Program.cs @@ -2,51 +2,45 @@ using Syncfusion.Pdf; using Syncfusion.Drawing; -// Create PDF document -PdfDocument document = new PdfDocument(); - -// Configure marginless page layout -document.PageSettings.Margins.Top = 0; -document.PageSettings.Margins.Bottom = 0; - -// Add first page to the document -PdfPage page = document.Pages.Add(); - -// Initialize grid component for data presentation -PdfGrid pdfGrid = new PdfGrid(); - -// Generate sample data (300 rows) -List data = new List(); -for (int i = 0; i < 100; i++) +//Create a new PDF document. +using (PdfDocument document = new PdfDocument()) { - // Create three unique rows per iteration - data.Add(new { ID = "1", Name = "Clay", Price = "$10" }); - data.Add(new { ID = "2", Name = "Gray", Price = "$20" }); - data.Add(new { ID = "3", Name = "Ash", Price = "$30" }); -} - -// Configure grid data binding -pdfGrid.DataSource = data; // Automatic conversion to IEnumerable - -// Set up grid layout with header space -PdfGridLayoutFormat format = new PdfGridLayoutFormat -{ - PaginateBounds = new RectangleF(0, 15, + // Configure marginless page layout + document.PageSettings.Margins.Top = 0; + document.PageSettings.Margins.Bottom = 0; + + // Add first page to the document + PdfPage page = document.Pages.Add(); + + // Initialize grid component for data presentation + PdfGrid pdfGrid = new PdfGrid(); + + // Generate sample data (300 rows) + List data = new List(); + for (int i = 0; i < 100; i++) + { + // Create three unique rows per iteration + data.Add(new { ID = "1", Name = "Clay", Price = "$10" }); + data.Add(new { ID = "2", Name = "Gray", Price = "$20" }); + data.Add(new { ID = "3", Name = "Ash", Price = "$30" }); + } + + // Configure grid data binding + pdfGrid.DataSource = data; // Automatic conversion to IEnumerable + + // Set up grid layout with header space + PdfGridLayoutFormat format = new PdfGridLayoutFormat + { + PaginateBounds = new RectangleF(0, 15, page.GetClientSize().Width, page.GetClientSize().Height - 15) -}; + }; -// Render grid to page with automatic pagination -pdfGrid.Draw(page, new RectangleF(0, 0, + // Render grid to page with automatic pagination + pdfGrid.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); -//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); -} - -// Proper document cleanup -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/PdfGrid/Column-customization-of-PdfGrid-in-a-PDF/.NET/Column-customization-of-PdfGrid-in-a-PDF/Program.cs b/Table/PdfGrid/Column-customization-of-PdfGrid-in-a-PDF/.NET/Column-customization-of-PdfGrid-in-a-PDF/Program.cs index 9494280e..7c9da422 100644 --- a/Table/PdfGrid/Column-customization-of-PdfGrid-in-a-PDF/.NET/Column-customization-of-PdfGrid-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Column-customization-of-PdfGrid-in-a-PDF/.NET/Column-customization-of-PdfGrid-in-a-PDF/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.Grid; using System.Data; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add a page to PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page to PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Create a DataTable. -DataTable dataTable = new DataTable(); + //Create a DataTable. + DataTable dataTable = new DataTable(); -//Add columns to the DataTable. -dataTable.Columns.Add("ID"); -dataTable.Columns.Add("Name"); + //Add columns to the DataTable. + dataTable.Columns.Add("ID"); + dataTable.Columns.Add("Name"); -//Add rows to the DataTable. -dataTable.Rows.Add(new object[] { "E01", "John" }); -dataTable.Rows.Add(new object[] { "E02", "Thomas" }); -dataTable.Rows.Add(new object[] { "E03", "Peter" }); + //Add rows to the DataTable. + dataTable.Rows.Add(new object[] { "E01", "John" }); + dataTable.Rows.Add(new object[] { "E02", "Thomas" }); + dataTable.Rows.Add(new object[] { "E03", "Peter" }); -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Set the width. -pdfGrid.Columns[1].Width = 50; + //Set the width. + pdfGrid.Columns[1].Width = 50; -//Create and customize the string formats. -PdfStringFormat format = new PdfStringFormat(); -format.Alignment = PdfTextAlignment.Center; -format.LineAlignment = PdfVerticalAlignment.Bottom; + //Create and customize the string formats. + PdfStringFormat format = new PdfStringFormat(); + format.Alignment = PdfTextAlignment.Center; + format.LineAlignment = PdfVerticalAlignment.Bottom; -//Set the column text format. -pdfGrid.Columns[0].Format = format; + //Set the column text format. + pdfGrid.Columns[0].Format = format; -//Draw the PdfGrid. -PdfGridLayoutResult result = pdfGrid.Draw(pdfPage, PointF.Empty); + //Draw the PdfGrid. + PdfGridLayoutResult result = pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/Table/PdfGrid/Create-nested-table-in-a-PDF-document/.NET/Create-nested-table-in-a-PDF-document/Program.cs b/Table/PdfGrid/Create-nested-table-in-a-PDF-document/.NET/Create-nested-table-in-a-PDF-document/Program.cs index 6d024568..1ed22b4f 100644 --- a/Table/PdfGrid/Create-nested-table-in-a-PDF-document/.NET/Create-nested-table-in-a-PDF-document/Program.cs +++ b/Table/PdfGrid/Create-nested-table-in-a-PDF-document/.NET/Create-nested-table-in-a-PDF-document/Program.cs @@ -1,68 +1,60 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Grid; +using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; using Syncfusion.Drawing; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create the parent grid. -PdfGrid parentPdfGrid = new PdfGrid(); + //Create the parent grid. + PdfGrid parentPdfGrid = new PdfGrid(); -//Add columns in the parent grid. -parentPdfGrid.Columns.Add(3); -parentPdfGrid.Columns[2].Width = 300; + //Add columns in the parent grid. + parentPdfGrid.Columns.Add(3); + parentPdfGrid.Columns[2].Width = 300; -//Add the rows in the parent grid. -PdfGridRow row1 = parentPdfGrid.Rows.Add(); -row1.Cells[0].Value = "Employee ID"; -row1.Cells[1].Value = "Employee Name"; -row1.Cells[2].Value = "Contact Details"; + //Add the rows in the parent grid. + PdfGridRow row1 = parentPdfGrid.Rows.Add(); + row1.Cells[0].Value = "Employee ID"; + row1.Cells[1].Value = "Employee Name"; + row1.Cells[2].Value = "Contact Details"; -//Add the rows in the parent grid. -PdfGridRow row2 = parentPdfGrid.Rows.Add(); -row2.Cells[0].Value = "E01"; -row2.Cells[1].Value = "Clay"; + //Add the rows in the parent grid. + PdfGridRow row2 = parentPdfGrid.Rows.Add(); + row2.Cells[0].Value = "E01"; + row2.Cells[1].Value = "Clay"; -//Create the child table. -PdfGrid childPdfGrid = new PdfGrid(); + //Create the child table. + PdfGrid childPdfGrid = new PdfGrid(); -//Add columns to the child grid. -childPdfGrid.Columns.Add(2); + //Add columns to the child grid. + childPdfGrid.Columns.Add(2); -//Add the rows to the child grid. -PdfGridRow childRow1 = childPdfGrid.Rows.Add(); -childRow1.Cells[0].Value = "Phone"; -childRow1.Cells[1].Value = "31 12 34 56"; + //Add the rows to the child grid. + PdfGridRow childRow1 = childPdfGrid.Rows.Add(); + childRow1.Cells[0].Value = "Phone"; + childRow1.Cells[1].Value = "31 12 34 56"; -PdfGridRow childRow2 = childPdfGrid.Rows.Add(); -childRow2.Cells[0].Value = "Email"; -childRow2.Cells[1].Value = "simonsbistro@outlook.com"; + PdfGridRow childRow2 = childPdfGrid.Rows.Add(); + childRow2.Cells[0].Value = "Email"; + childRow2.Cells[1].Value = "simonsbistro@outlook.com"; -PdfGridRow childRow3 = childPdfGrid.Rows.Add(); -childRow3.Cells[0].Value = "Address"; -childRow3.Cells[1].Value = "Vinbaeltet 34, Denmark"; + PdfGridRow childRow3 = childPdfGrid.Rows.Add(); + childRow3.Cells[0].Value = "Address"; + childRow3.Cells[1].Value = "Vinbaeltet 34, Denmark"; -//Set the value as another child grid in a cell. -parentPdfGrid.Rows[1].Cells[2].Value = childPdfGrid; + //Set the value as another child grid in a cell. + parentPdfGrid.Rows[1].Cells[2].Value = childPdfGrid; -//Set padding for child grid. -parentPdfGrid.Rows[1].Cells[2].Style.CellPadding = new PdfPaddings(5, 5, 5, 5); + //Set padding for child grid. + parentPdfGrid.Rows[1].Cells[2].Style.CellPadding = new PdfPaddings(5, 5, 5, 5); -//Draw the parent PdfGrid -parentPdfGrid.Draw(pdfPage, PointF.Empty); + //Draw the parent PdfGrid + parentPdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs b/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs index 8d341883..61e343a8 100644 --- a/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs @@ -1,11 +1,9 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Drawing; +using Syncfusion.Drawing; using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; using System.Data; -//Create a new PDF document +//Create a new PDF document. using (PdfDocument document = new PdfDocument()) { //Add a page @@ -26,10 +24,6 @@ //Draw the grid to the page of PDF document pdfGrid.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); - } + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } \ No newline at end of file diff --git a/Table/PdfGrid/Create-table-from-list-in-a-PDF-document/.NET/Create-table-from-list-in-a-PDF-document/Program.cs b/Table/PdfGrid/Create-table-from-list-in-a-PDF-document/.NET/Create-table-from-list-in-a-PDF-document/Program.cs index 60d2a87e..5cea6c55 100644 --- a/Table/PdfGrid/Create-table-from-list-in-a-PDF-document/.NET/Create-table-from-list-in-a-PDF-document/Program.cs +++ b/Table/PdfGrid/Create-table-from-list-in-a-PDF-document/.NET/Create-table-from-list-in-a-PDF-document/Program.cs @@ -1,43 +1,35 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); - -//Add a page. -PdfPage page = document.Pages.Add(); - -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page. + PdfPage page = document.Pages.Add(); -//Add values to list -List data = new List(); -Object row1 = new { ID = "1", Name = "Clay" }; -Object row2 = new { ID = "2", Name = "Gray" }; -Object row3 = new { ID = "3", Name = "Ash" }; + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add rows to the list. -data.Add(row1); -data.Add(row2); -data.Add(row3); + //Add values to list + List data = new List(); + Object row1 = new { ID = "1", Name = "Clay" }; + Object row2 = new { ID = "2", Name = "Gray" }; + Object row3 = new { ID = "3", Name = "Ash" }; -//Add list to IEnumerable. -IEnumerable tableData = data; + //Add rows to the list. + data.Add(row1); + data.Add(row2); + data.Add(row3); -//Assign data source. -pdfGrid.DataSource = tableData; + //Add list to IEnumerable. + IEnumerable tableData = data; -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); + //Assign data source. + pdfGrid.DataSource = tableData; -//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 grid to the page of PDF document. + pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); -//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/PdfGrid/Create-table-in-an-existing-document/.NET/Create-table-in-an-existing-document/Program.cs b/Table/PdfGrid/Create-table-in-an-existing-document/.NET/Create-table-in-an-existing-document/Program.cs index b4276042..fddf9038 100644 --- a/Table/PdfGrid/Create-table-in-an-existing-document/.NET/Create-table-in-an-existing-document/Program.cs +++ b/Table/PdfGrid/Create-table-in-an-existing-document/.NET/Create-table-in-an-existing-document/Program.cs @@ -1,48 +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.Grid; 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 first page from document. -PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; - -//Create PDF graphics for the page. -PdfGraphics graphics = page.Graphics; - -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); +//Load the PDF document. +using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"))) +{ + //Get first page from document. + PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage; -//Add values to list -List data = new List(); -Object row1 = new { ID = "1", Name = "Clay" }; -Object row2 = new { ID = "2", Name = "Thomas" }; -data.Add(row1); -data.Add(row2); + //Create PDF graphics for the page. + PdfGraphics graphics = page.Graphics; -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Assign data source. -pdfGrid.DataSource = dataTable; + //Add values to list + List data = new List(); + Object row1 = new { ID = "1", Name = "Clay" }; + Object row2 = new { ID = "2", Name = "Thomas" }; + data.Add(row1); + data.Add(row2); -//Draw grid to the page of PDF document. -pdfGrid.Draw(graphics, new Syncfusion.Drawing.PointF(10, 30)); + //Add list to IEnumerable. + IEnumerable dataTable = data; -//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 data source. + pdfGrid.DataSource = dataTable; -//Close the document. -loadedDocument.Close(true); + //Draw grid to the page of PDF document. + pdfGrid.Draw(graphics, new Syncfusion.Drawing.PointF(10, 30)); + //Save the PDF document + loadedDocument.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file diff --git a/Table/PdfGrid/Create-table-with-built-in-style/.NET/Create-table-with-built-in-style/Program.cs b/Table/PdfGrid/Create-table-with-built-in-style/.NET/Create-table-with-built-in-style/Program.cs index 83daa4af..53847690 100644 --- a/Table/PdfGrid/Create-table-with-built-in-style/.NET/Create-table-with-built-in-style/Program.cs +++ b/Table/PdfGrid/Create-table-with-built-in-style/.NET/Create-table-with-built-in-style/Program.cs @@ -1,50 +1,42 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Grid; //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 PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to list. -List data = new List(); -Object row1 = new { ID = "E01", Name = "Clay" }; -Object row2 = new { ID = "E02", Name = "Thomas" }; -Object row3 = new { ID = "E03", Name = "George" }; -Object row4 = new { ID = "E04", Name = "Steffen" }; -Object row5 = new { ID = "E05", Name = "Mathew" }; + //Add values to list. + List data = new List(); + Object row1 = new { ID = "E01", Name = "Clay" }; + Object row2 = new { ID = "E02", Name = "Thomas" }; + Object row3 = new { ID = "E03", Name = "George" }; + Object row4 = new { ID = "E04", Name = "Steffen" }; + Object row5 = new { ID = "E05", Name = "Mathew" }; -data.Add(row1); -data.Add(row2); -data.Add(row3); -data.Add(row4); -data.Add(row5); + data.Add(row1); + data.Add(row2); + data.Add(row3); + data.Add(row4); + data.Add(row5); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Apply built-in table style. -pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); + //Apply built-in table style. + pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); + //Draw grid to the page of PDF document. + pdfGrid.Draw(page, new Syncfusion.Drawing.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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -document.Close(true); - diff --git a/Table/PdfGrid/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs b/Table/PdfGrid/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs index 1897d1c0..8ffd1ad4 100644 --- a/Table/PdfGrid/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/Program.cs +++ b/Table/PdfGrid/Customize-the-table-in-a-PDF-document/.NET/Customize-the-table-in-a-PDF-document/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.Grid; //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 PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to list. -List data = new List(); -Object row1 = new { ID = "E01", Name = "Clay" }; -Object row2 = new { ID = "E02", Name = "Thomas" }; + //Add values to list. + List data = new List(); + Object row1 = new { ID = "E01", Name = "Clay" }; + Object row2 = new { ID = "E02", Name = "Thomas" }; -//Add rows to list. -data.Add(row1); -data.Add(row2); + //Add rows to list. + data.Add(row1); + data.Add(row2); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Declare and define the grid style -PdfGridStyle gridStyle = new PdfGridStyle(); + //Declare and define the grid style + PdfGridStyle gridStyle = new PdfGridStyle(); -//Set cell padding, which specifies the space between border and content of the cell. -gridStyle.CellPadding = new PdfPaddings(2, 2, 2, 2); + //Set cell padding, which specifies the space between border and content of the cell. + gridStyle.CellPadding = new PdfPaddings(2, 2, 2, 2); -//Set cell spacing, which specifies the space between the adjacent cells. -gridStyle.CellSpacing = 2; + //Set cell spacing, which specifies the space between the adjacent cells. + gridStyle.CellSpacing = 2; -//Enable to adjust PDF table row width based on the text length. -gridStyle.AllowHorizontalOverflow = true; + //Enable to adjust PDF table row width based on the text length. + gridStyle.AllowHorizontalOverflow = true; -//Apply style. -pdfGrid.Style = gridStyle; + //Apply style. + pdfGrid.Style = gridStyle; -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new PointF(10, 10)); + //Draw grid to the page of PDF document. + pdfGrid.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); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -document.Close(true); diff --git a/Table/PdfGrid/Draw-HTML-styled-text-in-a-PDF-table-cell/.NET/Draw-HTML-styled-text-in-a-PDF-table-cell/Program.cs b/Table/PdfGrid/Draw-HTML-styled-text-in-a-PDF-table-cell/.NET/Draw-HTML-styled-text-in-a-PDF-table-cell/Program.cs index 299ee2b1..8d1f2c32 100644 --- a/Table/PdfGrid/Draw-HTML-styled-text-in-a-PDF-table-cell/.NET/Draw-HTML-styled-text-in-a-PDF-table-cell/Program.cs +++ b/Table/PdfGrid/Draw-HTML-styled-text-in-a-PDF-table-cell/.NET/Draw-HTML-styled-text-in-a-PDF-table-cell/Program.cs @@ -1,48 +1,40 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using Syncfusion.Drawing; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add columns. -pdfGrid.Columns.Add(2); + //Add columns. + pdfGrid.Columns.Add(2); -//Add row and cell values. -PdfGridRow row1 = pdfGrid.Rows.Add(); -row1.Cells[0].Value = "Product Name"; -row1.Cells[1].Value = "Description"; + //Add row and cell values. + PdfGridRow row1 = pdfGrid.Rows.Add(); + row1.Cells[0].Value = "Product Name"; + row1.Cells[1].Value = "Description"; -//Add row and cell values. -PdfGridRow row2 = pdfGrid.Rows.Add(); -row2.Cells[0].Value = "Essential PDF"; + //Add row and cell values. + PdfGridRow row2 = pdfGrid.Rows.Add(); + row2.Cells[0].Value = "Essential PDF"; -//Render the HTML text. -string htmlText = "Essential PDF is a .NET library " + "with the capability to produce Adobe PDF files ."; -PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, new PdfStandardFont(PdfFontFamily.TimesRoman, 12), PdfBrushes.Black); + //Render the HTML text. + string htmlText = "Essential PDF is a .NET library " + "with the capability to produce Adobe PDF files ."; + PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, new PdfStandardFont(PdfFontFamily.TimesRoman, 12), PdfBrushes.Black); -//Set the HTML styled text value to the table cell. -row2.Cells[1].Value = richTextElement; + //Set the HTML styled text value to the table cell. + row2.Cells[1].Value = richTextElement; -//Draw the PdfGrid. -pdfGrid.Draw(pdfPage, PointF.Empty); + //Draw the PdfGrid. + pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); \ No newline at end of file diff --git a/Table/PdfGrid/Draw-borderless-table-in-PDF-document/.NET/Draw-borderless-table-in-PDF-document/Program.cs b/Table/PdfGrid/Draw-borderless-table-in-PDF-document/.NET/Draw-borderless-table-in-PDF-document/Program.cs index 626f4477..1e09fd91 100644 --- a/Table/PdfGrid/Draw-borderless-table-in-PDF-document/.NET/Draw-borderless-table-in-PDF-document/Program.cs +++ b/Table/PdfGrid/Draw-borderless-table-in-PDF-document/.NET/Draw-borderless-table-in-PDF-document/Program.cs @@ -1,85 +1,77 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; using Syncfusion.Drawing; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to the list. -List data = new List(); + //Add values to the list. + List data = new List(); -Object row1 = new { RollNumber = "E01", Name = "Maxim", Class = "IV" }; -Object row2 = new { RollNumber = "E02", Name = "Clay", Class = "IV" }; + Object row1 = new { RollNumber = "E01", Name = "Maxim", Class = "IV" }; + Object row2 = new { RollNumber = "E02", Name = "Clay", Class = "IV" }; -data.Add(row1); -data.Add(row2); + data.Add(row1); + data.Add(row2); -//Add list to the IEnumerable. -IEnumerable dataTable = data; + //Add list to the IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Declare and define the table cell style. -PdfGridCellStyle headerStyle = new PdfGridCellStyle(); + //Declare and define the table cell style. + PdfGridCellStyle headerStyle = new PdfGridCellStyle(); -//Set the border color for the table. -headerStyle.Borders.All = new PdfPen(Color.Transparent); + //Set the border color for the table. + headerStyle.Borders.All = new PdfPen(Color.Transparent); -//Set the text color for the header. -headerStyle.TextBrush = PdfBrushes.Red; + //Set the text color for the header. + headerStyle.TextBrush = PdfBrushes.Red; -//Apply the cell style for the header cells. -for (int i = 0; i < pdfGrid.Headers[0].Cells.Count; i++) -{ - //Get the header cell. - PdfGridCell headerCell = pdfGrid.Headers[0].Cells[i]; - - //Apply the header style. - headerCell.Style = headerStyle; -} + //Apply the cell style for the header cells. + for (int i = 0; i < pdfGrid.Headers[0].Cells.Count; i++) + { + //Get the header cell. + PdfGridCell headerCell = pdfGrid.Headers[0].Cells[i]; -//Declare and define the table cell style. -PdfGridCellStyle cellStyle = new PdfGridCellStyle(); + //Apply the header style. + headerCell.Style = headerStyle; + } -//Set the border color for the table. -cellStyle.Borders.All = new PdfPen(Color.Transparent); + //Declare and define the table cell style. + PdfGridCellStyle cellStyle = new PdfGridCellStyle(); -//Apply the cell style for the row cells. -for (int i = 0; i < pdfGrid.Rows.Count; i++) -{ - //Get the row. - PdfGridRow row = pdfGrid.Rows[i]; + //Set the border color for the table. + cellStyle.Borders.All = new PdfPen(Color.Transparent); - for (int j = 0; j < row.Cells.Count; j++) + //Apply the cell style for the row cells. + for (int i = 0; i < pdfGrid.Rows.Count; i++) { - //Get the cell. - PdfGridCell cell = row.Cells[j]; + //Get the row. + PdfGridRow row = pdfGrid.Rows[i]; + + for (int j = 0; j < row.Cells.Count; j++) + { + //Get the cell. + PdfGridCell cell = row.Cells[j]; - //Apply the cell style. - cell.Style = cellStyle; + //Apply the cell style. + cell.Style = cellStyle; + } } -} -//Draw a grid to the page of a PDF document. -pdfGrid.Draw(pdfPage, new PointF(10, 10)); + //Draw a grid to the page of a PDF document. + pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); \ No newline at end of file diff --git a/Table/PdfGrid/Draw-rotated-table-in-PDF-document/.NET/Draw-rotated-table-in-PDF-document/Program.cs b/Table/PdfGrid/Draw-rotated-table-in-PDF-document/.NET/Draw-rotated-table-in-PDF-document/Program.cs index 88af7766..b50b539a 100644 --- a/Table/PdfGrid/Draw-rotated-table-in-PDF-document/.NET/Draw-rotated-table-in-PDF-document/Program.cs +++ b/Table/PdfGrid/Draw-rotated-table-in-PDF-document/.NET/Draw-rotated-table-in-PDF-document/Program.cs @@ -1,57 +1,47 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; 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 PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add a handler to rotate the table. -pdfGrid.BeginPageLayout += PdfGrid_BeginPageLayout; + //Add a handler to rotate the table. + pdfGrid.BeginPageLayout += PdfGrid_BeginPageLayout; -//Add values to the list. -List data = new List(); + //Add values to the list. + List data = new List(); -Object row1 = new { ID = "57", Name = "AAA", Type = "ABC", Date = DateTime.Now }; -Object row2 = new { ID = "130", Name = "BBB", Type = "BCD", Date = DateTime.Now }; -Object row3 = new { ID = "92", Name = "CCC", Type = "CDE", Date = DateTime.Now }; + Object row1 = new { ID = "57", Name = "AAA", Type = "ABC", Date = DateTime.Now }; + Object row2 = new { ID = "130", Name = "BBB", Type = "BCD", Date = DateTime.Now }; + Object row3 = new { ID = "92", Name = "CCC", Type = "CDE", Date = DateTime.Now }; -data.Add(row1); -data.Add(row2); -data.Add(row3); + data.Add(row1); + data.Add(row2); + data.Add(row3); -//Add list to the IEnumerable. -IEnumerable dataTable = data; + //Add list to the IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Set a repeat header for the table. -pdfGrid.RepeatHeader = true; + //Set a repeat header for the table. + pdfGrid.RepeatHeader = true; -//Draw a grid to the page of a PDF document. -pdfGrid.Draw(page, new RectangleF(100, 20, 0, page.GetClientSize().Width)); + //Draw a grid to the page of a PDF document. + pdfGrid.Draw(page, new RectangleF(100, 20, 0, page.GetClientSize().Width)); -//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 PdfGrid_BeginPageLayout(object sender, BeginPageLayoutEventArgs e) { PdfPage page = e.Page; diff --git a/Table/PdfGrid/Insert-image-in-a-particular-table-cell/.NET/Insert-image-in-a-particular-table-cell/Program.cs b/Table/PdfGrid/Insert-image-in-a-particular-table-cell/.NET/Insert-image-in-a-particular-table-cell/Program.cs index 1662b772..0a596c3e 100644 --- a/Table/PdfGrid/Insert-image-in-a-particular-table-cell/.NET/Insert-image-in-a-particular-table-cell/Program.cs +++ b/Table/PdfGrid/Insert-image-in-a-particular-table-cell/.NET/Insert-image-in-a-particular-table-cell/Program.cs @@ -1,53 +1,42 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; using Syncfusion.Drawing; using System.Reflection.Metadata; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Create the page. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Create the page. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to the list. -List data = new List(); -Object row1 = new { SNO = "1", Image = "" }; -data.Add(row1); + //Add values to the list. + List data = new List(); + Object row1 = new { SNO = "1", Image = "" }; + data.Add(row1); -//Add list to the IEnumerable. -IEnumerable dataTable = data; + //Add list to the IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Set the row height. -pdfGrid.Rows[0].Height = 100; + //Set the row height. + pdfGrid.Rows[0].Height = 100; -//Call the event handler to draw the image in a particular cell. -pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout; + //Call the event handler to draw the image in a particular cell. + pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout; -//Draw a grid to the page of a PDF document. -pdfGrid.Draw(pdfPage, new PointF(10, 10)); + //Draw a grid to the page of a PDF document. + pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } -//Close the document. -pdfDocument.Close(true); - - - - static void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args) { if (args.CellIndex == 1 && !args.IsHeaderRow) diff --git a/Table/PdfGrid/Paginate-the-table-in-PDF-document/.NET/Paginate-the-table-in-PDF-document/Program.cs b/Table/PdfGrid/Paginate-the-table-in-PDF-document/.NET/Paginate-the-table-in-PDF-document/Program.cs index d78e83a0..2040d87a 100644 --- a/Table/PdfGrid/Paginate-the-table-in-PDF-document/.NET/Paginate-the-table-in-PDF-document/Program.cs +++ b/Table/PdfGrid/Paginate-the-table-in-PDF-document/.NET/Paginate-the-table-in-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.Grid; //Create a new PDF document. -PdfDocument document = new PdfDocument(); +using (PdfDocument document = new PdfDocument()) +{ + //Add a page + PdfPage page = document.Pages.Add(); -//Add a page -PdfPage page = document.Pages.Add(); + //Create a PdfGrid + PdfGrid pdfGrid = new PdfGrid(); -//Create a PdfGrid -PdfGrid pdfGrid = new PdfGrid(); + //Add values to list + List data = new List(); -//Add values to list -List data = new List(); + //You can add multiple rows here + Object row1 = new { ID = "E01", Name = "Clay" }; + Object row2 = new { ID = "E02", Name = "Thomas" }; -//You can add multiple rows here -Object row1 = new { ID = "E01", Name = "Clay" }; -Object row2 = new { ID = "E02", Name = "Thomas" }; + for (int i = 0; i < 500; i++) + { + data.Add(row1); + data.Add(row2); + } -for (int i = 0; i < 500; i++) -{ - data.Add(row1); - data.Add(row2); -} + //Add list to IEnumerable + IEnumerable dataTable = data; -//Add list to IEnumerable -IEnumerable dataTable = data; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Set properties to paginate the grid. + PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); + layoutFormat.Break = PdfLayoutBreakType.FitPage; + layoutFormat.Layout = PdfLayoutType.Paginate; -//Set properties to paginate the grid. -PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); -layoutFormat.Break = PdfLayoutBreakType.FitPage; -layoutFormat.Layout = PdfLayoutType.Paginate; + //Draw grid to the page of PDF document. + pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10), layoutFormat); -//Draw grid to the page of PDF document. -pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10), 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/PdfGrid/Prevent-row-breaks-across-pages/.NET/Prevent-row-breaks-across-pages/Program.cs b/Table/PdfGrid/Prevent-row-breaks-across-pages/.NET/Prevent-row-breaks-across-pages/Program.cs index 4741d275..925cc968 100644 --- a/Table/PdfGrid/Prevent-row-breaks-across-pages/.NET/Prevent-row-breaks-across-pages/Program.cs +++ b/Table/PdfGrid/Prevent-row-breaks-across-pages/.NET/Prevent-row-breaks-across-pages/Program.cs @@ -1,7 +1,7 @@ using Syncfusion.Pdf.Grid; using Syncfusion.Pdf; -// Create a new PDF document +//Create a new PDF document. using (PdfDocument document = new PdfDocument()) { // Add a page @@ -17,7 +17,7 @@ new { ID = "E03", - Description = new string('A', 5000) + Description = new string('A', 5000) }, new { ID = "E04", Description = "Short text 3" } }; @@ -31,10 +31,6 @@ // Draw the grid on the page pdfGrid.Draw(page, 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 + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } diff --git a/Table/PdfGrid/Resize-font-to-fit-grid-cell-width/.NET/Resize-font-to-fit-grid-cell-width/Program.cs b/Table/PdfGrid/Resize-font-to-fit-grid-cell-width/.NET/Resize-font-to-fit-grid-cell-width/Program.cs index 75b0146c..43733536 100644 --- a/Table/PdfGrid/Resize-font-to-fit-grid-cell-width/.NET/Resize-font-to-fit-grid-cell-width/Program.cs +++ b/Table/PdfGrid/Resize-font-to-fit-grid-cell-width/.NET/Resize-font-to-fit-grid-cell-width/Program.cs @@ -7,55 +7,52 @@ class Program { static void Main(string[] args) { - // 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 PdfGrid. - PdfGrid grid = new PdfGrid(); + // Create a PdfGrid. + PdfGrid grid = new PdfGrid(); - // Set the font for the grid. - grid.Style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); + // Set the font for the grid. + grid.Style.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); - // Add three columns to the grid. - grid.Columns.Add(3); + // Add three columns to the grid. + grid.Columns.Add(3); - // Set the width of each column. - for (int i = 0; i < 3; i++) - { - grid.Columns[i].Width = page.GetClientSize().Width / 3; - } + // Set the width of each column. + for (int i = 0; i < 3; i++) + { + grid.Columns[i].Width = page.GetClientSize().Width / 3; + } - // Set up the header cells. - PdfGridRow pdfGridHeader = grid.Headers.Add(1)[0]; - pdfGridHeader.Cells[0].Value = "Employee ID"; - pdfGridHeader.Cells[1].Value = "Employee Name"; - pdfGridHeader.Cells[2].Value = "Details"; + // Set up the header cells. + PdfGridRow pdfGridHeader = grid.Headers.Add(1)[0]; + pdfGridHeader.Cells[0].Value = "Employee ID"; + pdfGridHeader.Cells[1].Value = "Employee Name"; + pdfGridHeader.Cells[2].Value = "Details"; - // Add rows to the grid. - for (int i = 1; i <= 5; i++) - { - PdfGridRow row = grid.Rows.Add(); - row.Height = 20; - row.Cells[0].Value = "E0" + i; - row.Cells[1].Value = "Employee " + i; - row.Cells[2].Value = String.Format("Employee {0} is a software engineer with over ten years of experience in developing scalable applications. He specializes in full-stack development and enjoys working on innovative projects.", i); - } + // Add rows to the grid. + for (int i = 1; i <= 5; i++) + { + PdfGridRow row = grid.Rows.Add(); + row.Height = 20; + row.Cells[0].Value = "E0" + i; + row.Cells[1].Value = "Employee " + i; + row.Cells[2].Value = String.Format("Employee {0} is a software engineer with over ten years of experience in developing scalable applications. He specializes in full-stack development and enjoys working on innovative projects.", i); + } - // Adjust the font size to fit the cell content. - AdjustFontSize(grid); + // Adjust the font size to fit the cell content. + AdjustFontSize(grid); - // Draw the PdfGrid on the page. - grid.Draw(page, PointF.Empty); + // Draw the PdfGrid on the page. + grid.Draw(page, PointF.Empty); - // Save and close the document. - using (FileStream stream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite)) - { - document.Save(stream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - document.Close(true); } // Method to adjust the font size to fit the cell content. @@ -104,4 +101,4 @@ public static void AdjustFontSize(PdfGrid grid) } } } -} +} \ No newline at end of file diff --git a/Table/PdfGrid/Row-customization-of-PdfGrid-in-a-PDF/.NET/Row-customization-of-PdfGrid-in-a-PDF/Program.cs b/Table/PdfGrid/Row-customization-of-PdfGrid-in-a-PDF/.NET/Row-customization-of-PdfGrid-in-a-PDF/Program.cs index 616445bf..f3cb9af6 100644 --- a/Table/PdfGrid/Row-customization-of-PdfGrid-in-a-PDF/.NET/Row-customization-of-PdfGrid-in-a-PDF/Program.cs +++ b/Table/PdfGrid/Row-customization-of-PdfGrid-in-a-PDF/.NET/Row-customization-of-PdfGrid-in-a-PDF/Program.cs @@ -1,55 +1,47 @@ -// See https://aka.ms/new-console-template for more information - -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; //Create a new PDF document. -PdfDocument pdfDocument = new PdfDocument(); - -//Add page to PDF document. -PdfPage pdfPage = pdfDocument.Pages.Add(); +using (PdfDocument document = new PdfDocument()) +{ + //Add page to PDF document. + PdfPage pdfPage = document.Pages.Add(); -//Create a new PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); + //Create a new PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); -//Add values to list. -List data = new List(); -Object row1 = new { ID = "E01", Name = "John" }; -Object row2 = new { ID = "E02", Name = "Thomas" }; -Object row3 = new { ID = "E03", Name = "Peter" }; -data.Add(row1); -data.Add(row2); -data.Add(row3); + //Add values to list. + List data = new List(); + Object row1 = new { ID = "E01", Name = "John" }; + Object row2 = new { ID = "E02", Name = "Thomas" }; + Object row3 = new { ID = "E03", Name = "Peter" }; + data.Add(row1); + data.Add(row2); + data.Add(row3); -//Add list to IEnumerable. -IEnumerable dataTable = data; + //Add list to IEnumerable. + IEnumerable dataTable = data; -//Assign data source. -pdfGrid.DataSource = dataTable; + //Assign data source. + pdfGrid.DataSource = dataTable; -//Create an instance of PdfGridRowStyle. -PdfGridRowStyle pdfGridRowStyle = new PdfGridRowStyle(); -pdfGridRowStyle.BackgroundBrush = PdfBrushes.LightYellow; -pdfGridRowStyle.Font = new PdfStandardFont(PdfFontFamily.Courier, 10); -pdfGridRowStyle.TextBrush = PdfBrushes.Blue; -pdfGridRowStyle.TextPen = PdfPens.Pink; + //Create an instance of PdfGridRowStyle. + PdfGridRowStyle pdfGridRowStyle = new PdfGridRowStyle(); + pdfGridRowStyle.BackgroundBrush = PdfBrushes.LightYellow; + pdfGridRowStyle.Font = new PdfStandardFont(PdfFontFamily.Courier, 10); + pdfGridRowStyle.TextBrush = PdfBrushes.Blue; + pdfGridRowStyle.TextPen = PdfPens.Pink; -//Set the height. -pdfGrid.Rows[2].Height = 50; + //Set the height. + pdfGrid.Rows[2].Height = 50; -//Set style for the PdfGridRow. -pdfGrid.Rows[0].Style = pdfGridRowStyle; + //Set style for the PdfGridRow. + pdfGrid.Rows[0].Style = pdfGridRowStyle; -//Draw the PdfGrid. -PdfGridLayoutResult result = pdfGrid.Draw(pdfPage, Syncfusion.Drawing.PointF.Empty); + //Draw the PdfGrid. + PdfGridLayoutResult result = pdfGrid.Draw(pdfPage, 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. - pdfDocument.Save(outputFileStream); + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); } - -//Close the document. -pdfDocument.Close(true); diff --git a/Table/PdfGrid/Set-different-margins-for-multi-page-PDF-grid/.NET/Set-different-margins-for-multi-page-PDF-grid/Program.cs b/Table/PdfGrid/Set-different-margins-for-multi-page-PDF-grid/.NET/Set-different-margins-for-multi-page-PDF-grid/Program.cs index 7f2a4498..c1fb8ae3 100644 --- a/Table/PdfGrid/Set-different-margins-for-multi-page-PDF-grid/.NET/Set-different-margins-for-multi-page-PDF-grid/Program.cs +++ b/Table/PdfGrid/Set-different-margins-for-multi-page-PDF-grid/.NET/Set-different-margins-for-multi-page-PDF-grid/Program.cs @@ -2,39 +2,36 @@ using Syncfusion.Pdf; //Create a new PDF document. -PdfDocument document = new PdfDocument(); -//Set page margins -document.PageSettings.Margins.Top = 50; -document.PageSettings.Margins.Bottom = 50; -//Add a new PDF page. -PdfPage page = document.Pages.Add(); -//Create a PdfGrid. -PdfGrid pdfGrid = new PdfGrid(); -//Add values to the list. -List data = new List(); -for (int i = 0; i < 100; i++) +using (PdfDocument document = new PdfDocument()) { - Object row1 = new { ID = "1", Name = "Clay", Price = "$10" }; - Object row2 = new { ID = "2", Name = "Gray", Price = "$20" }; - Object row3 = new { ID = "3", Name = "Ash", Price = "$30" }; - data.Add(row1); - data.Add(row2); - data.Add(row3); -} -//Add list to IEnumerable. -IEnumerable tableData = data; -//Assign data source. -pdfGrid.DataSource = tableData; -PdfGridLayoutFormat format = new PdfGridLayoutFormat(); -//Set paginate bounds -format.PaginateBounds = new Syncfusion.Drawing.RectangleF(0, 15, page.GetClientSize().Width, page.GetClientSize().Height - 15); -//Draw the grid, letting Syncfusion handle pagination. -pdfGrid.Draw(page, new Syncfusion.Drawing.RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); -//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 + //Set page margins + document.PageSettings.Margins.Top = 50; + document.PageSettings.Margins.Bottom = 50; + //Add a new PDF page. + PdfPage page = document.Pages.Add(); + //Create a PdfGrid. + PdfGrid pdfGrid = new PdfGrid(); + //Add values to the list. + List data = new List(); + for (int i = 0; i < 100; i++) + { + Object row1 = new { ID = "1", Name = "Clay", Price = "$10" }; + Object row2 = new { ID = "2", Name = "Gray", Price = "$20" }; + Object row3 = new { ID = "3", Name = "Ash", Price = "$30" }; + data.Add(row1); + data.Add(row2); + data.Add(row3); + } + //Add list to IEnumerable. + IEnumerable tableData = data; + //Assign data source. + pdfGrid.DataSource = tableData; + PdfGridLayoutFormat format = new PdfGridLayoutFormat(); + //Set paginate bounds + format.PaginateBounds = new Syncfusion.Drawing.RectangleF(0, 15, page.GetClientSize().Width, page.GetClientSize().Height - 15); + //Draw the grid, letting Syncfusion handle pagination. + pdfGrid.Draw(page, new Syncfusion.Drawing.RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); + + //Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} \ No newline at end of file