Skip to content

Commit

Permalink
Fix sample warnings seen during workflow build.
Browse files Browse the repository at this point in the history
  • Loading branch information
datalogics-josepha committed Mar 20, 2024
1 parent 28aeff2 commit e96c50e
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 110 deletions.
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
12 changes: 6 additions & 6 deletions Images/DocToImages/DocToImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DocToImagesOptions
List<int> PageList = new List<int>(0);
int evenoddpages; // 1 = all odd pages, 2 = all even pages.
string outputfilename = "";
string outputdirname = "";
string? outputdirname = "";
SmoothFlags smoothingflags = SmoothFlags.None;
bool reversegray;
bool blackisone;
Expand Down Expand Up @@ -214,12 +214,12 @@ public string getoutputfile()
return (outputfilename);
}

public void setoutputdir(string outputdir)
public void setoutputdir(string? outputdir)
{
outputdirname = outputdir;
}

public string getoutputdir()
public string? getoutputdir()
{
return (outputdirname);
}
Expand Down Expand Up @@ -1071,7 +1071,7 @@ static void Main(string[] args)
// ReSharper disable once UnusedVariable
using (Library lib = new Library(options.getfontdirs()))
{
Document pdfdocument = null;
Document? pdfdocument = null;
int numpages = 0;
try
{
Expand All @@ -1089,7 +1089,7 @@ static void Main(string[] args)
* of the output filename and directory name.
*/

string outputfilename;
string? outputfilename;
if (options.getoutputfile() == "")
{
outputfilename = docpath;
Expand Down Expand Up @@ -1169,7 +1169,7 @@ static void Main(string[] args)
i++) // Get the images of the PDF pages to create an image collection.
{
Page docpage = pdfdocument.GetPage(pagelist[i]);
Rect PageRect = null;
Rect? PageRect = null;
if (options.getpageregion().Equals("crop"))
{
PageRect = docpage.CropBox;
Expand Down
6 changes: 3 additions & 3 deletions Images/ImageExport/ImageExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ public void Export_Element_Images(Content content)
else if (e is Container)
{
Console.WriteLine("Recursing through a Container");
Export_Element_Images((e as Container).Content);
Export_Element_Images(((Container)e).Content);
}
else if (e is Group)
{
Console.WriteLine("Recursing through a Group");
Export_Element_Images((e as Group).Content);
Export_Element_Images(((Group)e).Content);
}
else if (e is Form)
{
Console.WriteLine("Recursing through a Form");
Export_Element_Images((e as Form).Content);
Export_Element_Images(((Form)e).Content);
}

i++;
Expand Down
6 changes: 3 additions & 3 deletions Images/ImageExtraction/ImageExtraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ static void ExtractImages(Content content)
}
else if (e is Datalogics.PDFL.Container)
{
ExtractImages((e as Datalogics.PDFL.Container).Content);
ExtractImages(((Datalogics.PDFL.Container)e).Content);
}
else if (e is Datalogics.PDFL.Group)
{
ExtractImages((e as Datalogics.PDFL.Group).Content);
ExtractImages(((Datalogics.PDFL.Group)e).Content);
}
else if (e is Form)
{
ExtractImages((e as Form).Content);
ExtractImages(((Datalogics.PDFL.Form)e).Content);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Images/ImageResampling/ImageResampling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ static void ResampleImages(Content content)
else if (e is Container)
{
Console.WriteLine("Recursing through a Container");
ResampleImages((e as Container).Content);
ResampleImages(((Container)e).Content);
}
else if (e is Group)
{
Console.WriteLine("Recursing through a Group");
ResampleImages((e as Group).Content);
ResampleImages(((Group)e).Content);
}
else if (e is Form)
{
Console.WriteLine("Recursing through a Form");
Content formcontent = (e as Form).Content;
Content formcontent = ((Form)e).Content;
ResampleImages(formcontent);
(e as Form).Content = formcontent;
((Form)e).Content = formcontent;
}

i++;
Expand Down
20 changes: 10 additions & 10 deletions InformationExtraction/ListPaths/ListPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ private static void ListPathsInContent(Content content, int pgno)

if (e is Datalogics.PDFL.Path)
{
ListPath(e as Datalogics.PDFL.Path, pgno);
ListPath((Datalogics.PDFL.Path)e, pgno);
}
else if (e is Container)
{
Console.WriteLine("Recurring through a Container");
ListPathsInContent((e as Container).Content, pgno);
ListPathsInContent(((Datalogics.PDFL.Container)e).Content, pgno);
}
else if (e is Group)
{
Console.WriteLine("Recurring through a Group");
ListPathsInContent((e as Group).Content, pgno);
ListPathsInContent(((Datalogics.PDFL.Group)e).Content, pgno);
}
else if (e is Form)
{
Console.WriteLine("Recurring through a Form");
ListPathsInContent((e as Form).Content, pgno);
ListPathsInContent(((Datalogics.PDFL.Form)e).Content, pgno);
}
}
}
Expand All @@ -83,40 +83,40 @@ private static void ListPath(Datalogics.PDFL.Path path, int pgno)
{
if (segment is MoveTo)
{
MoveTo moveto = segment as MoveTo;
MoveTo moveto = (MoveTo)segment;
Console.WriteLine(" MoveTo x={0}, y={1}", moveto.Point.H, moveto.Point.V);
}
else if (segment is LineTo)
{
LineTo lineto = segment as LineTo;
LineTo lineto = (LineTo)segment;
Console.WriteLine(" LineTo x={0}, y={1}",
lineto.Point.H, lineto.Point.V);
}
else if (segment is CurveTo)
{
CurveTo curveto = segment as CurveTo;
CurveTo curveto = (CurveTo)segment;
Console.WriteLine(" CurveTo x1={0}, y1={1}, x2={2}, y2={3}, x3={4}, y3={5}",
curveto.Point1.H, curveto.Point1.V,
curveto.Point2.H, curveto.Point2.V,
curveto.Point3.H, curveto.Point3.V);
}
else if (segment is CurveToV)
{
CurveToV curveto = segment as CurveToV;
CurveToV curveto = (CurveToV)segment;
Console.WriteLine(" CurveToV x2={0}, y2={1}, x3={2}, y3={3}",
curveto.Point2.H, curveto.Point2.V,
curveto.Point3.H, curveto.Point3.V);
}
else if (segment is CurveToY)
{
CurveToY curveto = segment as CurveToY;
CurveToY curveto = (CurveToY)segment;
Console.WriteLine(" CurveToV x1={0}, y1={1}, x3={2}, y3={3}",
curveto.Point1.H, curveto.Point1.V,
curveto.Point3.H, curveto.Point3.V);
}
else if (segment is RectSegment)
{
RectSegment rect = segment as RectSegment;
RectSegment rect = (RectSegment)segment;
Console.WriteLine(" Rectangle x={0}, y={1}, width={2}, height={3}",
rect.Point.H, rect.Point.V,
rect.Width, rect.Height);
Expand Down
36 changes: 27 additions & 9 deletions InformationExtraction/Metadata/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,61 @@ private static void DisplayImageMetadata(String input)
{
// Demonstrate getting data from an image
Content content = doc.GetPage(0).Content;
Container container = (Container) content.GetElement(0);
Datalogics.PDFL.Image image = (Datalogics.PDFL.Image) container.Content.GetElement(0);
Container container = (Container)content.GetElement(0);
Datalogics.PDFL.Image image = (Datalogics.PDFL.Image)container.Content.GetElement(0);
String metadata = image.Stream.Dict.XMPMetadata;
Console.WriteLine("Ducky CreatorTool: {0}\n", GetCreatorToolAttribute(metadata));
}
}

static string GetTitle(string xmlstring)
{
string title = "";

XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlstring);
XmlElement element = (XmlElement) xmldoc.GetElementsByTagName("dc:title")[0];
XmlNode titleNode = element.GetElementsByTagName("rdf:li")[0];
return GetText(titleNode.ChildNodes);
XmlElement? element = (XmlElement?)xmldoc.GetElementsByTagName("dc:title")[0];
if (element != null)
{
XmlNode? titleNode = element.GetElementsByTagName("rdf:li")[0];
if (titleNode != null)
{
title = GetText(titleNode.ChildNodes);
}
}

return title;
}

// ReSharper disable once UnusedMember.Local
static string GetCreatorTool(string xmlstring)
{
string creatorTool = "";
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlstring);
XmlElement element = (XmlElement) xmldoc.GetElementsByTagName("xap:CreatorTool")[0];
return GetText(element.ChildNodes);
XmlElement? element = (XmlElement?)xmldoc.GetElementsByTagName("xap:CreatorTool")[0];
if (element != null)
{
creatorTool = GetText(element.ChildNodes);
}

return creatorTool;
}

static string GetCreatorToolAttribute(string xmlstring)
{
string creatorToolAttribute = "";

XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(xmlstring);
foreach (XmlNode node in xmldoc.GetElementsByTagName("rdf:Description"))
{
XmlElement e = (XmlElement) node;
if (e.HasAttribute("xap:CreatorTool"))
return e.GetAttribute("xap:CreatorTool");
creatorToolAttribute = e.GetAttribute("xap:CreatorTool");
}

return null;
return creatorToolAttribute;
}

static string GetText(XmlNodeList nodeList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ static void AddTextToImages(Document doc, Content content, OCREngine engine)
}
else if (e is Container)
{
AddTextToImages(doc, (e as Container).Content, engine);
AddTextToImages(doc, ((Container)e).Content, engine);
}
else if (e is Group)
{
AddTextToImages(doc, (e as Group).Content, engine);
AddTextToImages(doc, ((Group)e).Content, engine);
}
else if (e is Form)
{
AddTextToImages(doc, (e as Form).Content, engine);
AddTextToImages(doc, ((Form)e).Content, engine);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Text/AddUnicodeText/AddUnicodeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void Main(string[] args)
foreach (String str in strings)
{
// Find a font that can represent all characters in the string, if there is one.
Font font = GetRepresentableFont(fonts, str);
Font? font = GetRepresentableFont(fonts, str);
if (font == null)
{
Console.WriteLine(
Expand Down Expand Up @@ -117,7 +117,7 @@ static void Main(string[] args)
}
}

static Font GetRepresentableFont(List<Font> fonts, String str)
static Font? GetRepresentableFont(List<Font> fonts, String str)
{
foreach (Font font in fonts)
{
Expand Down
Loading

0 comments on commit e96c50e

Please sign in to comment.