Skip to content

Commit

Permalink
Update DotNET Core Samples, num 6
Browse files Browse the repository at this point in the history
Used vendor tool to review C# files, broke lines to make them shorter,
removed unneeded spaces and indents.
  • Loading branch information
datalogics-mdawson committed Aug 31, 2020
1 parent 9d29ebe commit 260a483
Show file tree
Hide file tree
Showing 62 changed files with 884 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static void Main(string[] args)
if (args.Length > 2)
sOutput = args[2];

Console.WriteLine("Copying annotations from " + sInput1 + " into " + sInput2 + " and writing to " + sOutput);
Console.WriteLine("Copying annotations from " + sInput1 + " into " + sInput2 + " and writing to " +
sOutput);

Page sourcePage = sourceDoc.GetPage(0);
Page destinationPage = destinationDoc.GetPage(0);
Expand Down Expand Up @@ -81,7 +82,7 @@ static void Main(string[] args)
// the exception will specify which operation (copy or paste)
// that it could not complete.
// ReSharper disable once UnusedVariable
LinkAnnotation copiedLink = ((LinkAnnotation)ann).CopyTo(destinationPage, linkCenter);
LinkAnnotation copiedLink = ((LinkAnnotation) ann).CopyTo(destinationPage, linkCenter);
}
catch (ApplicationException ae)
{
Expand All @@ -91,7 +92,6 @@ static void Main(string[] args)
}

destinationDoc.Save(SaveFlags.Full, sOutput);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ static void Main(string[] args)

String sInput = Library.ResourceDirectory + "Sample_Input/sample_annotations.pdf";

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

Console.WriteLine("Input file: " + sInput);

Document doc = new Document(sInput);

Page pg = doc.GetPage(0);
Annotation ann = pg.GetAnnotation(0);

Console.WriteLine(ann.Title);
Console.WriteLine(ann.GetType().Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace FlashAnnotCreate
{
class FlashAnnotCreate
{

static void Main(string[] args)
{
Console.WriteLine("FlashAnnotCreate Sample:");
Expand All @@ -44,7 +43,8 @@ static void Main(string[] args)
if (args.Length > 2)
sOutput = args[2];

Console.WriteLine("Using flash file " + sInput1 + " and generating appearance from " + sInput2 + ", saving output file : " + sOutput);
Console.WriteLine("Using flash file " + sInput1 + " and generating appearance from " + sInput2 +
", saving output file : " + sOutput);

// Create a document and a 5" x 4" page for the Flash annotation
using (Document doc = new Document())
Expand Down Expand Up @@ -116,9 +116,11 @@ static void Main(string[] args)
// Add the permissions dictionary to the rendition
mediaClipObj.Put("P", permObj);

using (System.IO.FileStream fileStream = new System.IO.FileStream(sInput1, System.IO.FileMode.Open))
using (System.IO.FileStream fileStream =
new System.IO.FileStream(sInput1, System.IO.FileMode.Open))
{
using (PDFStream fileStmObj = new PDFStream(fileStream, doc, new PDFDict(doc, false), new PDFArray(doc, false)))
using (PDFStream fileStmObj = new PDFStream(fileStream, doc, new PDFDict(doc, false),
new PDFArray(doc, false)))
{
// Make a new file reference
PDFDict fileRefObj = new PDFDict(doc, true);
Expand Down Expand Up @@ -161,7 +163,8 @@ static void Main(string[] args)
// NOTE: the actual appearance of the page in the annotation will be scaled to fit
// within the boundaries of the annotation - so, if the page being used is of drastically
// different x/y proportions from the annotation, it will appear distorted. */
tempContent.AddPage(Content.BeforeFirst, doc, importPDPage, null, null, 0, null);
tempContent.AddPage(Content.BeforeFirst, doc, importPDPage, null, null, 0,
null);

if (tempContent.NumElements == 1 && tempContent.GetElement(0) is Form)
{
Expand All @@ -173,7 +176,8 @@ static void Main(string[] args)
cosAnnot.Put("AP", apDict);
}
else
Console.WriteLine("Unexpected page import result. Annotation will have no appearance.");
Console.WriteLine(
"Unexpected page import result. Annotation will have no appearance.");
}
}
catch (ApplicationException ex)
Expand All @@ -182,7 +186,8 @@ static void Main(string[] args)
{
Console.WriteLine("Exception %x (%s) while importing annotation appearance:");
Console.WriteLine(ex.Message);
Console.WriteLine("* Annotation will not have a visible appearance but is still in PDF file");
Console.WriteLine(
"* Annotation will not have a visible appearance but is still in PDF file");
}
else
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override void Call(ReportType reportType, string message, string replacem
{
message = message.Replace("%s", replacementText);
}

Console.WriteLine(message);
}
else if (replacementText != null)
Expand Down
34 changes: 20 additions & 14 deletions DotNETCore/Sample_Source/ContentCreation/AddElements/AddElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace AddElements
{
class AddElements
{
{
static void Main(string[] args)
{
Console.WriteLine("AddElements Sample:");
Expand Down Expand Up @@ -51,28 +51,32 @@ static void Main(string[] args)
DashPattern.Add(5);
DashPattern.Add(6); // Set the Dash Pattern list to [5 6]
gs.DashPattern = DashPattern;
gs.StrokeColor = new Color(0, 1.0, 0);// Green Star
gs.StrokeColor = new Color(0, 1.0, 0); // Green Star
starpath.GraphicState = gs;
starpath.PaintOp = PathPaintOpFlags.Stroke;
double CenterX = 306.0; // Center of Page
double CenterY = 396.0;
double Radius = 72 * 4.0; // 4 inches with 72 dpi
double radians72 = 72/(45/Math.Atan(1.0)); // angles must be in radians.
double radians36 = 36/(45/Math.Atan(1.0));
double radians72 = 72 / (45 / Math.Atan(1.0)); // angles must be in radians.
double radians36 = 36 / (45 / Math.Atan(1.0));
Point CenterPoint = new Point(CenterX, CenterY);
Point Point0 = new Point(CenterX, CenterY+Radius);
Point Point1 = new Point(CenterX+Radius*Math.Sin(radians72), CenterY+Radius*Math.Cos(radians72));
Point Point2 = new Point(CenterX + Radius*Math.Sin(radians36), CenterY - Radius*Math.Cos(radians36));
Point Point3 = new Point(CenterX - Radius*Math.Sin(radians36),CenterY - Radius*Math.Cos(radians36));
Point Point4 = new Point (CenterX - Radius * Math.Sin(radians72), CenterY + Radius * Math.Cos(radians72));
Point Point0 = new Point(CenterX, CenterY + Radius);
Point Point1 = new Point(CenterX + Radius * Math.Sin(radians72),
CenterY + Radius * Math.Cos(radians72));
Point Point2 = new Point(CenterX + Radius * Math.Sin(radians36),
CenterY - Radius * Math.Cos(radians36));
Point Point3 = new Point(CenterX - Radius * Math.Sin(radians36),
CenterY - Radius * Math.Cos(radians36));
Point Point4 = new Point(CenterX - Radius * Math.Sin(radians72),
CenterY + Radius * Math.Cos(radians72));
starpath.MoveTo(Point0);
starpath.AddLine(Point2);
starpath.AddLine(Point4);
starpath.AddLine(Point1);
starpath.AddLine(Point3);
starpath.AddLine(Point0);
starpath.ClosePath();
docpage.Content.AddElement(starpath); // Add the new element to the Content of the page.
docpage.Content.AddElement(starpath); // Add the new element to the Content of the page.

// Draw a pentagon around the star
Path pentpath = new Path();
Expand Down Expand Up @@ -124,17 +128,17 @@ static void Main(string[] args)
List<double> diamondDashPattern = new List<double>();
gs.DashPattern = diamondDashPattern;
gs.FillColor = new Color(1.0, 1.0, 0); // Yellow
gs.StrokeColor = new Color(153.0/255.0, 0, 0); // kind of a deep red
gs.StrokeColor = new Color(153.0 / 255.0, 0, 0); // kind of a deep red
diamond.PaintOp = PathPaintOpFlags.EoFill | PathPaintOpFlags.Stroke;

gs.Width = 1.0;
gs.LineJoin = LineJoin.BevelJoin;
diamond.GraphicState = gs;

diamond.MoveTo(new Point(306, 198));
diamond.AddLine( new Point(459, 396));
diamond.AddLine(new Point(459, 396));
diamond.AddLine(new Point(306, 594));
diamond.AddLine( new Point(153, 396));
diamond.AddLine(new Point(153, 396));
diamond.AddLine(new Point(306, 198));
diamond.ClosePath();
docpage.Content.AddElement(diamond); // Add the new element to the Content of the page.
Expand All @@ -150,7 +154,8 @@ static void Main(string[] args)
catch (ApplicationException ex)
{
if (ex.Message.Equals("The specified font could not be found.") &&
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) &&
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
.OSPlatform.Linux) &&
!System.IO.Directory.Exists("/usr/share/fonts/msttcore/"))
{
Console.WriteLine("Please install Microsoft Core Fonts on Linux first.");
Expand All @@ -159,6 +164,7 @@ static void Main(string[] args)

throw;
}

gs = new GraphicState();
gs.FillColor = new Color(0, 0, 1.0);
TextState ts = new TextState();
Expand Down
5 changes: 2 additions & 3 deletions DotNETCore/Sample_Source/ContentCreation/Clips/Clips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ static void Main(string[] args)
Clip clip = new Clip();
clip.AddElement(clipPath);
path.Clip = clip;
Console.WriteLine("Created new clip, assigned clipping path to it, and added new clip to original path.");
Console.WriteLine(
"Created new clip, assigned clipping path to it, and added new clip to original path.");

// Update the page's content and save the file with clipping
page.UpdateContent();
Expand All @@ -91,5 +92,3 @@ static void Main(string[] args)
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ static Bookmark PrepareDescendentBookmarkToRebase(Document doc, string bookmarkN
/// <param name="childBookmarkName">the name of child bookmark</param>
static void AddBookmarkAsChild(Document doc, string parentBookmarkName, string childBookmarkName)
{
doc.BookmarkRoot.FindDescendentBookmark(parentBookmarkName).AddChild(PrepareDescendentBookmarkToRebase(doc, childBookmarkName));
doc.BookmarkRoot.FindDescendentBookmark(parentBookmarkName)
.AddChild(PrepareDescendentBookmarkToRebase(doc, childBookmarkName));
}

/// <summary>
Expand All @@ -79,9 +80,11 @@ static void AddBookmarkAsChild(Document doc, string parentBookmarkName, string c
/// <param name="parentBookmarkName">name of the parent bookmark</param>
/// <param name="childBookmarkName">name of the child bookmark</param>
/// <param name="subTreeTitle">name for new subtree</param>
static void AddBookmarkAsSubtree(Document doc, int maxDepth, string parentBookmarkName, string childBookmarkName, string subTreeTitle)
static void AddBookmarkAsSubtree(Document doc, int maxDepth, string parentBookmarkName,
string childBookmarkName, string subTreeTitle)
{
doc.FindBookmark(parentBookmarkName, maxDepth).AddSubtree(PrepareDescendentBookmarkToRebase(doc, childBookmarkName), subTreeTitle);
doc.FindBookmark(parentBookmarkName, maxDepth)
.AddSubtree(PrepareDescendentBookmarkToRebase(doc, childBookmarkName), subTreeTitle);
}

static void Main(string[] args)
Expand All @@ -106,41 +109,44 @@ static void Main(string[] args)

using (Document doc = new Document(sInput))
{

Bookmark rootBookmark = doc.BookmarkRoot;

// Create a few bookmarks that point to page "0" (developer page 0, user page 1)
// with different ViewDestinations that have different Rects and zoom levels
using (Page page = doc.GetPage(0))
{
// Use CreateNewChild() to hang a new bookmark in tree off root bookmark
Bookmark bm0 = rootBookmark.CreateNewChild("(A) Root child, points to page 1, upper left corner, 300% zoom");
Bookmark bm0 =
rootBookmark.CreateNewChild(
"(A) Root child, points to page 1, upper left corner, 300% zoom");
Rect rect = page.MediaBox;
bm0.Action = CreateGoToAction(doc, rect, 3.0);

// Use CreateNewChild() to hang a new bookmark in tree off newly created bookmark
Bookmark bm1 = bm0.CreateNewChild("(B) Root child's child, points to page 1, halfway down page, 75% zoom");
Bookmark bm1 =
bm0.CreateNewChild("(B) Root child's child, points to page 1, halfway down page, 75% zoom");
rect = new Rect(rect.Left, rect.Bottom, rect.Right, rect.Top / 2.0);
bm1.Action = CreateGoToAction(doc, rect, 0.75);

// Use CreateNewSibling() to hang a new bookmark in tree next to existing bookmark
bm1 = bm0.CreateNewSibling("(C) Root child's sibling, points to page 1, 1/4 from top of page, 133% zoom");
bm1 = bm0.CreateNewSibling(
"(C) Root child's sibling, points to page 1, 1/4 from top of page, 133% zoom");
rect = new Rect(rect.Left, rect.Bottom, rect.Right, rect.Top * 0.75);
bm1.Action = CreateGoToAction(doc, rect, 1.33);

AddBookmarkAsChild(
doc,
"(C) Root child's sibling, points to page 1, 1/4 from top of page, 133% zoom",
"(B) Root child's child, points to page 1, halfway down page, 75% zoom"
);
);

AddBookmarkAsSubtree(
doc,
12,
"(A) Root child, points to page 1, upper left corner, 300% zoom",
"(C) Root child's sibling, points to page 1, 1/4 from top of page, 133% zoom",
"Bookmark formerly known as '(C) ... '"
);
);

// Create three bookmarks as new children to the root
bm0 = rootBookmark.CreateNewChild("Child 2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace GradientShade
{
class GradientShade
{
{
static void Main(string[] args)
{
Console.WriteLine("GradientShade Sample:");
Expand All @@ -44,9 +44,12 @@ static void Main(string[] args)
Double[] C1 = {1.0, 0.0, 0.0};
ExponentialFunction f = new ExponentialFunction(domain, 3, C0, C1, 1);

Point[] coords = {new Point(72, 72),
new Point(4*72, 72) };

Point[] coords =
{
new Point(72, 72),
new Point(4 * 72, 72)
};

Function[] functionList = {f};
AxialShadingPattern asp = new AxialShadingPattern(ColorSpace.DeviceRGB, coords, functionList);

Expand All @@ -55,7 +58,7 @@ static void Main(string[] args)

// Please note path does not create a default graphic state,
// so this is necessary, but for the first element only.
if (gs == null)
if (gs == null)
gs = new GraphicState();

gs.FillColor = new Color(asp);
Expand All @@ -67,8 +70,8 @@ static void Main(string[] args)
path.AddLine(new Point(11 * 72 - 36, 36));
path.ClosePath();
path.PaintOp = PathPaintOpFlags.Stroke | PathPaintOpFlags.Fill;
docpage.Content.AddElement(path); // Add the new element to the Content of the page.

docpage.Content.AddElement(path); // Add the new element to the Content of the page.
docpage.UpdateContent(); // Update the PDF page with the changed content

doc.Save(SaveFlags.Full, sOutput);
Expand Down
Loading

0 comments on commit 260a483

Please sign in to comment.