Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Clipping_and_graphics_state</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Loading