diff --git a/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state.sln b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state.sln new file mode 100644 index 00000000..8c0c4880 --- /dev/null +++ b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36616.10 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clipping-and-graphics-state", "Clipping-and-graphics-state\Clipping-and-graphics-state.csproj", "{D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3AD004B-8B2A-4230-9AA7-E0EC9CFC6C9C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {820F8B8B-A228-4044-AE9F-406099112325} + EndGlobalSection +EndGlobal diff --git a/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Clipping-and-graphics-state.csproj b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Clipping-and-graphics-state.csproj new file mode 100644 index 00000000..84198582 --- /dev/null +++ b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Clipping-and-graphics-state.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Clipping_and_graphics_state + enable + enable + + + + + + + diff --git a/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Data/Input.png b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Data/Input.png new file mode 100644 index 00000000..02194707 Binary files /dev/null and b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Data/Input.png differ diff --git a/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Output/gitkeep.txt b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Output/gitkeep.txt new file mode 100644 index 00000000..e69de29b diff --git a/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Program.cs b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Program.cs new file mode 100644 index 00000000..b5c799af --- /dev/null +++ b/Images/Clipping-and-graphics-state/.NET/Clipping-and-graphics-state/Program.cs @@ -0,0 +1,29 @@ +using Syncfusion.Drawing; +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +// Create a new PDF document +using (PdfDocument document = new PdfDocument()) +{ + // Add a page to the document + PdfPage page = document.Pages.Add(); + // Get the graphics object for the page + PdfGraphics graphics = page.Graphics; + // Open the image file as a stream + using FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Input.png"), FileMode.Open, FileAccess.Read); + // Load the image from the stream + PdfBitmap image = new PdfBitmap(imageStream); + // Save the current graphics state (to restore later) + PdfGraphicsState state = graphics.Save(); + // Define a rectangular clipping region + RectangleF clipRect = new RectangleF(50, 50, 200, 100); + graphics.SetClip(clipRect); + // Draw the image — only the part within the clipping region will be visible + graphics.DrawImage(image, new RectangleF(40, 60, 150, 80)); + // Restore the graphics state to remove the clipping region + graphics.Restore(state); + // Draw the image again — this time the full image will be visible + graphics.DrawImage(image, new RectangleF(60, 160, 150, 80)); + // Save the PDF document + document.Save(Path.GetFullPath(@"Output/Output.pdf")); +} 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 14d980d7..cfa42e6f 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 @@ -6,22 +6,24 @@ { //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 the attachment. - PdfAttachment pdfFile = new PdfAttachment("CorporateBrochure.pdf", pdfStream); - - //Set the file name. + // Set the name of the attachment file pdfFile.FileName = "CorporateBrochure.pdf"; - - //Set the startup document to view. + // Provide a description for the attachment + pdfFile.Description = "This is a PDF document"; + // Set the creation date of the attachment + pdfFile.CreationDate = DateTime.Now; + // Specify the MIME type of the attachment (important for identifying file type) + pdfFile.MimeType = "application/pdf"; + // Optionally, set the modification date if needed + pdfFile.ModificationDate = DateTime.Now; + // Optionally, set the relationship (e.g., "Data", "Source", etc.) + pdfFile.Relationship = PdfAttachmentRelationship.Unspecified; + // Set this attachment as the startup document in the PDF portfolio document.PortfolioInformation.StartupDocument = pdfFile; - //Add the attachment to the document. document.Attachments.Add(pdfFile); //Save the PDF document 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 a58b3610..85f33148 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 @@ -3,18 +3,27 @@ //Load the PDF document. PdfLoadedDocument document = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf")); - -string outputFileName = ""; - -//Iterate the attachments. +// Iterate through all attachments in the PDF document foreach (PdfAttachment attachment in document.Attachments) { - //Extract the attachment and save to the disk. - FileStream s = new FileStream(attachment.FileName, FileMode.Create); - s.Write(attachment.Data, 0, attachment.Data.Length); - s.Dispose(); - - outputFileName = attachment.FileName; + // Create a file stream to save the attachment to disk using its original file name + using (FileStream s = new FileStream(attachment.FileName, FileMode.Create)) + { + // Write the attachment data to the file + s.Write(attachment.Data, 0, attachment.Data.Length); + } + // Retrieve the MIME type of the attachment (e.g., application/pdf, image/png) + string mimeType = attachment.MimeType; + Console.WriteLine($"Saved: {attachment.FileName}, MIME Type: {mimeType}"); + // Optional: Access additional metadata if needed + DateTime creationDate = attachment.CreationDate; + DateTime modificationDate = attachment.ModificationDate; + string description = attachment.Description; + PdfAttachmentRelationship relationship = attachment.Relationship; + // Log or use the metadata as needed + Console.WriteLine($"Description: {description}"); + Console.WriteLine($"Created on: {creationDate}, Modified on: {modificationDate}"); + Console.WriteLine($"Relationship: {relationship}"); } //Save the PDF document document.Save(Path.GetFullPath(@"Output/Output.pdf"));