Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ec21b0b
Added ccitt group 3 compression
Apr 10, 2015
37666ae
added CCITTFAX4 compression
jaykay-design Nov 11, 2017
2ab77a7
fixed compiler warnings
jaykay-design Nov 11, 2017
53e5f7f
updated TIFF library package
jaykay-design Nov 11, 2017
759b194
Handle the case when CCITTFaxDecode \DecodeParms are stored as an arr…
jaykay-design May 30, 2018
9a11105
added PdfString support for color palettes
Feb 17, 2019
442df18
fix negated 1bpp TIFs with Photometric.MINISBLACK
ghosttie Mar 28, 2022
5dbb246
Update README.md
husaft Dec 6, 2022
13c0632
Merge pull request #1 from ghosttie/patch-1
husaft Dec 6, 2022
ff3a243
Merge pull request #2 from sk2andy/master
husaft Dec 6, 2022
4f23b32
Merge pull request #3 from jaykay-design/master
husaft Dec 6, 2022
6860084
Merge branch 'master' of https://github.com/vanderkorn/PDFSharp.Exten…
husaft Dec 6, 2022
8c6684f
Merge branch 'vanderkorn-master'
husaft Dec 6, 2022
f0d9006
Merge branch 'master' of https://github.com/Open-Inventions/PDFSharp.…
husaft Dec 6, 2022
e3b1a76
Added vs to ignore
husaft Dec 6, 2022
f4ffe6f
Update README.md
husaft Dec 6, 2022
cafb290
Update README.md
husaft Dec 6, 2022
1770313
Removed doubled lines after merge
husaft Dec 6, 2022
8994bad
Merge branch 'master' of https://github.com/Open-Inventions/PDFSharp.…
husaft Dec 6, 2022
680c3d1
Modernizing the project file
husaft Dec 6, 2022
5f63051
Removing Nuget stuff
husaft Dec 6, 2022
62ae97e
Moving core lib into its own dir
husaft Dec 6, 2022
1798d9a
Added example application
husaft Dec 6, 2022
fe61363
Updated to latest NET LTS
husaft Dec 6, 2022
f247e4c
Added several examples per image mode
husaft Dec 7, 2022
df04e33
Added output folder to extracted images
husaft Dec 9, 2022
e3e94eb
Removing step by step old legacy
husaft Dec 9, 2022
8758f45
Patching first of three
husaft Dec 9, 2022
8bc2158
Fixed Readme spelling
husaft Dec 9, 2022
4f6226a
Added format helper and color applier
husaft Dec 9, 2022
4b58439
Added two helpers
husaft Dec 9, 2022
f41f7ac
Added fax tiff decode
husaft Dec 9, 2022
f90d030
Added method for expanding half byte to full
husaft Dec 9, 2022
239e87a
Removing old code
husaft Dec 9, 2022
7e62032
Removing old code
husaft Dec 9, 2022
533ce7d
Catching error if flatedecode does not work
husaft Dec 9, 2022
a41b2e2
Successfully ported every known test case
husaft Dec 9, 2022
d3fdb29
Merge pull request #5 from Open-Inventions/newgfx
husaft Dec 9, 2022
c3551b0
Updated to newest PDF lib
husaft Dec 9, 2022
b981cdc
It went up to 75 percent of code coverage
husaft Dec 9, 2022
9244ad1
Update README.md
husaft Dec 26, 2022
8cbb5e8
Update PDFSharp.Extensions.csproj
husaft Dec 26, 2022
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
459 changes: 454 additions & 5 deletions .gitignore

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions PDFSharp.Extensions.Sample/PDFSharp.Extensions.Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\PDFSharp.Extensions\PDFSharp.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="res\**\*.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Update="res\**\*.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
103 changes: 103 additions & 0 deletions PDFSharp.Extensions.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using SixLabors.ImageSharp;
using System.IO;
using System.Linq;
using PdfSharp.Pdf;
using PdfSharp.Pdf.Drawing;
using PdfSharpCore.Pdf;
using PdfSharpCore.Pdf.IO;

namespace PDFSharp.Extensions.Sample
{
internal static class Program
{
private static void Main(string[] args)
{
var root = args.FirstOrDefault() ?? Path.Combine("res");
var output = Directory.CreateDirectory("out").Name;
const SearchOption o = SearchOption.AllDirectories;
var files = Directory.GetFiles(root, "*.pdf", o);
foreach (var file in files)
try
{
ExtractImages(output, file);
}
catch (Exception e)
{
Console.Error.WriteLine($"{file} -> {e.Message}");
}

var doc = files.FirstOrDefault(f => f.Contains("sample"));
ExtractDocument(output, doc);

var imgs = Directory.GetFiles(root, "*.png", o);
CombineImages(output, imgs);
}

private static void CombineImages(string output, string[] filenames)
{
var images = filenames.Select(Image.Load).ToArray();

var name = Path.GetFileNameWithoutExtension(filenames.First());
var path = Path.Combine(output, $"{name}.pdf");
using (PdfDocument pdf = images.First().ToPdf())
pdf.Save(path);

name = Path.GetFileNameWithoutExtension(filenames.Last());
path = Path.Combine(output, $"{name}.pdf");
using (PdfDocument pdf = images.ToPdf())
pdf.Save(path);
}

private static void ExtractDocument(string output, string filename)
{
using (var document = PdfReader.Open(filename, PdfDocumentOpenMode.Import))
{
using var image = document.GetImages().Single();
var name = Path.GetFileNameWithoutExtension(filename);
var path = Path.Combine(output, $"{name}.png");
image.SaveAsPng(path);

var page = document.Pages[0];

var elements = page.Elements;
var array = elements.Values.OfType<PdfArray>().Single();
Console.WriteLine($" {nameof(PdfArray)} " +
$"{nameof(PdfArrayExtensions.IsEmpty)} " +
$"= {array.IsEmpty()}");
array.Dump();

var resources = page.Resources.Elements;
var dict = resources.Values.OfType<PdfDictionary>().First();
dict.Dump();
}
}

private static void ExtractImages(string output, string filename)
{
Console.WriteLine("Processing file: {0}", filename);

using (var document = PdfReader.Open(filename, PdfDocumentOpenMode.Import))
{
var pageIndex = 0;
foreach (PdfPage page in document.Pages)
{
var imageIndex = 0;
foreach (var image in page.GetImages())
{
var currPage = pageIndex + 1;
var currImg = imageIndex + 1;
Console.WriteLine("\r\nExtracting image {1} from page {0}", currPage, currImg);

var pre = Path.GetFileNameWithoutExtension(filename);
var path = string.Format(@"{2} {0:00000000}-{1:000}.png", currPage, currImg, pre);
path = Path.Combine(output, path);
image.SaveAsPng(path);
imageIndex++;
}
pageIndex++;
}
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file added PDFSharp.Extensions.Sample/res/DCT/Created.pdf
Binary file not shown.
Binary file added PDFSharp.Extensions.Sample/res/DCT/Sample.pdf
Binary file not shown.
Binary file added PDFSharp.Extensions.Sample/res/DCT/issue_28.pdf
Binary file not shown.
Binary file added PDFSharp.Extensions.Sample/res/Flate/OTGuide.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added PDFSharp.Extensions.Sample/res/New/example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PDFSharp.Extensions.Sample/res/New/example-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 0 additions & 66 deletions PDFSharp.Extensions.csproj

This file was deleted.

23 changes: 0 additions & 23 deletions PDFSharp.Extensions.nuspec

This file was deleted.

48 changes: 28 additions & 20 deletions PDFSharp.Extensions.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFSharp.Extensions", "PDFSharp.Extensions.csproj", "{35910C2C-3D6D-4912-9584-4DE66C294729}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{35910C2C-3D6D-4912-9584-4DE66C294729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35910C2C-3D6D-4912-9584-4DE66C294729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35910C2C-3D6D-4912-9584-4DE66C294729}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35910C2C-3D6D-4912-9584-4DE66C294729}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFSharp.Extensions", "PDFSharp.Extensions\PDFSharp.Extensions.csproj", "{3D172E2D-785B-4CC1-BF95-CAD6AD9BDC41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PDFSharp.Extensions.Sample", "PDFSharp.Extensions.Sample\PDFSharp.Extensions.Sample.csproj", "{FB0B4F48-BE1D-4B26-BE00-A9A21F2820D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3D172E2D-785B-4CC1-BF95-CAD6AD9BDC41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D172E2D-785B-4CC1-BF95-CAD6AD9BDC41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D172E2D-785B-4CC1-BF95-CAD6AD9BDC41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D172E2D-785B-4CC1-BF95-CAD6AD9BDC41}.Release|Any CPU.Build.0 = Release|Any CPU
{FB0B4F48-BE1D-4B26-BE00-A9A21F2820D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB0B4F48-BE1D-4B26-BE00-A9A21F2820D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB0B4F48-BE1D-4B26-BE00-A9A21F2820D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB0B4F48-BE1D-4B26-BE00-A9A21F2820D5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
29 changes: 29 additions & 0 deletions PDFSharp.Extensions/PDFSharp.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<RootNamespace>PDFSharp.Extensions</RootNamespace>
<PackageId>PdfSharpCore.Extensions</PackageId>
<Version>0.1.2.4</Version>
<Authors>Open Inventions</Authors>
<Company>Open Inventions</Company>
<LicenseUrl>https://github.com/Open-Inventions/PDFSharp.Extensions/blob/master/LICENSE</LicenseUrl>
<ProjectUrl>https://github.com/Open-Inventions/PDFSharp.Extensions</ProjectUrl>
<RepositoryUrl>https://github.com/Open-Inventions/PDFSharp.Extensions</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RequireLicenseAcceptance>true</RequireLicenseAcceptance>
<Description>Extension methods for PdfSharpCore to support and simplify some common operations including image extraction.</Description>
<ReleaseNotes>Initial release.</ReleaseNotes>
<Copyright>Copyright © 2014, George Heeres (gheeres@gmail.com) + 2022, OI</Copyright>
<Trademark>Licensed under MIT</Trademark>
<PackageTags>pdf, pdfsharp, PdfSharpCore, image, extension</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BitMiracle.LibTiff.NET" Version="2.4.649" />
<PackageReference Include="PdfSharpCore" Version="1.3.43" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using PdfSharpCore.Pdf;
using System;

// ReSharper disable once CheckNamespace
namespace PdfSharp.Pdf
Expand Down
Loading