Skip to content

Commit

Permalink
Merge pull request #34 from datalogics/develop
Browse files Browse the repository at this point in the history
Update main from develop
  • Loading branch information
datalogics-robl authored Apr 11, 2024
2 parents bd47914 + b7061f3 commit 2c1b561
Show file tree
Hide file tree
Showing 32 changed files with 415 additions and 123 deletions.
190 changes: 190 additions & 0 deletions .github/workflows/test-dotnet-samples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
name: test-samples

on:
pull_request:
push:
branches: [ develop, main ]

env:
DOTNET_VERSION: '6.x'

jobs:
run-samples:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-14]
dir: [
'Annotations/Annotations/',
'Annotations/InkAnnotations/',
'Annotations/LinkAnnotation/',
'Annotations/PolygonAnnotations/',
'Annotations/PolyLineAnnotations/',
'ContentCreation/AddElements/',
'ContentCreation/AddHeaderFooter/',
'ContentCreation/Clips/',
'ContentCreation/CreateBookmarks/',
'ContentCreation/GradientShade/',
'ContentCreation/MakeDocWithCalGrayColorSpace/',
'ContentCreation/MakeDocWithCalRGBColorSpace/',
'ContentCreation/MakeDocWithDeviceNColorSpace/',
'ContentCreation/MakeDocWithICCBasedColorSpace/',
'ContentCreation/MakeDocWithIndexedColorSpace/',
'ContentCreation/MakeDocWithLabColorSpace/',
'ContentCreation/MakeDocWithSeparationColorSpace/',
'ContentCreation/NameTrees/',
'ContentCreation/NumberTrees/',
'ContentCreation/RemoteGoToActions/',
'ContentCreation/WriteNChannelTiff/',
'ContentModification/Action/',
'ContentModification/AddCollection/',
'ContentModification/ChangeLayerConfiguration/',
'ContentModification/ChangeLinkColors/',
'ContentModification/CreateLayer/',
'ContentModification/ExtendedGraphicStates/',
'ContentModification/FlattenTransparency/',
'ContentModification/LaunchActions/',
'ContentModification/MergePDF/',
'ContentModification/PageLabels/',
'ContentModification/PDFObject/',
'ContentModification/UnderlinesAndHighlights/',
'ContentModification/Watermark/',
'DocumentConversion/ColorConvertDocument/',
'DocumentConversion/ConvertToOffice/',
'DocumentConversion/CreateDocFromXPS/',
'DocumentConversion/Factur-XConverter/',
'DocumentConversion/PDFAConverter/',
'DocumentConversion/PDFXConverter/',
'DocumentConversion/ZUGFeRDConverter/',
'DocumentOptimization/PDFOptimize/',
'Images/DocToImages/',
'Images/DrawSeparations/',
'Images/DrawToBitmap/',
'Images/EPSSeparations/',
'Images/GetSeparatedImages/',
'Images/ImageEmbedICCProfile/',
'Images/ImageExport/',
'Images/ImageExtraction/',
'Images/ImageFromStream/',
'Images/ImageImport/',
'Images/ImageResampling/',
'Images/ImageSoftMask/',
'Images/OutputPreview/',
'Images/RasterizePage/',
'InformationExtraction/ListBookmarks/',
'InformationExtraction/ListInfo/',
'InformationExtraction/ListLayers/',
'InformationExtraction/ListPaths/',
'InformationExtraction/Metadata/',
'OpticalCharacterRecognition/AddTextToDocument/',
'OpticalCharacterRecognition/AddTextToImage/',
'Other/MemoryFileSystem/',
'Other/StreamIO/',
'Security/AddRegexRedaction/',
'Security/Redactions/',
'Text/AddGlyphs/',
'Text/AddUnicodeText/',
'Text/AddVerticalText/',
'Text/ExtractAcroFormFieldData/',
'Text/ExtractCJKTextByPatternMatch/',
'Text/ExtractTextByPatternMatch/',
'Text/ExtractTextByRegion/',
'Text/ExtractTextFromAnnotations/',
'Text/ExtractTextFromMultiRegions/',
'Text/ExtractTextPreservingStyleAndPositionInfo/',
'Text/ListWords/',
'Text/RegexExtractText/',
'Text/RegexTextSearch/',
'Text/TextExtract/'
]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Setup Microsoft Core Fonts
working-directory: ${{ matrix.dir }}
run: |
sample_name=$(basename "$PWD")
if [ "${{ matrix.os }}" == 'ubuntu-latest' ]; then
case "$sample_name" in "AddHeaderFooter" | "AddElements" | "MakeDocWithCalGrayColorSpace" | "MakeDocWithCalRGBColorSpace" | "MakeDocWithDeviceNColorSpace" | "MakeDocWithICCBasedColorSpace" | "MakeDocWithIndexedColorSpace" | "MakeDocWithLabColorSpace" | "MakeDocWithSeparationColorSpace" | "ExtendedGraphicStates" | "AddGlyphs" | "AddUnicodeText")
echo 'ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true' | sudo debconf-set-selections
sudo apt-get install ttf-mscorefonts-installer
;;
esac
fi
- name: Build samples
working-directory: ${{ matrix.dir }}
run: |
sample_name=$(basename "$PWD")
if { [ "$sample_name" != "ConvertToOffice" ] && [ "$sample_name" != "CreateDocFromXPS" ]; } || [ "${{ matrix.os }}" != 'macos-14' ]; then
dotnet build -c Release *.csproj
else
echo "Not available on this os"
fi
- name: Run samples
working-directory: ${{matrix.dir}}
run: |
sample_name=$(basename "$PWD")
if [ "$sample_name" == "Redactions" ] && [ "${{matrix.os}}" == 'ubuntu-latest' ]; then
echo "Not available on this os"
else
if { [ "$sample_name" != "ConvertToOffice" ] && [ "$sample_name" != "CreateDocFromXPS" ]; } || [ "${{matrix.os}}" != 'macos-14' ]; then
if [ "${{matrix.os}}" == 'windows-latest' ]; then
if [ "$sample_name" == "DocToImages" ]; then
bin/Release/net6.0/$sample_name.exe -format=png $HOME/.nuget/packages/adobe.pdf.library.sampleinput/1.0.0/build/Resources/Sample_Input/ducky.pdf
else
bin/Release/net6.0/$sample_name.exe
fi
else
if [ "$sample_name" == "DocToImages" ]; then
dotnet bin/Release/net6.0/$sample_name.dll -format=png $HOME/.nuget/packages/adobe.pdf.library.sampleinput/1.0.0/build/Resources/Sample_Input/ducky.pdf
else
dotnet bin/Release/net6.0/$sample_name.dll
fi
fi
else
echo "Not available on this os"
fi
fi
- name: Set sample_name variable
id: set-sample-name
working-directory: ${{matrix.dir}}
run: echo "SAMPLE_NAME=$(basename "$PWD")" >> "$GITHUB_ENV"

- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: output-${{ runner.os }}-${{ env.SAMPLE_NAME }}
path: |
${{matrix.dir}}*.docx
${{matrix.dir}}*.xslx
${{matrix.dir}}*.pptx
${{matrix.dir}}*.pdf
${{matrix.dir}}*.tif
${{matrix.dir}}*.png
${{matrix.dir}}*.jpg
${{matrix.dir}}*.eps
${{matrix.dir}}*.tiff
${{matrix.dir}}*.bmp
${{matrix.dir}}*.gif
${{matrix.dir}}*.json
${{matrix.dir}}*.txt
${{matrix.dir}}*.csv
- name: List files
run: |
ls ${{matrix.dir}}
2 changes: 1 addition & 1 deletion ContentCreation/AddHeaderFooter/AddHeaderFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void Main(string[] args)

using (Library lib = new Library())
{
String sOutput = "../AddHeaderFooter-out.pdf";
String sOutput = "AddHeaderFooter-out.pdf";

Console.WriteLine("Output file: " + sOutput);

Expand Down
40 changes: 40 additions & 0 deletions ContentModification/AddQRCode/AddQRCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Datalogics.PDFL;

/*
*
* This sample shows how to add a QR barcode to a PDF page
*
* Copyright (c) 2024, Datalogics, Inc. All rights reserved.
*
*/
namespace AddCollection
{
class AddQRCode
{
static void Main(string[] args)
{
Console.WriteLine("AddQRCode Sample:");

using (Library lib = new Library())
{
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/sample_links.pdf";
String sOutput = "../AddQRCode-out.pdf";

if (args.Length > 0)
sInput = args[0];

using (Document doc = new Document(sInput))
{
Page page = doc.GetPage(0);

page.AddQRBarcode("Datalogics", 72.0, page.CropBox.Top - 1.5 * 72.0, 72.0, 72.0);

doc.Save(SaveFlags.Full, sOutput);
}
}
}
}
}
14 changes: 14 additions & 0 deletions ContentModification/AddQRCode/AddQRCode.csproj
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="Adobe.PDF.Library.LM.NET" Version="18.*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions ContentModification/ChangeLinkColors/ChangeLinkColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void Main(string[] args)
Annotation annot = page.GetAnnotation(i);
if (annot is LinkAnnotation)
{
linkAnnots.Add(annot as LinkAnnotation);
linkAnnots.Add((LinkAnnotation)annot);
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ static void FindAndProcessText(Content content, List<LinkAnnotation> linkAnnots)
else if (element is Text)
{
Console.WriteLine("Found a Text object.");
CheckCharactersInText(element as Text, linkAnnots);
CheckCharactersInText((Text)element, linkAnnots);
}
}
}
Expand Down
60 changes: 32 additions & 28 deletions ContentModification/CreateLayer/CreateLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,38 @@ static void Main(string[] args)
Console.WriteLine("Opened a document.");

Page pg = doc.GetPage(0);
Image img = (pg.Content.GetElement(0) as Image);

// Containers, Forms and Annotations can be attached to an
// OptionalContentGroup; other content (like Image) can
// be made optional by placing it inside a Container
Container container = new Container();
container.Content = new Content();
container.Content.AddElement(img);

// We replace the Image with the Container
// (which now holds the image)
pg.Content.RemoveElement(0);
pg.UpdateContent();

pg.Content.AddElement(container);
pg.UpdateContent();

// We create a new OptionalContentGroup and place it in the
// OptionalContentConfig.Order array
OptionalContentGroup ocg = CreateNewOptionalContentGroup(doc, "Rubber Ducky");

// Now we associate the Container with the OptionalContentGroup
// via an OptionalContentMembershipDict. Note that we MUST
// update the Page's content afterwards.
AssociateOCGWithContainer(doc, ocg, container);
pg.UpdateContent();

doc.Save(SaveFlags.Full, sOutput);
Element element = pg.Content.GetElement(0);
if (element is Image)
{
Image img = (Image)element;

// Containers, Forms and Annotations can be attached to an
// OptionalContentGroup; other content (like Image) can
// be made optional by placing it inside a Container
Container container = new Container();
container.Content = new Content();
container.Content.AddElement(img);

// We replace the Image with the Container
// (which now holds the image)
pg.Content.RemoveElement(0);
pg.UpdateContent();

pg.Content.AddElement(container);
pg.UpdateContent();

// We create a new OptionalContentGroup and place it in the
// OptionalContentConfig.Order array
OptionalContentGroup ocg = CreateNewOptionalContentGroup(doc, "Rubber Ducky");

// Now we associate the Container with the OptionalContentGroup
// via an OptionalContentMembershipDict. Note that we MUST
// update the Page's content afterwards.
AssociateOCGWithContainer(doc, ocg, container);
pg.UpdateContent();

doc.Save(SaveFlags.Full, sOutput);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage
m = m.Scale(12.0, 12.0);

ExtendedGraphicState xgs = new ExtendedGraphicState();
TextRun tr = null;
TextRun? tr = null;
if (i == 0)
{
xgs.BlendMode = BlendMode.Normal;
Expand Down
3 changes: 3 additions & 0 deletions ContentModification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Creates an action associated with a link annotation on a PDF page.
## ***AddCollection***
Adds a collection to a PDF document to turn that document into a PDF Portfolio.

## ***AddQRCode***
Adds a QR barcode to the Page of a PDF document.

## ***ChangeLayerConfiguration***
Sets the on/off states for Optional Content Groups (Layers) within a PDF document.

Expand Down
2 changes: 1 addition & 1 deletion DocumentOptimization/PDFOptimize/PDFOptimize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void Main(string[] args)
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; ;
String sOutput = "../PDFOptimizer-out.pdf";
String sOutput = "PDFOptimizer-out.pdf";

if (args.Length > 0)
sInput = args[0];
Expand Down
Loading

0 comments on commit 2c1b561

Please sign in to comment.