Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

830501- Added Compress PDFs samples #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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.6.33417.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compress_secured_PDF_NET", "Compress_secured_PDF_NET\Compress_secured_PDF_NET.csproj", "{A7643DD4-589A-41FC-AFE0-4C6316ED1AB0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A7643DD4-589A-41FC-AFE0-4C6316ED1AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7643DD4-589A-41FC-AFE0-4C6316ED1AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7643DD4-589A-41FC-AFE0-4C6316ED1AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7643DD4-589A-41FC-AFE0-4C6316ED1AB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01627C7B-49BA-4C53-ACD4-9F9D2739263F}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using Syncfusion.Pdf;

namespace Compress_secured_PDF_NET {
internal class Program {
static void Main(string[] args) {
//Load existing PDF document.
FileStream fileStream = new FileStream(Path.GetFullPath("../../../Data/SecurePDF.pdf"), FileMode.Open, FileAccess.Read);
PdfLoadedDocument document = new PdfLoadedDocument(fileStream, "sample123");
jeyalakshmit marked this conversation as resolved.
Show resolved Hide resolved

//Create a new compression option.
PdfCompressionOptions options = new PdfCompressionOptions();
//Enable the compress image.
options.CompressImages = true;
//Set the image quality.
options.ImageQuality = 50;

//Assign the compression option to the document
document.Compress(options);
//Create file stream.
using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) {
//Save the PDF document to file stream.
document.Save(outputFileStream);
}
//Close the document.
document.Close(true);
}
}
}
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.6.33417.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge_and_compress_PDF_NET", "Merge_and_compress_PDF_NET\Merge_and_compress_PDF_NET.csproj", "{57645AC9-37C6-4DF8-AD81-30EE1290FA49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{57645AC9-37C6-4DF8-AD81-30EE1290FA49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57645AC9-37C6-4DF8-AD81-30EE1290FA49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57645AC9-37C6-4DF8-AD81-30EE1290FA49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57645AC9-37C6-4DF8-AD81-30EE1290FA49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {11312D7C-18D0-4A8D-996D-1044D027BE7F}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf;

namespace Merge_and_compress_PDF_NET {
internal class Program {
static void Main(string[] args) {
// Create a PDF document.
using (PdfDocument finalDocument = new PdfDocument()) {

// Get the stream from an existing PDF documents.
using (FileStream firstStream = new FileStream(Path.GetFullPath("../../../Data/imageDoc.pdf"), FileMode.Open, FileAccess.Read))

using (FileStream secondStream = new FileStream(Path.GetFullPath("../../../Data/imageDoc.pdf"), FileMode.Open, FileAccess.Read)) {

// Create a PDF stream for merging.
Stream[] streams = { firstStream, secondStream };

// Merge PDF documents.
PdfDocumentBase.Merge(finalDocument, streams);

// Save the document into a stream.
MemoryStream outputStream = new MemoryStream();
finalDocument.Save(outputStream);

// Create a new PdfLoadedDocument object from the file stream.
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(outputStream)) {

// Create a new PdfCompressionOptions object.
PdfCompressionOptions options = new PdfCompressionOptions();

// Enable the compress image and set image quality.
options.CompressImages = true;
options.ImageQuality = 50;

// Compress the PDF document.
loadedDocument.Compress(options);

// Save the document into memory stream.
using (FileStream memoryStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite)) {
loadedDocument.Save(memoryStream);
}
}
}
}
}
}
}