From 260a483a3d296188cda6de838b1439e26300ec78 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Mon, 31 Aug 2020 13:02:04 -0500 Subject: [PATCH] Update DotNET Core Samples, num 6 Used vendor tool to review C# files, broke lines to make them shorter, removed unneeded spaces and indents. --- .../AnnotationCopyPaste.cs | 6 +- .../Annotations/Annotations/Annotations.cs | 6 +- .../FlashAnnotCreate/FlashAnnotCreate.cs | 19 +- .../AddElements/AEReportProc.cs | 1 + .../AddElements/AddElements.cs | 34 ++-- .../ContentCreation/Clips/Clips.cs | 5 +- .../CreateBookmarks/CreateBookmarks.cs | 24 ++- .../GradientShade/GradientShade.cs | 17 +- .../MakeDocWithCalGrayColorSpace.cs | 11 +- .../MakeDocWithCalRGBColorSpace.cs | 15 +- .../MakeDocWithDeviceNColorSpace.cs | 14 +- .../MakeDocWithICCBasedColorSpace.cs | 10 +- .../MakeDocWithIndexedColorSpace.cs | 10 +- .../MakeDocWithLabColorSpace.cs | 13 +- .../MakeDocWithSeparationColorSpace.cs | 17 +- .../ContentCreation/NameTrees/NameTrees.cs | 183 ++++++++--------- .../NumberTrees/NumberTrees.cs | 114 +++++------ .../RemoteGoToActions/RemoteGoToActions.cs | 5 +- .../WriteNChannelTiff/WriteNChannelTiff.cs | 5 +- .../ContentModification/Action/Action.cs | 4 +- .../AddCollection/AddCollection.cs | 6 +- .../ChangeLayerConfiguration.cs | 1 - .../ChangeLinkColors/ChangeLinkColors.cs | 46 +++-- .../CreateLayer/CreateLayer.cs | 3 +- .../ExtendedGraphicStates.cs | 9 +- .../FlattenTransparency.cs | 30 +-- .../LaunchActions/LaunchActions.cs | 2 - .../ContentModification/MergePDF/MergePDF.cs | 7 +- .../PDFObject/PDFObject.cs | 15 +- .../PageLabels/PageLabels.cs | 8 +- .../UnderlinesAndHighlights.cs | 10 +- .../Watermark/Watermark.cs | 12 +- .../ColorConvertDocument.cs | 20 +- .../PDFAConverter/PDFAConverter.cs | 2 +- .../PDFXConverter/PDFXConverter.cs | 4 +- .../ZUGFeRDConverter/ZUGFeRDConverter.cs | 120 ++++++----- .../Images/DocToImages/DocToImages.cs | 189 ++++++++++++------ .../Images/DrawSeparations/DrawSeparations.cs | 15 +- .../Images/DrawToBitmap/DrawToBitmap.cs | 73 ++++--- .../Images/EPSSeparations/EPSSeparations.cs | 50 +++-- .../GetSeparatedImages/GetSeparatedImages.cs | 12 +- .../ImageEmbedICCProfile.cs | 17 +- .../Images/ImageExport/ImageExport.cs | 42 ++-- .../Images/ImageExtraction/ImageExtraction.cs | 13 +- .../Images/ImageFromStream/ImageFromStream.cs | 15 +- .../Images/ImageImport/ImageImport.cs | 1 - .../Images/ImageResampling/ImageResampling.cs | 10 +- .../Images/ImageSoftMask/ImageSoftMask.cs | 2 - .../Images/RasterizePage/RasterizePage.cs | 31 +-- .../ListBookmarks/ListBookmarks.cs | 3 +- .../ListLayers/ListLayers.cs | 6 +- .../Metadata/Metadata.cs | 32 +-- .../AddTextToDocument/AddTextToDocument.cs | 12 +- .../AddTextToImage/AddTextToImage.cs | 23 ++- .../Sample_Source/Other/StreamIO/StreamIO.cs | 66 +++--- .../Printing/PrintPDF/PrintPDF.cs | 63 ++++-- .../Security/Redactions/Redactions.cs | 12 +- .../Sample_Source/Text/AddGlyphs/AddGlyphs.cs | 4 +- .../Text/AddUnicodeText/AddUnicodeText.cs | 28 ++- .../Text/AddVerticalText/AddVerticalText.cs | 10 +- .../Sample_Source/Text/ListWords/ListWords.cs | 9 +- .../Text/TextExtract/TextExtract.cs | 26 ++- 62 files changed, 884 insertions(+), 688 deletions(-) diff --git a/DotNETCore/Sample_Source/Annotations/AnnotationCopyPaste/AnnotationCopyPaste.cs b/DotNETCore/Sample_Source/Annotations/AnnotationCopyPaste/AnnotationCopyPaste.cs index 9d7ad3ec..a1afe05a 100644 --- a/DotNETCore/Sample_Source/Annotations/AnnotationCopyPaste/AnnotationCopyPaste.cs +++ b/DotNETCore/Sample_Source/Annotations/AnnotationCopyPaste/AnnotationCopyPaste.cs @@ -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); @@ -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) { @@ -91,7 +92,6 @@ static void Main(string[] args) } destinationDoc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/Annotations/Annotations/Annotations.cs b/DotNETCore/Sample_Source/Annotations/Annotations/Annotations.cs index 2279f1a3..30b27fc0 100644 --- a/DotNETCore/Sample_Source/Annotations/Annotations/Annotations.cs +++ b/DotNETCore/Sample_Source/Annotations/Annotations/Annotations.cs @@ -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); } diff --git a/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs b/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs index 0c72e0cf..e317bbba 100644 --- a/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs +++ b/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs @@ -18,7 +18,6 @@ namespace FlashAnnotCreate { class FlashAnnotCreate { - static void Main(string[] args) { Console.WriteLine("FlashAnnotCreate Sample:"); @@ -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()) @@ -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); @@ -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) { @@ -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) @@ -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; diff --git a/DotNETCore/Sample_Source/ContentCreation/AddElements/AEReportProc.cs b/DotNETCore/Sample_Source/ContentCreation/AddElements/AEReportProc.cs index af82e0c2..a78f5d08 100644 --- a/DotNETCore/Sample_Source/ContentCreation/AddElements/AEReportProc.cs +++ b/DotNETCore/Sample_Source/ContentCreation/AddElements/AEReportProc.cs @@ -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) diff --git a/DotNETCore/Sample_Source/ContentCreation/AddElements/AddElements.cs b/DotNETCore/Sample_Source/ContentCreation/AddElements/AddElements.cs index b6309780..1316b2d6 100644 --- a/DotNETCore/Sample_Source/ContentCreation/AddElements/AddElements.cs +++ b/DotNETCore/Sample_Source/ContentCreation/AddElements/AddElements.cs @@ -19,7 +19,7 @@ namespace AddElements { class AddElements - { + { static void Main(string[] args) { Console.WriteLine("AddElements Sample:"); @@ -51,20 +51,24 @@ 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); @@ -72,7 +76,7 @@ static void Main(string[] args) 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(); @@ -124,7 +128,7 @@ static void Main(string[] args) List diamondDashPattern = new List(); 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; @@ -132,9 +136,9 @@ static void Main(string[] args) 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. @@ -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."); @@ -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(); diff --git a/DotNETCore/Sample_Source/ContentCreation/Clips/Clips.cs b/DotNETCore/Sample_Source/ContentCreation/Clips/Clips.cs index 62dfe8d0..a0465e97 100644 --- a/DotNETCore/Sample_Source/ContentCreation/Clips/Clips.cs +++ b/DotNETCore/Sample_Source/ContentCreation/Clips/Clips.cs @@ -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(); @@ -91,5 +92,3 @@ static void Main(string[] args) } } } - - diff --git a/DotNETCore/Sample_Source/ContentCreation/CreateBookmarks/CreateBookmarks.cs b/DotNETCore/Sample_Source/ContentCreation/CreateBookmarks/CreateBookmarks.cs index 0316f77a..e1cefeb0 100644 --- a/DotNETCore/Sample_Source/ContentCreation/CreateBookmarks/CreateBookmarks.cs +++ b/DotNETCore/Sample_Source/ContentCreation/CreateBookmarks/CreateBookmarks.cs @@ -66,7 +66,8 @@ static Bookmark PrepareDescendentBookmarkToRebase(Document doc, string bookmarkN /// the name of child bookmark 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)); } /// @@ -79,9 +80,11 @@ static void AddBookmarkAsChild(Document doc, string parentBookmarkName, string c /// name of the parent bookmark /// name of the child bookmark /// name for new subtree - 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) @@ -106,7 +109,6 @@ 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) @@ -114,17 +116,21 @@ static void Main(string[] args) 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); @@ -132,7 +138,7 @@ static void Main(string[] args) 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, @@ -140,7 +146,7 @@ static void Main(string[] args) "(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"); diff --git a/DotNETCore/Sample_Source/ContentCreation/GradientShade/GradientShade.cs b/DotNETCore/Sample_Source/ContentCreation/GradientShade/GradientShade.cs index 04ac2a0c..fdcc7309 100644 --- a/DotNETCore/Sample_Source/ContentCreation/GradientShade/GradientShade.cs +++ b/DotNETCore/Sample_Source/ContentCreation/GradientShade/GradientShade.cs @@ -18,7 +18,7 @@ namespace GradientShade { class GradientShade - { + { static void Main(string[] args) { Console.WriteLine("GradientShade Sample:"); @@ -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); @@ -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); @@ -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); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalGrayColorSpace/MakeDocWithCalGrayColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalGrayColorSpace/MakeDocWithCalGrayColorSpace.cs index dc482e46..7d130339 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalGrayColorSpace/MakeDocWithCalGrayColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalGrayColorSpace/MakeDocWithCalGrayColorSpace.cs @@ -41,7 +41,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."); @@ -54,17 +55,17 @@ static void Main(string[] args) // space with the CCIR XA/11-recommended D65 white point and // opto-electronic transfer function. - Double[] whitePoint = { 0.9505, 1.0000, 1.0890 }; - Double[] blackPoint = { 0.0, 0.0, 0.0 }; + Double[] whitePoint = {0.9505, 1.0000, 1.0890}; + Double[] blackPoint = {0.0, 0.0, 0.0}; double gamma = 2.2222; ColorSpace cs = new CalGrayColorSpace(whitePoint, blackPoint, gamma); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 0.5 }); + gs.FillColor = new Color(cs, new[] {0.5}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalRGBColorSpace/MakeDocWithCalRGBColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalRGBColorSpace/MakeDocWithCalRGBColorSpace.cs index c8fe6bd1..4ad171e6 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalRGBColorSpace/MakeDocWithCalRGBColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithCalRGBColorSpace/MakeDocWithCalRGBColorSpace.cs @@ -42,7 +42,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."); @@ -57,19 +58,19 @@ static void Main(string[] args) // // Plus a dummy value for testing the black point - Double[] whitePoint = { 0.9505, 1.0000, 1.0890 }; - Double[] blackPoint = { 0.0, 0.0, 0.0 }; - Double[] gamma = { 1.8, 1.8, 1.8 }; - Double[] matrix = { 0.4497, 0.2446, 0.0252, 0.3163, 0.6720, 0.1412, 0.1845, 0.0833, 0.9227 }; + Double[] whitePoint = {0.9505, 1.0000, 1.0890}; + Double[] blackPoint = {0.0, 0.0, 0.0}; + Double[] gamma = {1.8, 1.8, 1.8}; + Double[] matrix = {0.4497, 0.2446, 0.0252, 0.3163, 0.6720, 0.1412, 0.1845, 0.0833, 0.9227}; ColorSpace cs = new CalRGBColorSpace(whitePoint, blackPoint, gamma, matrix); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 0.3, 0.7, 0.3 }); + gs.FillColor = new Color(cs, new[] {0.3, 0.7, 0.3}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithDeviceNColorSpace/MakeDocWithDeviceNColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithDeviceNColorSpace/MakeDocWithDeviceNColorSpace.cs index ff5bbf6f..2595ed3a 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithDeviceNColorSpace/MakeDocWithDeviceNColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithDeviceNColorSpace/MakeDocWithDeviceNColorSpace.cs @@ -41,7 +41,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."); @@ -50,20 +51,21 @@ static void Main(string[] args) throw; } + ColorSpace alternate = ColorSpace.DeviceRGB; - Double[] domain = { 0.0, 1.0, 0.0, 1.0 }; - Double[] range = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; + Double[] domain = {0.0, 1.0, 0.0, 1.0}; + Double[] range = {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}; string code = "{ 0 exch }"; Function tintTransform = new PostScriptCalculatorFunction(domain, range, code); - ColorSpace cs = new DeviceNColorSpace(new[] { "DLRed", "DLBlue" }, alternate, tintTransform); + ColorSpace cs = new DeviceNColorSpace(new[] {"DLRed", "DLBlue"}, alternate, tintTransform); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 0.75, 0.75 }); + gs.FillColor = new Color(cs, new[] {0.75, 0.75}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithICCBasedColorSpace/MakeDocWithICCBasedColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithICCBasedColorSpace/MakeDocWithICCBasedColorSpace.cs index b75fd371..96286cb6 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithICCBasedColorSpace/MakeDocWithICCBasedColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithICCBasedColorSpace/MakeDocWithICCBasedColorSpace.cs @@ -44,7 +44,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) && !Directory.Exists("/usr/share/fonts/msttcore/")) { Console.WriteLine("Please install Microsoft Core Fonts on Linux first."); @@ -53,16 +54,17 @@ static void Main(string[] args) throw; } + FileStream stream = new FileStream(sInput, FileMode.Open); PDFStream pdfStream = new PDFStream(stream, doc, null, null); ColorSpace cs = new ICCBasedColorSpace(pdfStream, 3); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 1.0, 0.0, 0.0 }); + gs.FillColor = new Color(cs, new[] {1.0, 0.0, 0.0}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); @@ -71,7 +73,7 @@ static void Main(string[] args) page.UpdateContent(); doc.EmbedFonts(); - doc.Save(SaveFlags.Full, sOutput); + doc.Save(SaveFlags.Full, sOutput); } } } diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithIndexedColorSpace/MakeDocWithIndexedColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithIndexedColorSpace/MakeDocWithIndexedColorSpace.cs index 8c3129df..ab10fd10 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithIndexedColorSpace/MakeDocWithIndexedColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithIndexedColorSpace/MakeDocWithIndexedColorSpace.cs @@ -45,7 +45,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."); @@ -54,11 +55,12 @@ static void Main(string[] args) throw; } + ColorSpace baseCS = ColorSpace.DeviceRGB; List lookup = new List(); - int[] lowhi = { 0, 255 }; + int[] lowhi = {0, 255}; foreach (int r in lowhi) { foreach (int g in lowhi) @@ -75,11 +77,11 @@ static void Main(string[] args) IndexedColorSpace cs = new IndexedColorSpace(baseCS, 7, lookup); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 4.0 }); + gs.FillColor = new Color(cs, new[] {4.0}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithLabColorSpace/MakeDocWithLabColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithLabColorSpace/MakeDocWithLabColorSpace.cs index f501c2b6..da936fa7 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithLabColorSpace/MakeDocWithLabColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithLabColorSpace/MakeDocWithLabColorSpace.cs @@ -44,7 +44,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."); @@ -58,17 +59,17 @@ static void Main(string[] args) // theoretically unbounded, are defined to lie in the useful // range -128 to +127 - Double[] whitePoint = { 0.9505, 1.0000, 1.0890 }; - Double[] blackPoint = { 0.0, 0.0, 0.0 }; - Double[] range = { -128.0, 127.0, -128.0, 127.0 }; + Double[] whitePoint = {0.9505, 1.0000, 1.0890}; + Double[] blackPoint = {0.0, 0.0, 0.0}; + Double[] range = {-128.0, 127.0, -128.0, 127.0}; ColorSpace cs = new LabColorSpace(whitePoint, blackPoint, range); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new Double[] { 55, -54, 55 }); + gs.FillColor = new Color(cs, new Double[] {55, -54, 55}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); diff --git a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithSeparationColorSpace/MakeDocWithSeparationColorSpace.cs b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithSeparationColorSpace/MakeDocWithSeparationColorSpace.cs index dc52341b..fdcc81d6 100644 --- a/DotNETCore/Sample_Source/ContentCreation/MakeDocWithSeparationColorSpace/MakeDocWithSeparationColorSpace.cs +++ b/DotNETCore/Sample_Source/ContentCreation/MakeDocWithSeparationColorSpace/MakeDocWithSeparationColorSpace.cs @@ -41,7 +41,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."); @@ -50,22 +51,23 @@ static void Main(string[] args) throw; } + ColorSpace alternate = ColorSpace.DeviceRGB; - Double[] domain = { 0.0, 1.0 }; + Double[] domain = {0.0, 1.0}; int nOutputs = 3; - Double[] range = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 }; - Double[] C0 = { 0.0, 0.0, 0.0 }; - Double[] C1 = { 1.0, 0.0, 0.0 }; + Double[] range = {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}; + Double[] C0 = {0.0, 0.0, 0.0}; + Double[] C1 = {1.0, 0.0, 0.0}; Function tintTransform = new ExponentialFunction(domain, nOutputs, C0, C1, 1.0); tintTransform.Range = range; ColorSpace cs = new SeparationColorSpace("DLColor", alternate, tintTransform); GraphicState gs = new GraphicState(); - gs.FillColor = new Color(cs, new[] { 1.0 }); + gs.FillColor = new Color(cs, new[] {1.0}); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size - 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" + 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); @@ -76,7 +78,6 @@ static void Main(string[] args) doc.EmbedFonts(); doc.Save(SaveFlags.Full, sOutput); } - } } } diff --git a/DotNETCore/Sample_Source/ContentCreation/NameTrees/NameTrees.cs b/DotNETCore/Sample_Source/ContentCreation/NameTrees/NameTrees.cs index 2a2b6203..085c291d 100644 --- a/DotNETCore/Sample_Source/ContentCreation/NameTrees/NameTrees.cs +++ b/DotNETCore/Sample_Source/ContentCreation/NameTrees/NameTrees.cs @@ -31,100 +31,103 @@ static void Main() { Console.WriteLine("Initialized the library."); - // Create a new document and blank first page - Document doc = new Document(); - Rect rect = new Rect(0, 0, 612, 792); + // Create a new document and blank first page + Document doc = new Document(); + Rect rect = new Rect(0, 0, 612, 792); doc.CreatePage(Document.BeforeFirstPage, rect); - Console.WriteLine("Created new document and first page."); + Console.WriteLine("Created new document and first page."); - // Create a NumberTree and put a key-value pair in it - NameTree nametree = new NameTree(doc); + // Create a NumberTree and put a key-value pair in it + NameTree nametree = new NameTree(doc); - // Use put() to put a key-value pair in it - PDFString key = new PDFString("Bailout", doc, false, false); + // Use put() to put a key-value pair in it + PDFString key = new PDFString("Bailout", doc, false, false); PDFString value = new PDFString("Smorgasbord", doc, false, false); - nametree.Put(key, value); - Console.WriteLine("\nCreated NameTree and added first key-value pair."); - - // Put another key-value pair in it - nametree.Put(new PDFString("Brandish", doc, false, false), new PDFString("Copasetic", doc, false, false)); - - // Retrieve second entry - PDFString keysearchstring = new PDFString("Brandish", doc, false, false); - PDFObject lookup = nametree.Get(keysearchstring); - Console.WriteLine("\nRetrieving two entries:"); - Console.WriteLine(lookup); - - // Retrieve first entry - lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); - Console.WriteLine(lookup); - - // Use remove() method to remove first entry - nametree.Remove(new PDFString("Bailout", doc, false, false)); - - // Get both entries, and demonstrate that first is now gone - Console.WriteLine("\nAfter removing entry 1, we now have:"); - lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); - Console.WriteLine(lookup); - lookup = nametree.Get(new PDFString("Brandish", doc, false, false)); - Console.WriteLine(lookup); - - // Create two new NameTrees and set each to our original numbertree - NameTree abc = nametree; - NameTree xyz = nametree; - - // Show they are equal - if (abc.Equals(xyz)) - Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); - else - Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); - - // Create two new NameTrees - abc = new NameTree(doc); - xyz = new NameTree(doc); - - // Show they are not equal - if (abc.Equals(xyz)) - Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); - else - Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); - - // Get the PDFDict from the NameTree - PDFDict dict = nametree.PDFDict; - Console.WriteLine("\nThe PDFDict from the NameTree:"); - Console.WriteLine(dict); - - // Kill the NameTree object - nametree.Dispose(); - Console.WriteLine("\nDisposed the NameTree object."); - - ////////////////////////////////////////////////// - // Now use Document methods to operate on NameTree - ////////////////////////////////////////////////// - - // Create a NameTree in the document using createNameTree() method - NameTree docCreatedNameTree = doc.CreateNameTree("MyNameTree"); - docCreatedNameTree.Put(new PDFString("Argyle", doc, false, false), new PDFString("Seamstress", doc, false, false)); - Console.WriteLine("Created a NameTree object in the document."); - - // Look for the NameTree in the document by using the getNameTree() method - Console.WriteLine("\nTwo searches for NameTree using getNameTree() method; first fails, second succeeeds:"); - docCreatedNameTree = doc.GetNameTree("Garbage"); - Console.WriteLine(docCreatedNameTree); - docCreatedNameTree = doc.GetNameTree("MyNameTree"); - Console.WriteLine(docCreatedNameTree); - - // Remove the NameTree from the document by using the remove NameTree() method - Console.WriteLine("\nRemove the NameTree from the document."); - doc.RemoveNameTree("Garbage"); - docCreatedNameTree = doc.GetNameTree("MyNameTree"); - Console.WriteLine(docCreatedNameTree); - doc.RemoveNameTree("MyNameTree"); - docCreatedNameTree = doc.GetNameTree("MyNameTree"); - Console.WriteLine(docCreatedNameTree); - - // Dispose the doc object - doc.Dispose(); + nametree.Put(key, value); + Console.WriteLine("\nCreated NameTree and added first key-value pair."); + + // Put another key-value pair in it + nametree.Put(new PDFString("Brandish", doc, false, false), + new PDFString("Copasetic", doc, false, false)); + + // Retrieve second entry + PDFString keysearchstring = new PDFString("Brandish", doc, false, false); + PDFObject lookup = nametree.Get(keysearchstring); + Console.WriteLine("\nRetrieving two entries:"); + Console.WriteLine(lookup); + + // Retrieve first entry + lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); + Console.WriteLine(lookup); + + // Use remove() method to remove first entry + nametree.Remove(new PDFString("Bailout", doc, false, false)); + + // Get both entries, and demonstrate that first is now gone + Console.WriteLine("\nAfter removing entry 1, we now have:"); + lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); + Console.WriteLine(lookup); + lookup = nametree.Get(new PDFString("Brandish", doc, false, false)); + Console.WriteLine(lookup); + + // Create two new NameTrees and set each to our original numbertree + NameTree abc = nametree; + NameTree xyz = nametree; + + // Show they are equal + if (abc.Equals(xyz)) + Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); + else + Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); + + // Create two new NameTrees + abc = new NameTree(doc); + xyz = new NameTree(doc); + + // Show they are not equal + if (abc.Equals(xyz)) + Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); + else + Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); + + // Get the PDFDict from the NameTree + PDFDict dict = nametree.PDFDict; + Console.WriteLine("\nThe PDFDict from the NameTree:"); + Console.WriteLine(dict); + + // Kill the NameTree object + nametree.Dispose(); + Console.WriteLine("\nDisposed the NameTree object."); + + ////////////////////////////////////////////////// + // Now use Document methods to operate on NameTree + ////////////////////////////////////////////////// + + // Create a NameTree in the document using createNameTree() method + NameTree docCreatedNameTree = doc.CreateNameTree("MyNameTree"); + docCreatedNameTree.Put(new PDFString("Argyle", doc, false, false), + new PDFString("Seamstress", doc, false, false)); + Console.WriteLine("Created a NameTree object in the document."); + + // Look for the NameTree in the document by using the getNameTree() method + Console.WriteLine( + "\nTwo searches for NameTree using getNameTree() method; first fails, second succeeeds:"); + docCreatedNameTree = doc.GetNameTree("Garbage"); + Console.WriteLine(docCreatedNameTree); + docCreatedNameTree = doc.GetNameTree("MyNameTree"); + Console.WriteLine(docCreatedNameTree); + + // Remove the NameTree from the document by using the remove NameTree() method + Console.WriteLine("\nRemove the NameTree from the document."); + doc.RemoveNameTree("Garbage"); + docCreatedNameTree = doc.GetNameTree("MyNameTree"); + Console.WriteLine(docCreatedNameTree); + doc.RemoveNameTree("MyNameTree"); + docCreatedNameTree = doc.GetNameTree("MyNameTree"); + Console.WriteLine(docCreatedNameTree); + + // Dispose the doc object + doc.Dispose(); } } } diff --git a/DotNETCore/Sample_Source/ContentCreation/NumberTrees/NumberTrees.cs b/DotNETCore/Sample_Source/ContentCreation/NumberTrees/NumberTrees.cs index 8ae8cf90..4bd20836 100644 --- a/DotNETCore/Sample_Source/ContentCreation/NumberTrees/NumberTrees.cs +++ b/DotNETCore/Sample_Source/ContentCreation/NumberTrees/NumberTrees.cs @@ -31,53 +31,53 @@ static void Main() { Console.WriteLine("Initialized the library."); - // Create a new document and blank first page - Document doc = new Document(); - Rect rect = new Rect(0, 0, 612, 792); - doc.CreatePage(Document.BeforeFirstPage, rect); - Console.WriteLine("Created new document and first page."); - - // Create a NumberTree and put a key-value pair in it - NumberTree numbertree = new NumberTree(doc); - - // Use put() to put a key-value pair in it - int key = 1; - PDFString value = new PDFString("Smorgasbord", doc, false, false); - numbertree.Put(key, value); - Console.WriteLine("\nCreated NumberTree and added first key-value pair."); - - // Put another key-value pair in it - numbertree.Put(2, new PDFString("Copasetic", doc, false, false)); - - // Retrieve second entry - int keysearchinteger = 2; - PDFObject lookup = numbertree.Get(keysearchinteger); - Console.WriteLine("\nRetrieving two entries:"); - Console.WriteLine(lookup); - - // Retrieve first entry - lookup = numbertree.Get(1); - Console.WriteLine(lookup); - - // Use remove() method to remove first entry - numbertree.Remove(1); - - // Get 1 and 2, and demonstrate that 1 is now gone - Console.WriteLine("\nAfter removing entry 1, we now have:"); - lookup = numbertree.Get(1); - Console.WriteLine(lookup); - lookup = numbertree.Get(2); - Console.WriteLine(lookup); - - // Create two new NumberTrees and set each to our original numbertree - NumberTree abc = numbertree; - NumberTree xyz = numbertree; - - // Show they are equal - if (abc.Equals(xyz)) - Console.WriteLine("\nThe two NumberTrees abc and xyz are the same"); - else - Console.WriteLine("\nThe two NumberTrees abc and xyz are not the same"); + // Create a new document and blank first page + Document doc = new Document(); + Rect rect = new Rect(0, 0, 612, 792); + doc.CreatePage(Document.BeforeFirstPage, rect); + Console.WriteLine("Created new document and first page."); + + // Create a NumberTree and put a key-value pair in it + NumberTree numbertree = new NumberTree(doc); + + // Use put() to put a key-value pair in it + int key = 1; + PDFString value = new PDFString("Smorgasbord", doc, false, false); + numbertree.Put(key, value); + Console.WriteLine("\nCreated NumberTree and added first key-value pair."); + + // Put another key-value pair in it + numbertree.Put(2, new PDFString("Copasetic", doc, false, false)); + + // Retrieve second entry + int keysearchinteger = 2; + PDFObject lookup = numbertree.Get(keysearchinteger); + Console.WriteLine("\nRetrieving two entries:"); + Console.WriteLine(lookup); + + // Retrieve first entry + lookup = numbertree.Get(1); + Console.WriteLine(lookup); + + // Use remove() method to remove first entry + numbertree.Remove(1); + + // Get 1 and 2, and demonstrate that 1 is now gone + Console.WriteLine("\nAfter removing entry 1, we now have:"); + lookup = numbertree.Get(1); + Console.WriteLine(lookup); + lookup = numbertree.Get(2); + Console.WriteLine(lookup); + + // Create two new NumberTrees and set each to our original numbertree + NumberTree abc = numbertree; + NumberTree xyz = numbertree; + + // Show they are equal + if (abc.Equals(xyz)) + Console.WriteLine("\nThe two NumberTrees abc and xyz are the same"); + else + Console.WriteLine("\nThe two NumberTrees abc and xyz are not the same"); // Create two new NumberTrees abc = new NumberTree(doc); @@ -89,18 +89,18 @@ static void Main() else Console.WriteLine("\nThe two NumberTrees abc and xyz are not the same"); - // Get the PDFDict from the NumberTree - PDFDict dict = numbertree.PDFDict; - Console.WriteLine("\nThe PDFDict from the NumberTree:"); - Console.WriteLine(dict); - - // Dispose the NumberTree object + // Get the PDFDict from the NumberTree + PDFDict dict = numbertree.PDFDict; + Console.WriteLine("\nThe PDFDict from the NumberTree:"); + Console.WriteLine(dict); + + // Dispose the NumberTree object numbertree.Dispose(); - Console.WriteLine("\nDisposed the NumberTree object."); - - // Dispose the doc object + Console.WriteLine("\nDisposed the NumberTree object."); + + // Dispose the doc object doc.Dispose(); - Console.WriteLine("Disposed document object."); + Console.WriteLine("Disposed document object."); } } } diff --git a/DotNETCore/Sample_Source/ContentCreation/RemoteGoToActions/RemoteGoToActions.cs b/DotNETCore/Sample_Source/ContentCreation/RemoteGoToActions/RemoteGoToActions.cs index 245e9c4b..f74fddc6 100644 --- a/DotNETCore/Sample_Source/ContentCreation/RemoteGoToActions/RemoteGoToActions.cs +++ b/DotNETCore/Sample_Source/ContentCreation/RemoteGoToActions/RemoteGoToActions.cs @@ -28,7 +28,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sFileSpec = Library.ResourceDirectory + "Sample_Input/ducky.pdf"; String sOutput = "RemoteGoToActions-out.pdf"; @@ -71,7 +70,8 @@ static void Main(string[] args) FileSpecification fileSpec = new FileSpecification(doc, sFileSpec); Console.WriteLine("Path to remote document : " + fileSpec.Path); - RemoteDestination remoteDest = new RemoteDestination(doc, 0, "XYZ", new Rect(0, 0, 4 * 72, 4 * 72), 1.5); + RemoteDestination remoteDest = + new RemoteDestination(doc, 0, "XYZ", new Rect(0, 0, 4 * 72, 4 * 72), 1.5); Console.WriteLine("When the Link is clicked the remote document will open to : "); Console.WriteLine("Page Number : " + remoteDest.PageNumber); Console.WriteLine("zoom level : " + remoteDest.Zoom); @@ -85,7 +85,6 @@ static void Main(string[] args) newLink.Action = remoteAction; doc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/ContentCreation/WriteNChannelTiff/WriteNChannelTiff.cs b/DotNETCore/Sample_Source/ContentCreation/WriteNChannelTiff/WriteNChannelTiff.cs index 762497a3..33eee820 100644 --- a/DotNETCore/Sample_Source/ContentCreation/WriteNChannelTiff/WriteNChannelTiff.cs +++ b/DotNETCore/Sample_Source/ContentCreation/WriteNChannelTiff/WriteNChannelTiff.cs @@ -32,10 +32,10 @@ static void Main(string[] args) String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; String sOutput = "WriteNChannelTiff-out.tif"; - if(args.Length > 0) + if (args.Length > 0) sInput = args[0]; - if(args.Length > 1) + if (args.Length > 1) sOutput = args[1]; Console.WriteLine("Input file: " + sInput + " writing to " + sOutput); @@ -63,7 +63,6 @@ static void Main(string[] args) // Save images as multi-channeled tiff. images.Save(sOutput, ImageType.TIFF); } - } } } diff --git a/DotNETCore/Sample_Source/ContentModification/Action/Action.cs b/DotNETCore/Sample_Source/ContentModification/Action/Action.cs index 14e514cb..d9a00a23 100644 --- a/DotNETCore/Sample_Source/ContentModification/Action/Action.cs +++ b/DotNETCore/Sample_Source/ContentModification/Action/Action.cs @@ -26,7 +26,7 @@ static void Main() String sOutput = "Actions-out.pdf"; Console.WriteLine("Initialized the library."); - + Document doc = new Document(); using (new Path()) @@ -71,7 +71,7 @@ static void Main() uri.IsMap = true; Console.WriteLine("Complete changed URI:" + doc.BaseURI + uri.URI); - + if (uri.IsMap) Console.WriteLine("Send mouse coordinates"); else diff --git a/DotNETCore/Sample_Source/ContentModification/AddCollection/AddCollection.cs b/DotNETCore/Sample_Source/ContentModification/AddCollection/AddCollection.cs index f3bc5abc..a8080375 100644 --- a/DotNETCore/Sample_Source/ContentModification/AddCollection/AddCollection.cs +++ b/DotNETCore/Sample_Source/ContentModification/AddCollection/AddCollection.cs @@ -38,7 +38,7 @@ static void Main(string[] args) Document doc = new Document(sInput); - Console.WriteLine("Input file: " + sInput + ". Writing to " + sOutput); + Console.WriteLine("Input file: " + sInput + ". Writing to " + sOutput); // Check if document already has collection Collection collection = doc.Collection; @@ -49,6 +49,7 @@ static void Main(string[] args) doc.CreateCollection(); collection = doc.Collection; } + // Create a couple of schema fields CollectionSchemaField field = new CollectionSchemaField("Description", SchemaFieldSubtype.Description); field.Name = "DescriptionField"; @@ -74,7 +75,8 @@ static void Main(string[] args) // described in the parent collection dictionary. // The array form is used to allow additional fields to contribute // to the sort, where each additional field is used to break ties. - System.Collections.Generic.IList colSort = new System.Collections.Generic.List(); + System.Collections.Generic.IList colSort = + new System.Collections.Generic.List(); colSort.Add(new CollectionSortItem("Description", false)); colSort.Add(new CollectionSortItem("Number", true)); diff --git a/DotNETCore/Sample_Source/ContentModification/ChangeLayerConfiguration/ChangeLayerConfiguration.cs b/DotNETCore/Sample_Source/ContentModification/ChangeLayerConfiguration/ChangeLayerConfiguration.cs index 6bc1d815..fe924ddd 100644 --- a/DotNETCore/Sample_Source/ContentModification/ChangeLayerConfiguration/ChangeLayerConfiguration.cs +++ b/DotNETCore/Sample_Source/ContentModification/ChangeLayerConfiguration/ChangeLayerConfiguration.cs @@ -124,4 +124,3 @@ static void Main(string[] args) } } } - diff --git a/DotNETCore/Sample_Source/ContentModification/ChangeLinkColors/ChangeLinkColors.cs b/DotNETCore/Sample_Source/ContentModification/ChangeLinkColors/ChangeLinkColors.cs index 5b638cd9..03a07503 100644 --- a/DotNETCore/Sample_Source/ContentModification/ChangeLinkColors/ChangeLinkColors.cs +++ b/DotNETCore/Sample_Source/ContentModification/ChangeLinkColors/ChangeLinkColors.cs @@ -42,25 +42,25 @@ static void Main(string[] args) sOutput = args[1]; Console.WriteLine("Input file: " + sInput + ", writing to " + sOutput); - + Document doc = new Document(sInput); Console.WriteLine("Opened a document."); Page page = doc.GetPage(0); - + List linkAnnots = new List(); - + // First, make a list of all the link annotations on the page. - for(int i=0; i < page.NumAnnotations; i++) + for (int i = 0; i < page.NumAnnotations; i++) { Annotation annot = page.GetAnnotation(i); - if(annot is LinkAnnotation) + if (annot is LinkAnnotation) { linkAnnots.Add(annot as LinkAnnotation); } } - + Content content = page.Content; // Iterate over the page's content and process the Text objects. @@ -81,24 +81,24 @@ static void FindAndProcessText(Content content, List linkAnnots) Element element = content.GetElement(i); if (element is Container) { - Content nestedContent = ((Container)element).Content; + Content nestedContent = ((Container) element).Content; FindAndProcessText(nestedContent, linkAnnots); } else if (element is Form) { - Content nestedContent = ((Form)element).Content; + Content nestedContent = ((Form) element).Content; FindAndProcessText(nestedContent, linkAnnots); } else if (element is Group) { - Content nestedContent = ((Group)element).Content; + Content nestedContent = ((Group) element).Content; FindAndProcessText(nestedContent, linkAnnots); } else if (element is Text) { Console.WriteLine("Found a Text object."); CheckCharactersInText(element as Text, linkAnnots); - } + } } } @@ -106,19 +106,19 @@ static void CheckCharactersInText(Text txt, List linkAnnots) { // This function checks to see if any characters in this Text object // fall within the bounds of the LinkAnnotations on this page. - for(int i=0; i < linkAnnots.Count; i++) - { + for (int i = 0; i < linkAnnots.Count; i++) + { int charIndex; // Find the index of the first character in this Text object that intersects // with the LinkAnnotation rectangle, if there is one. - for(charIndex = 0; charIndex < txt.NumberOfCharacters; charIndex++) - { - if(txt.RectIntersectsCharacter(linkAnnots[i].Rect, charIndex)) + for (charIndex = 0; charIndex < txt.NumberOfCharacters; charIndex++) + { + if (txt.RectIntersectsCharacter(linkAnnots[i].Rect, charIndex)) break; } - - if(charIndex >= txt.NumberOfCharacters) + + if (charIndex >= txt.NumberOfCharacters) { // The LinkAnnotation rect falls outside of this Text object. // Try the next rect on the list. @@ -142,16 +142,18 @@ static void CheckCharactersInText(Text txt, List linkAnnots) // getting false positives or false negatives, you may need to tweak the // heuristic. Matrix charMatrix = txt.GetTextMatrixForCharacter(charIndex); - bool hWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLx) < Math.Ceiling(charMatrix.H)) && (Math.Floor(charMatrix.H) < Math.Ceiling(linkAnnots[i].Rect.URx)); - bool vWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLy) < Math.Ceiling(charMatrix.V)) && (Math.Floor(charMatrix.V) < Math.Ceiling(linkAnnots[i].Rect.URy)); + bool hWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLx) < Math.Ceiling(charMatrix.H)) && + (Math.Floor(charMatrix.H) < Math.Ceiling(linkAnnots[i].Rect.URx)); + bool vWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLy) < Math.Ceiling(charMatrix.V)) && + (Math.Floor(charMatrix.V) < Math.Ceiling(linkAnnots[i].Rect.URy)); if (hWithinLinkBox && vWithinLinkBox) { Console.WriteLine("Found a character that falls within the bounds of LinkAnnotation " + i); - + int startRunIndex; - - if(charIndex == 0) + + if (charIndex == 0) { // This is the first character, no splitting needed. startRunIndex = 0; diff --git a/DotNETCore/Sample_Source/ContentModification/CreateLayer/CreateLayer.cs b/DotNETCore/Sample_Source/ContentModification/CreateLayer/CreateLayer.cs index c75e368b..0918b112 100644 --- a/DotNETCore/Sample_Source/ContentModification/CreateLayer/CreateLayer.cs +++ b/DotNETCore/Sample_Source/ContentModification/CreateLayer/CreateLayer.cs @@ -103,7 +103,8 @@ public static void AssociateOCGWithContainer(Document doc, OptionalContentGroup // 'typical' usage; other options can be used to create an 'inverting' layer // (i.e. 'Display this content when the layer is turned OFF'), or to make the // Container's visibility depend on several OptionalContentGroups - OptionalContentMembershipDict ocmd = new OptionalContentMembershipDict(doc, new[] {ocg}, VisibilityPolicy.AnyOn); + OptionalContentMembershipDict ocmd = + new OptionalContentMembershipDict(doc, new[] {ocg}, VisibilityPolicy.AnyOn); // Associate the Container with the OptionalContentMembershipDict cont.OptionalContentMembershipDict = ocmd; diff --git a/DotNETCore/Sample_Source/ContentModification/ExtendedGraphicStates/ExtendedGraphicStates.cs b/DotNETCore/Sample_Source/ContentModification/ExtendedGraphicStates/ExtendedGraphicStates.cs index a60c090a..49f1c536 100644 --- a/DotNETCore/Sample_Source/ContentModification/ExtendedGraphicStates/ExtendedGraphicStates.cs +++ b/DotNETCore/Sample_Source/ContentModification/ExtendedGraphicStates/ExtendedGraphicStates.cs @@ -45,7 +45,8 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage 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."); @@ -54,6 +55,7 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage throw; } + GraphicState gsText = new GraphicState(); gsText.FillColor = new Color(0, 0, 1.0); TextState ts = new TextState(); @@ -170,6 +172,7 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage xgs.BlendMode = BlendMode.Luminosity; tr = new TextRun("Luminosity", f, gsText, ts, m); } + t.AddRun(tr); docpage.Content.AddElement(t); docpage.UpdateContent(); @@ -202,7 +205,8 @@ static void Main(string[] args) if (args.Length > 2) sOutput = args[2]; - Console.WriteLine("Input files: " + sInput1 + " and " + sInput2 + ". Saving to output file: " + sOutput); + Console.WriteLine("Input files: " + sInput1 + " and " + sInput2 + ". Saving to output file: " + + sOutput); Document doc = new Document(); @@ -215,7 +219,6 @@ static void Main(string[] args) doc.EmbedFonts(); doc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/ContentModification/FlattenTransparency/FlattenTransparency.cs b/DotNETCore/Sample_Source/ContentModification/FlattenTransparency/FlattenTransparency.cs index d5416d47..a4cb1965 100644 --- a/DotNETCore/Sample_Source/ContentModification/FlattenTransparency/FlattenTransparency.cs +++ b/DotNETCore/Sample_Source/ContentModification/FlattenTransparency/FlattenTransparency.cs @@ -34,11 +34,10 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput1 = Library.ResourceDirectory + "Sample_Input/trans_1page.pdf"; - String sOutput1 = "FlattenTransparency-out1.pdf"; + String sOutput1 = "FlattenTransparency-out1.pdf"; String sInput2 = Library.ResourceDirectory + "Sample_Input/trans_multipage.pdf"; - String sOutput2 = "FlattenTransparency-out2.pdf"; + String sOutput2 = "FlattenTransparency-out2.pdf"; if (args.Length > 0) sInput1 = args[0]; @@ -50,7 +49,7 @@ static void Main(string[] args) sOutput2 = args[3]; // Open a document with a single page. - Document doc1 = new Document(sInput1); + Document doc1 = new Document(sInput1); // Verify that the page has transparency. The parameter indicates // whether to include the appearances of annotations or not when @@ -59,7 +58,7 @@ static void Main(string[] args) bool isTransparent = pg1.HasTransparency(true); // If there is transparency, flatten the document. - if(isTransparent) + if (isTransparent) { // Flattening the document will check each page for transparency. // If a page has transparency, PDFL will create a new, flattened @@ -67,24 +66,24 @@ static void Main(string[] args) // new one. Because of this, make sure to dispose of outstanding Page objects // that refer to pages in the Document before calling flattenTransparency. pg1.Dispose(); - + doc1.FlattenTransparency(); Console.WriteLine("Flattened single page document " + sInput1 + " as " + sOutput1 + "."); doc1.Save(SaveFlags.Full, sOutput1); } - + // Open a document with multiple pages. Document doc2 = new Document(sInput2); - + // Iterate over the pages of the document and find the first page that has // transparency. isTransparent = false; int totalPages = doc2.NumPages; int pageCounter = 0; - while(!isTransparent && pageCounter <= totalPages) + while (!isTransparent && pageCounter <= totalPages) { Page pg = doc2.GetPage(pageCounter); - if(pg.HasTransparency(true)) + if (pg.HasTransparency(true)) { isTransparent = true; // Explicitly delete the page here, to ensure the reference is gone before we @@ -92,10 +91,11 @@ static void Main(string[] args) pg.Dispose(); break; } + pageCounter++; } - - if(isTransparent) + + if (isTransparent) { // Set up some parameters for the flattening. FlattenTransparencyParams ftParams = new FlattenTransparencyParams(); @@ -103,14 +103,14 @@ static void Main(string[] args) // The Quality setting indicates the percentage (0%-100%) of vector information // that is preserved. Lower values result in higher rasterization of vectors. ftParams.Quality = 50; - + // Flatten transparency in the document, starting from the first page // that has transparency. doc2.FlattenTransparency(ftParams, pageCounter, Document.LastPage); Console.WriteLine("Flattened a multi-page document " + sInput2 + " as " + sOutput2 + "."); - doc2.Save(SaveFlags.Full, sOutput2); + doc2.Save(SaveFlags.Full, sOutput2); } } - } + } } } diff --git a/DotNETCore/Sample_Source/ContentModification/LaunchActions/LaunchActions.cs b/DotNETCore/Sample_Source/ContentModification/LaunchActions/LaunchActions.cs index c0ad7df8..19ada9d5 100644 --- a/DotNETCore/Sample_Source/ContentModification/LaunchActions/LaunchActions.cs +++ b/DotNETCore/Sample_Source/ContentModification/LaunchActions/LaunchActions.cs @@ -22,7 +22,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput = Library.ResourceDirectory + "Sample_Input/ducky.pdf"; String sOutput = "LaunchActions-out.pdf"; @@ -69,7 +68,6 @@ static void Main(string[] args) newLink.Action = launch; doc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/ContentModification/MergePDF/MergePDF.cs b/DotNETCore/Sample_Source/ContentModification/MergePDF/MergePDF.cs index b23e2240..cd54967b 100644 --- a/DotNETCore/Sample_Source/ContentModification/MergePDF/MergePDF.cs +++ b/DotNETCore/Sample_Source/ContentModification/MergePDF/MergePDF.cs @@ -25,7 +25,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput1 = Library.ResourceDirectory + "Sample_Input/merge_pdf1.pdf"; String sInput2 = Library.ResourceDirectory + "Sample_Input/merge_pdf2.pdf"; String sOutput = "MergePDF-out.pdf"; @@ -49,12 +48,14 @@ static void Main(string[] args) { doc1.InsertPages(Document.LastPage, doc2, 0, Document.AllPages, PageInsertFlags.All); } - catch(LibraryException ex) + catch (LibraryException ex) { - if (!ex.Message.Contains("An incorrect structure tree was found in the PDF file but operation continued")) + if (!ex.Message.Contains( + "An incorrect structure tree was found in the PDF file but operation continued")) { throw; } + Console.Out.WriteLine(ex.Message); } diff --git a/DotNETCore/Sample_Source/ContentModification/PDFObject/PDFObject.cs b/DotNETCore/Sample_Source/ContentModification/PDFObject/PDFObject.cs index 306c5fac..f2e57f9a 100644 --- a/DotNETCore/Sample_Source/ContentModification/PDFObject/PDFObject.cs +++ b/DotNETCore/Sample_Source/ContentModification/PDFObject/PDFObject.cs @@ -29,7 +29,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput = Library.ResourceDirectory + "Sample_Input/sample_links.pdf"; String sOutput = "PDFObject-out.pdf"; @@ -44,13 +43,13 @@ static void Main(string[] args) Document doc = new Document(sInput); Page page = doc.GetPage(0); - LinkAnnotation annot = (LinkAnnotation)page.GetAnnotation(1); - URIAction uri = (URIAction)annot.Action; + LinkAnnotation annot = (LinkAnnotation) page.GetAnnotation(1); + URIAction uri = (URIAction) annot.Action; // Print some info about the URI action, before we modify it Console.WriteLine("Initial URL: " + uri.URI); Console.WriteLine("Is Map property: " + uri.IsMap); - + // Modify the URIAction // // A URI action is a dictionary containing: @@ -66,8 +65,8 @@ static void Main(string[] args) // Create a new string object PDFString uri_string = new PDFString("http://www.google.com", doc, false, false); - uri_dict.Put("URI", uri_string); // Change the URI (replaces the old one) - uri_dict.Remove("IsMap"); // Remove the IsMap entry + uri_dict.Put("URI", uri_string); // Change the URI (replaces the old one) + uri_dict.Remove("IsMap"); // Remove the IsMap entry // Check that we deleted the IsMap entry Console.WriteLine("Does this dictionary have an IsMap entry? " + uri_dict.Contains("IsMap")); @@ -78,8 +77,8 @@ static void Main(string[] args) // Check the modified contents of the link doc = new Document(sOutput); page = doc.GetPage(0); - annot = (LinkAnnotation)page.GetAnnotation(1); - uri = (URIAction)annot.Action; + annot = (LinkAnnotation) page.GetAnnotation(1); + uri = (URIAction) annot.Action; Console.WriteLine("Modified URL: " + uri.URI); Console.WriteLine("Is Map property (if not present, defaults to false): " + uri.IsMap); diff --git a/DotNETCore/Sample_Source/ContentModification/PageLabels/PageLabels.cs b/DotNETCore/Sample_Source/ContentModification/PageLabels/PageLabels.cs index 0d573f4d..3a684bba 100644 --- a/DotNETCore/Sample_Source/ContentModification/PageLabels/PageLabels.cs +++ b/DotNETCore/Sample_Source/ContentModification/PageLabels/PageLabels.cs @@ -59,7 +59,7 @@ static void Main(string[] args) Console.WriteLine("Added page range starting on page 5."); // Change the properties of the third page range - labels = doc.PageLabels; // Get a freshly sorted list + labels = doc.PageLabels; // Get a freshly sorted list labels[2].Prefix = "Section 3-"; labels[2].FirstNumberInRange = 2; doc.PageLabels = labels; @@ -67,12 +67,12 @@ static void Main(string[] args) Console.WriteLine("Changed the prefix for the third range."); // Now walk the list of page labels - foreach( PageLabel label in doc.PageLabels ) + foreach (PageLabel label in doc.PageLabels) { Console.WriteLine("Label range starts on page " + label.StartPageIndex - + ", ends on page " + label.EndPageIndex); + + ", ends on page " + label.EndPageIndex); Console.WriteLine("The prefix is '" + label.Prefix - + "' and begins with number " + label.FirstNumberInRange); + + "' and begins with number " + label.FirstNumberInRange); Console.WriteLine(); } } diff --git a/DotNETCore/Sample_Source/ContentModification/UnderlinesAndHighlights/UnderlinesAndHighlights.cs b/DotNETCore/Sample_Source/ContentModification/UnderlinesAndHighlights/UnderlinesAndHighlights.cs index b6e3d413..aa0a7e4d 100644 --- a/DotNETCore/Sample_Source/ContentModification/UnderlinesAndHighlights/UnderlinesAndHighlights.cs +++ b/DotNETCore/Sample_Source/ContentModification/UnderlinesAndHighlights/UnderlinesAndHighlights.cs @@ -59,14 +59,16 @@ static void Main(string[] args) // Store the Quads of all "Cloudy" words in a list for later use in // creating the annotation. if (w.Text.ToLower().Equals("cloudy") || - ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && - w.Text.ToLower().StartsWith("cloudy"))) + ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == + WordAttributeFlags.HasTrailingPunctuation && + w.Text.ToLower().StartsWith("cloudy"))) cloudyQuads.AddRange(w.Quads); // Store the Quads of all "Rain" words if (w.Text.ToLower().Equals("rain") || - ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && - w.Text.ToLower().StartsWith("rain"))) + ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == + WordAttributeFlags.HasTrailingPunctuation && + w.Text.ToLower().StartsWith("rain"))) rainQuads.AddRange(w.Quads); } diff --git a/DotNETCore/Sample_Source/ContentModification/Watermark/Watermark.cs b/DotNETCore/Sample_Source/ContentModification/Watermark/Watermark.cs index 721ba86b..0f5ccd37 100644 --- a/DotNETCore/Sample_Source/ContentModification/Watermark/Watermark.cs +++ b/DotNETCore/Sample_Source/ContentModification/Watermark/Watermark.cs @@ -28,8 +28,8 @@ static void Main(string[] args) { Console.WriteLine("Watermark Sample:"); // ReSharper disable once UnusedVariable - using( Library lib = new Library()) { - + using (Library lib = new Library()) + { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; @@ -45,7 +45,8 @@ static void Main(string[] args) if (args.Length > 2) sOutput = args[2]; - Console.WriteLine("Adding watermark from " + sWatermark + " to " + sInput +" and saving to " + sOutput); + Console.WriteLine("Adding watermark from " + sWatermark + " to " + sInput + " and saving to " + + sOutput); Document doc = new Document(sInput); @@ -62,7 +63,7 @@ static void Main(string[] args) watermarkParams.TargetRange.PageSpec = PageSpec.OddPagesOnly; WatermarkTextParams watermarkTextParams = new WatermarkTextParams(); - Color color = new Color(109.0f/255.0f, 15.0f/255.0f, 161.0f/255.0f); + Color color = new Color(109.0f / 255.0f, 15.0f / 255.0f, 161.0f / 255.0f); watermarkTextParams.Color = color; watermarkTextParams.Text = "Multiline\nWatermark"; @@ -75,8 +76,7 @@ static void Main(string[] args) doc.EmbedFonts(); doc.Save(SaveFlags.Full | SaveFlags.Linearized, sOutput); - - } + } } } } diff --git a/DotNETCore/Sample_Source/DocumentConversion/ColorConvertDocument/ColorConvertDocument.cs b/DotNETCore/Sample_Source/DocumentConversion/ColorConvertDocument/ColorConvertDocument.cs index edf98b36..0d685e87 100644 --- a/DotNETCore/Sample_Source/DocumentConversion/ColorConvertDocument/ColorConvertDocument.cs +++ b/DotNETCore/Sample_Source/DocumentConversion/ColorConvertDocument/ColorConvertDocument.cs @@ -34,7 +34,9 @@ static void Main(string[] args) paths.Add(Library.ResourceDirectory + "Fonts/"); // ReSharper disable once UnusedVariable - using (Library lib = new Library(paths, Library.ResourceDirectory + "CMap/", Library.ResourceDirectory + "Unicode/", Library.ResourceDirectory + "Color", LibraryFlags.DisableMemorySuballocator)) + using (Library lib = new Library(paths, Library.ResourceDirectory + "CMap/", + Library.ResourceDirectory + "Unicode/", Library.ResourceDirectory + "Color", + LibraryFlags.DisableMemorySuballocator)) { Console.WriteLine("Initialized the library."); @@ -51,17 +53,17 @@ static void Main(string[] args) Document doc = new Document(sInput); - /* Create the list of color conversion actions to be applied to the document. Each object in the document is compared - * against the selection criteria for each of the actions until a matching action is found. Actions do not chain, - * except in the case of aliased ink definitions - */ + /* Create the list of color conversion actions to be applied to the document. Each object in the document is compared + * against the selection criteria for each of the actions until a matching action is found. Actions do not chain, + * except in the case of aliased ink definitions + */ List colorConvActions = new List(); ColorConvertActions action = new ColorConvertActions(); - /* In this example, make any object in the document a candidate for color conversion. Also allow for any kind of Color Space. - * The ColorConvertObjAttrs values can be combined together for more specific matching patterns using the | operator. - * This is also true for Color Spaces. - */ + /* In this example, make any object in the document a candidate for color conversion. Also allow for any kind of Color Space. + * The ColorConvertObjAttrs values can be combined together for more specific matching patterns using the | operator. + * This is also true for Color Spaces. + */ action.MustMatchAnyAttrs = ColorConvertObjAttrs.ColorConvAnyObject; action.MustMatchAnyCSAttrs = ColorConvertCSpaceType.ColorConvAnySpace; action.IntentToMatch = RenderIntent.UseProfileIntent; diff --git a/DotNETCore/Sample_Source/DocumentConversion/PDFAConverter/PDFAConverter.cs b/DotNETCore/Sample_Source/DocumentConversion/PDFAConverter/PDFAConverter.cs index b0750ee5..b6ea796e 100644 --- a/DotNETCore/Sample_Source/DocumentConversion/PDFAConverter/PDFAConverter.cs +++ b/DotNETCore/Sample_Source/DocumentConversion/PDFAConverter/PDFAConverter.cs @@ -37,7 +37,7 @@ static void Main(string[] args) if (args.Length > 1) sOutput = args[1]; - Console.WriteLine("Converting " + sInput + ", output file is " + sOutput); + Console.WriteLine("Converting " + sInput + ", output file is " + sOutput); using (Document doc = new Document(sInput)) { diff --git a/DotNETCore/Sample_Source/DocumentConversion/PDFXConverter/PDFXConverter.cs b/DotNETCore/Sample_Source/DocumentConversion/PDFXConverter/PDFXConverter.cs index f6afbcf3..55941fee 100644 --- a/DotNETCore/Sample_Source/DocumentConversion/PDFXConverter/PDFXConverter.cs +++ b/DotNETCore/Sample_Source/DocumentConversion/PDFXConverter/PDFXConverter.cs @@ -70,9 +70,9 @@ static void Main(string[] args) // Note that the returned document will have its major and minor // version set--this is required for PDF/X compliance. This is only // visible AFTER you save the document. - Console.WriteLine(sOutput + " has version number: " + pdfxDoc.MajorVersion + "." + pdfxDoc.MinorVersion); + Console.WriteLine(sOutput + " has version number: " + pdfxDoc.MajorVersion + "." + + pdfxDoc.MinorVersion); } - } } } diff --git a/DotNETCore/Sample_Source/DocumentConversion/ZUGFeRDConverter/ZUGFeRDConverter.cs b/DotNETCore/Sample_Source/DocumentConversion/ZUGFeRDConverter/ZUGFeRDConverter.cs index 2d7e7617..40987c02 100644 --- a/DotNETCore/Sample_Source/DocumentConversion/ZUGFeRDConverter/ZUGFeRDConverter.cs +++ b/DotNETCore/Sample_Source/DocumentConversion/ZUGFeRDConverter/ZUGFeRDConverter.cs @@ -41,7 +41,8 @@ static void Main(string[] args) String sInputInoviceXML = args[1]; String sOutput = "ZUGFeRDConverter-out.pdf"; - Console.WriteLine("Converting " + sInputPDF + " with " + sInputInoviceXML + ", output file is " + sOutput); + Console.WriteLine("Converting " + sInputPDF + " with " + sInputInoviceXML + ", output file is " + + sOutput); // Step 1) Open the input PDF using (Document doc = new Document(sInputPDF)) @@ -99,55 +100,84 @@ static void AddMetadataAndExtensionSchema(Document document, string sInputInovic //Set the XMP ZUGFeRD properties document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathDocumentType, pathDocumentTypeValue); - document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathDocumentFileName, pathDocumentFileNameValue); - document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathConformanceLevel, pathConformanceLevelValue); + document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathDocumentFileName, + pathDocumentFileNameValue); + document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathConformanceLevel, + pathConformanceLevelValue); document.SetXMPMetadataProperty(namespaceURI, namespacePrefix, pathVersion, pathVersionValue); //Create the PDF/A Extension Schema for ZUGFeRD since it's not part of the PDF/A standard. string extensionSchema; extensionSchema = "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "ZUGFeRD PDFA Extension Schema" + Environment.NewLine - + "urn:ferd:pdfa:CrossIndustryDocument:invoice:2p0#" + Environment.NewLine - + "zf" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "DocumentFileName" + Environment.NewLine - + "Text" + Environment.NewLine - + "external" + Environment.NewLine - + "name of the embedded XML invoice file" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "DocumentType" + Environment.NewLine - + "Text" + Environment.NewLine - + "external" + Environment.NewLine - + "INVOICE" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "Version" + Environment.NewLine - + "Text" + Environment.NewLine - + "external" + Environment.NewLine - + "The actual version of the ZUGFeRD XML schema" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "ConformanceLevel" + Environment.NewLine - + "Text" + Environment.NewLine - + "external" + Environment.NewLine - + "The conformance level of the embedded ZUGFeRD data" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine - + "" + Environment.NewLine; + + "xmlns:pdfaExtension=\"http://www.aiim.org/pdfa/ns/extension/\"" + + Environment.NewLine + + "xmlns:pdfaSchema=\"http://www.aiim.org/pdfa/ns/schema#\"" + + Environment.NewLine + + "xmlns:pdfaProperty=\"http://www.aiim.org/pdfa/ns/property#\">" + + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + + Environment.NewLine + + "ZUGFeRD PDFA Extension Schema" + + Environment.NewLine + + "urn:ferd:pdfa:CrossIndustryDocument:invoice:2p0#" + + Environment.NewLine + + "zf" + + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + + Environment.NewLine + + "DocumentFileName" + + Environment.NewLine + + "Text" + + Environment.NewLine + + "external" + + Environment.NewLine + + "name of the embedded XML invoice file" + + Environment.NewLine + + "" + Environment.NewLine + + "" + + Environment.NewLine + + "DocumentType" + + Environment.NewLine + + "Text" + + Environment.NewLine + + "external" + + Environment.NewLine + + "INVOICE" + + Environment.NewLine + + "" + Environment.NewLine + + "" + + Environment.NewLine + + "Version" + + Environment.NewLine + + "Text" + + Environment.NewLine + + "external" + + Environment.NewLine + + "The actual version of the ZUGFeRD XML schema" + + Environment.NewLine + + "" + Environment.NewLine + + "" + + Environment.NewLine + + "ConformanceLevel" + + Environment.NewLine + + "Text" + + Environment.NewLine + + "external" + + Environment.NewLine + + "The conformance level of the embedded ZUGFeRD data" + + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine + + "" + Environment.NewLine; string xmpMetadata = document.XMPMetadata; diff --git a/DotNETCore/Sample_Source/Images/DocToImages/DocToImages.cs b/DotNETCore/Sample_Source/Images/DocToImages/DocToImages.cs index ad762ffc..55775e95 100644 --- a/DotNETCore/Sample_Source/Images/DocToImages/DocToImages.cs +++ b/DotNETCore/Sample_Source/Images/DocToImages/DocToImages.cs @@ -23,42 +23,44 @@ namespace DocToImages { public class DocToImagesOptions { - ImageType outputformat = ImageType.Invalid; - ColorSpace color = ColorSpace.DeviceRGB; - bool grayhalftone; - bool firstpageonly; - int quality; - double hres = 300.0; - double vres = 300.0; - List fontdirs = new List(0); - int hpixelsize; - int vpixelsize; + ImageType outputformat = ImageType.Invalid; + ColorSpace color = ColorSpace.DeviceRGB; + bool grayhalftone; + bool firstpageonly; + int quality; + double hres = 300.0; + double vres = 300.0; + List fontdirs = new List(0); + int hpixelsize; + int vpixelsize; CompressionCode compress = CompressionCode.Default; - string pageregion = "crop"; - List PageList = new List(0); - int evenoddpages; // 1 = all odd pages, 2 = all even pages. - string outputfilename = ""; - string outputdirname = ""; - SmoothFlags smoothingflags = SmoothFlags.None; - bool reversegray; - bool blackisone; - bool multipage; - int ZeroSuffix; - bool asprinted; + string pageregion = "crop"; + List PageList = new List(0); + int evenoddpages; // 1 = all odd pages, 2 = all even pages. + string outputfilename = ""; + string outputdirname = ""; + SmoothFlags smoothingflags = SmoothFlags.None; + bool reversegray; + bool blackisone; + bool multipage; + int ZeroSuffix; + bool asprinted; public void setoutputformat(ImageType format) { outputformat = format; } + public ImageType getoutputformat() { - return(outputformat); + return (outputformat); } public void setcolor(ColorSpace outputcolor) { color = outputcolor; } + public ColorSpace getcolor() { return (color); @@ -68,6 +70,7 @@ public void setgrayhalftone(bool halftone) { grayhalftone = halftone; } + public bool getgrayhalftone() { return (grayhalftone); @@ -77,6 +80,7 @@ public void setfirst(bool firstonly) { firstpageonly = firstonly; } + public bool getfirst() { return (firstpageonly); @@ -86,6 +90,7 @@ public void setquality(int q) { quality = q; } + public int getquality() { return (quality); @@ -95,6 +100,7 @@ public void sethres(double h) { hres = h; } + public double gethres() { return (hres); @@ -104,6 +110,7 @@ public void setvres(double v) { vres = v; } + public double getvres() { return (vres); @@ -127,6 +134,7 @@ public void sethpixels(int h) { hpixelsize = h; } + public int gethpixels() { return (hpixelsize); @@ -136,6 +144,7 @@ public void setvpixels(int v) { vpixelsize = v; } + public int getvpixels() { return (vpixelsize); @@ -145,6 +154,7 @@ public void setcompress(CompressionCode cc) { compress = cc; } + public CompressionCode getcompress() { return (compress); @@ -154,6 +164,7 @@ public void setpageregion(string region) { pageregion = region; } + public string getpageregion() { return (pageregion); @@ -171,7 +182,7 @@ public void appendpagelist(int pageno) public List getpagelist() { - return(PageList); + return (PageList); } /* @@ -204,6 +215,7 @@ public void setoutputfile(string outputfile) { outputfilename = outputfile; } + public string getoutputfile() { return (outputfilename); @@ -213,6 +225,7 @@ public void setoutputdir(string outputdir) { outputdirname = outputdir; } + public string getoutputdir() { return (outputdirname); @@ -222,6 +235,7 @@ public void setsmooth(SmoothFlags flags) { smoothingflags = flags; } + public SmoothFlags getsmooth() { return (smoothingflags); @@ -231,6 +245,7 @@ public void setreversegray(bool reverse) { reversegray = reverse; } + public bool getreversegray() { return (reversegray); @@ -240,6 +255,7 @@ public void setblackisone(bool isblackone) { blackisone = isblackone; } + public bool getblackisone() { return (blackisone); @@ -249,6 +265,7 @@ public void setmultipage(bool multi) { multipage = multi; } + public bool getmultipage() { return (multipage); @@ -258,6 +275,7 @@ public void setZeroSuffix(int numdigs) { ZeroSuffix = numdigs; } + public int getZeroSuffix() { return (ZeroSuffix); @@ -267,6 +285,7 @@ public void setasprinted(bool asp) { asprinted = asp; } + public bool getasprinted() { return (asprinted); @@ -274,7 +293,7 @@ public bool getasprinted() public bool checkformattype() { - return ( outputformat != ImageType.Invalid ); + return (outputformat != ImageType.Invalid); } public bool checkcolorspacegrayhalftone() @@ -312,7 +331,8 @@ public bool checkformatcompressionjpg() public bool checkcompressionnone() { if (compress == CompressionCode.NONE) - return (outputformat == ImageType.BMP || outputformat == ImageType.PNG || outputformat == ImageType.TIFF); + return (outputformat == ImageType.BMP || outputformat == ImageType.PNG || + outputformat == ImageType.TIFF); else return true; } @@ -383,7 +403,7 @@ public bool checkmultiformat() return true; } - public bool checkpagelist( int pagemax ) + public bool checkpagelist(int pagemax) { bool rc = true; if (PageList.Count != 0) @@ -397,20 +417,23 @@ public bool checkpagelist( int pagemax ) } } } - return(rc); + + return (rc); } public bool checkfontdirs() { bool rc = true; - for (int i = 0; i < fontdirs.Count; i++ ) + for (int i = 0; i < fontdirs.Count; i++) { - if (System.IO.Directory.Exists(fontdirs[i]) == false ) + if (System.IO.Directory.Exists(fontdirs[i]) == false) { - Console.WriteLine("The directory path " + fontdirs[i] + " listed in the fontlist options is not a valid directory."); + Console.WriteLine("The directory path " + fontdirs[i] + + " listed in the fontlist options is not a valid directory."); rc = false; } } + return (rc); } } @@ -425,7 +448,8 @@ static void Usage() Console.WriteLine("Options are one or more of:"); Console.WriteLine("-format=[tif, jpg, bmp, png, gif], No default"); Console.WriteLine("-color=[gray|cmyk|rgb], default=rgb"); - Console.WriteLine("-grayhalftone = [n|y] - is a grayscale image halftone? Only valid for format=tif and color=gray."); + Console.WriteLine( + "-grayhalftone = [n|y] - is a grayscale image halftone? Only valid for format=tif and color=gray."); Console.WriteLine("-first=[y|n] Only convert the first PDFL page, default=n"); Console.WriteLine("-quality=1-100. Only valid for an output type of jpg, default for jpg is 75"); Console.WriteLine("-resolution=[horiz x vert] ( target DPI, [12-1200], default=300"); @@ -444,7 +468,8 @@ static void Usage() Console.WriteLine("\tlzw is only valid for an output format of tif"); Console.WriteLine("-region=[crop|media|art|trim|bleed|bounding]"); Console.WriteLine("\t(region of PDF page to rasterize, default=crop"); - Console.WriteLine("-pages=[comma separated list or range, or even or odd], i.e., pages=2,4,7-9,14. Default is all."); + Console.WriteLine( + "-pages=[comma separated list or range, or even or odd], i.e., pages=2,4,7-9,14. Default is all."); Console.WriteLine("-output=[filename], (default=input filename)"); Console.WriteLine("-smoothing=[none|text|all], (default=none"); Console.WriteLine("-reverse=[y|n], Reverse black/white, for gray images only."); @@ -454,41 +479,42 @@ static void Usage() Console.WriteLine("-asprinted=[y|n], default=n, Renders only printable annotations."); } - static string CreateFileSuffix( string filename, ImageType imagetype) + static string CreateFileSuffix(string filename, ImageType imagetype) { - string outputfile= ""; - switch(imagetype) + string outputfile = ""; + switch (imagetype) { - case ImageType.BMP: + case ImageType.BMP: outputfile = filename + ".bmp"; break; - case ImageType.GIF: + case ImageType.GIF: outputfile = filename + ".gif"; break; - case ImageType.JPEG: + case ImageType.JPEG: outputfile = filename + ".jpg"; break; - case ImageType.PNG: + case ImageType.PNG: outputfile = filename + ".png"; break; - case ImageType.TIFF: + case ImageType.TIFF: outputfile = filename + ".tif"; break; } + return (outputfile); } - static string formatdigits( int numdigits, int counter) + static string formatdigits(int numdigits, int counter) { string counterstring = counter.ToString(); string ZeroSuffix = ""; - if ( counterstring.Length >= numdigits) + if (counterstring.Length >= numdigits) { - return( counterstring); + return (counterstring); } for (int x = 0; x < numdigits - counterstring.Length; x++) @@ -504,7 +530,8 @@ static void saveTheImage(Image saveimage, int imageIndex, DocToImagesOptions opt { string outputfilepath; if (options.getoutputdir() != "") - outputfilepath = options.getoutputdir() + "/" + options.getoutputfile() + formatdigits(options.getZeroSuffix(), imageIndex); + outputfilepath = options.getoutputdir() + "/" + options.getoutputfile() + + formatdigits(options.getZeroSuffix(), imageIndex); else outputfilepath = options.getoutputfile() + formatdigits(options.getZeroSuffix(), imageIndex); @@ -538,7 +565,7 @@ static void Main(string[] args) Environment.Exit(1); } - for (int i = 0; i < args.Length-1; i++) + for (int i = 0; i < args.Length - 1; i++) { String arg = args[i]; if (arg.StartsWith("-") && arg.Contains("=")) @@ -569,9 +596,11 @@ static void Main(string[] args) } else { - Console.WriteLine("Invalid value for the format option. Valid values are jpg, tif, bmp, png, gif"); + Console.WriteLine( + "Invalid value for the format option. Valid values are jpg, tif, bmp, png, gif"); Environment.Exit(1); } + continue; } @@ -595,6 +624,7 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the color option. Valid values are gray, rgb, cmyk"); Environment.Exit(1); } + continue; } @@ -603,13 +633,14 @@ static void Main(string[] args) // Process grayscale half tone if (opt.Equals("y")) options.setgrayhalftone(true); - else if ( opt.Equals("n")) + else if (opt.Equals("n")) options.setgrayhalftone(false); else { Console.WriteLine("Invalid value for the grayhalftone option. Valid values are n or y"); Environment.Exit(1); } + continue; } @@ -629,6 +660,7 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the first option. Valid values are 'y' and 'n'."); Environment.Exit(1); } + continue; } @@ -641,6 +673,7 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the quality option. Valid values are 1 through 100."); Environment.Exit(1); } + options.setquality(quality); continue; } @@ -661,6 +694,7 @@ static void Main(string[] args) options.sethres(res); options.setvres(res); } + continue; } @@ -687,6 +721,7 @@ static void Main(string[] args) options.sethpixels(pixels); options.setvpixels(pixels); } + continue; } @@ -727,9 +762,11 @@ static void Main(string[] args) } else { - Console.WriteLine("Invalid value for the compression option. Valid values are: no|lzw|g3|g4|jpg"); + Console.WriteLine( + "Invalid value for the compression option. Valid values are: no|lzw|g3|g4|jpg"); Environment.Exit(1); } + continue; } @@ -737,11 +774,13 @@ static void Main(string[] args) { // process page output region option if (!(opt.Equals("crop") || opt.Equals("media") || opt.Equals("art") || - opt.Equals("trim") || opt.Equals("bleed") || opt.Equals("bounding"))) + opt.Equals("trim") || opt.Equals("bleed") || opt.Equals("bounding"))) { - Console.WriteLine("Invalid value for the region option. Value values are: crop|media|art|trim|bleed|bounding"); + Console.WriteLine( + "Invalid value for the region option. Value values are: crop|media|art|trim|bleed|bounding"); Environment.Exit(1); } + options.setpageregion(opt); continue; } @@ -792,6 +831,7 @@ static void Main(string[] args) } } } + continue; } @@ -819,9 +859,11 @@ static void Main(string[] args) } else { - Console.WriteLine("Invalid value for the smoothing option. Valid values are none|text|all"); + Console.WriteLine( + "Invalid value for the smoothing option. Valid values are none|text|all"); Environment.Exit(1); } + continue; } @@ -841,6 +883,7 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the reverse option. Valid values are 'y' and 'n'."); Environment.Exit(1); } + continue; } @@ -857,9 +900,11 @@ static void Main(string[] args) } else { - Console.WriteLine("Invalid value for the blackisone option. Valid values are 'y' and 'n'."); + Console.WriteLine( + "Invalid value for the blackisone option. Valid values are 'y' and 'n'."); Environment.Exit(1); } + continue; } @@ -879,6 +924,7 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the multi option. Valid values are 'y' and 'n'."); Environment.Exit(1); } + continue; } @@ -890,6 +936,7 @@ static void Main(string[] args) { Console.WriteLine("Invalid value for the digits option. Valid values are 0-9."); } + options.setZeroSuffix(numdigits); continue; } @@ -910,8 +957,10 @@ static void Main(string[] args) Console.WriteLine("Invalid value for the asprinted option. Valid values are 'y' and 'n'."); Environment.Exit(1); } + continue; } + Console.WriteLine("Invalid option: " + arg); Usage(); Environment.Exit(1); @@ -978,7 +1027,8 @@ static void Main(string[] args) if (options.checktiffcompressgrayhalftone() == false) { - Console.WriteLine("compression can only be set to 'g3' or 'g4' if grayhalftone is set to 'y' and color is set to 'gray'"); + Console.WriteLine( + "compression can only be set to 'g3' or 'g4' if grayhalftone is set to 'y' and color is set to 'gray'"); errorcount++; } @@ -1027,7 +1077,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library(options.getfontdirs())) { - Document pdfdocument = null; int numpages = 0; try @@ -1050,18 +1099,23 @@ static void Main(string[] args) if (options.getoutputfile() == "") { outputfilename = docpath; - } else + } + else { - outputfilename =options.getoutputfile(); + outputfilename = options.getoutputfile(); } + options.setoutputdir(System.IO.Path.GetDirectoryName(outputfilename)); - string[] basefilename = System.IO.Path.GetFileName(outputfilename).Split('.'); // split off the .pdf suffix. + string[] basefilename = + System.IO.Path.GetFileName(outputfilename).Split('.'); // split off the .pdf suffix. options.setoutputfile(basefilename[0]); if (options.checkpagelist(numpages) == false) { - Console.WriteLine("The list of pages given in the 'pages' option is outside the number of pages in this PDF document: " + pdfdocument.NumPages); + Console.WriteLine( + "The list of pages given in the 'pages' option is outside the number of pages in this PDF document: " + + pdfdocument.NumPages); Environment.Exit(1); } @@ -1077,16 +1131,18 @@ static void Main(string[] args) { numpages = 1; // Will modify the operation of the loop below. } + for (int i = 0; i < numpages; i++) { // Remember in the Doc object page #'s start with 0, but physically they start with 1. - if ((options.onlyodd() == false && options.onlyeven() == false) || // all pages - (options.onlyodd() && (((i + 1) % 2) == 1)) || // this is an odd page - (options.onlyeven() && (((i + 1) % 2) == 0))) // this is an even page + if ((options.onlyodd() == false && options.onlyeven() == false) || // all pages + (options.onlyodd() && (((i + 1) % 2) == 1)) || // this is an odd page + (options.onlyeven() && (((i + 1) % 2) == 0))) // this is an even page { options.appendpagelist(i); } } + pagelist = options.getpagelist(); } @@ -1110,10 +1166,13 @@ static void Main(string[] args) { isp.JPEGQuality = options.getquality(); } + isp.ReverseGray = options.getreversegray(); isp.TIFFBlackIsOne = options.getblackisone(); - for (int i = 0; i < pagelist.Count; i++) // Get the images of the PDF pages to create an image collection. + for (int i = 0; + i < pagelist.Count; + i++) // Get the images of the PDF pages to create an image collection. { Page docpage = pdfdocument.GetPage(pagelist[i]); Rect PageRect = null; @@ -1146,9 +1205,9 @@ static void Main(string[] args) Console.WriteLine("Unknown page region option."); Environment.Exit(1); } + try { - Image pageimage = docpage.GetImage(PageRect, pip); if (options.getmultipage()) { @@ -1166,6 +1225,7 @@ static void Main(string[] args) Environment.Exit(1); } } + /* * Pageimagecollection now Contains, as the name states, * a collection of images created from the PDF pages according @@ -1176,7 +1236,7 @@ static void Main(string[] args) { string outputfilepath; if (options.getoutputdir() != "") - outputfilepath = options.getoutputdir()+"/"+options.getoutputfile(); + outputfilepath = options.getoutputdir() + "/" + options.getoutputfile(); else outputfilepath = options.getoutputfile(); @@ -1192,6 +1252,5 @@ static void Main(string[] args) } } } - } } diff --git a/DotNETCore/Sample_Source/Images/DrawSeparations/DrawSeparations.cs b/DotNETCore/Sample_Source/Images/DrawSeparations/DrawSeparations.cs index 876e310f..3b8111ec 100644 --- a/DotNETCore/Sample_Source/Images/DrawSeparations/DrawSeparations.cs +++ b/DotNETCore/Sample_Source/Images/DrawSeparations/DrawSeparations.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; - using Datalogics.PDFL; /* @@ -24,15 +23,17 @@ class DrawSeparations { static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -96,10 +97,10 @@ static void Main(string[] args) for (int i = 0; i < separatedColorChannels.Count; ++i) { - separatedColorChannels[i].Save(sOutput + i + "-" + colorants[i].SeparationName + ".png", ImageFormat.Png); + separatedColorChannels[i].Save(sOutput + i + "-" + colorants[i].SeparationName + ".png", + ImageFormat.Png); } } - } } } diff --git a/DotNETCore/Sample_Source/Images/DrawToBitmap/DrawToBitmap.cs b/DotNETCore/Sample_Source/Images/DrawToBitmap/DrawToBitmap.cs index 092d2b17..c997d69a 100644 --- a/DotNETCore/Sample_Source/Images/DrawToBitmap/DrawToBitmap.cs +++ b/DotNETCore/Sample_Source/Images/DrawToBitmap/DrawToBitmap.cs @@ -4,7 +4,6 @@ using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; - using Datalogics.PDFL; /* @@ -60,7 +59,8 @@ class SampleRenderProgressProc : RenderProgressProc public override void Call(float stagePercent, string info, RenderProgressStage stage) { mSomeBoolean = ((mSomeBoolean) ? false : true); - Console.WriteLine("SampleRenderProgressProc Call (stage/stagePercent/info): {0} {1} {2}", stage, stagePercent, info); + Console.WriteLine("SampleRenderProgressProc Call (stage/stagePercent/info): {0} {1} {2}", stage, + stagePercent, info); } static private bool mSomeBoolean; @@ -116,8 +116,8 @@ private static void SaveBitmap(Bitmap bitmap, string nameSuffix) /// the layer name. It uses for saving process. private static void DrawLayerToBitmap(Page pg, DrawParams parms, string layerName) { - int width = (int)Math.Ceiling(parms.DestRect.Width); - int height = (int)Math.Ceiling(parms.DestRect.Height); + int width = (int) Math.Ceiling(parms.DestRect.Width); + int height = (int) Math.Ceiling(parms.DestRect.Height); using (Bitmap bitmap = new Bitmap(width, height)) { @@ -133,9 +133,10 @@ private static void DrawLayerToBitmap(Page pg, DrawParams parms, string layerNam /// the DrawParams object /// the layer name. It uses for saving process. private static void DrawLayerToGraphics(Page pg, DrawParams parms, string layerName) - { // Draw as if to a DeviceContext (DC) - int width = (int)Math.Ceiling(parms.DestRect.Width); - int height = (int)Math.Ceiling(parms.DestRect.Height); + { + // Draw as if to a DeviceContext (DC) + int width = (int) Math.Ceiling(parms.DestRect.Width); + int height = (int) Math.Ceiling(parms.DestRect.Height); using (Bitmap bitmap = new Bitmap(width, height)) { @@ -162,7 +163,8 @@ static void DrawLayersToBitmap(Document doc, Page pg, DrawParams parms) states[i] = true; using (OptionalContentContext occ = new OptionalContentContext(doc)) - { // Render and save current layer + { + // Render and save current layer occ.SetOCGStates(ocgs, states); parms.OptionalContentContext = occ; @@ -194,7 +196,8 @@ static void DrawLayersToGraphics(Document doc, Page pg, DrawParams parms) states[i] = true; using (OptionalContentContext occ = new OptionalContentContext(doc)) - { // Render and save current layer + { + // Render and save current layer occ.SetOCGStates(ocgs, states); parms.OptionalContentContext = occ; @@ -218,8 +221,8 @@ static void DrawToBitmapWithDrawParams(Page pg, DrawParams parms) { Rect boundBox = parms.DestRect; - int width = (int)Math.Ceiling(boundBox.Width); - int height = (int)Math.Ceiling(boundBox.Height); + int width = (int) Math.Ceiling(boundBox.Width); + int height = (int) Math.Ceiling(boundBox.Height); using (Bitmap bitmap = new Bitmap(width, height)) { @@ -237,8 +240,8 @@ static void DrawToBitmapWithDrawParams(Page pg, DrawParams parms) /// height of the destination Bitmap static void DrawToBitmapWithMatrix(Page pg, Matrix matrix, double width, double height) { - int w = (int)Math.Ceiling(width); - int h = (int)Math.Ceiling(height); + int w = (int) Math.Ceiling(width); + int h = (int) Math.Ceiling(height); using (Bitmap bitmap = new Bitmap(w, h)) { @@ -257,8 +260,8 @@ static void DrawToGraphicsWithDrawParams(Page pg, DrawParams parms) { Rect boundBox = parms.DestRect; - int width = (int)Math.Ceiling(boundBox.Width); - int height = (int)Math.Ceiling(boundBox.Height); + int width = (int) Math.Ceiling(boundBox.Width); + int height = (int) Math.Ceiling(boundBox.Height); // // Draw as if to a DeviceContext (DC)... @@ -280,8 +283,8 @@ static void DrawToGraphicsWithDrawParams(Page pg, DrawParams parms) /// height of the destination Bitmap static void DrawToGraphicsWithMatrix(Page pg, Matrix matrix, double width, double height) { - int w = (int)Math.Ceiling(width); - int h = (int)Math.Ceiling(height); + int w = (int) Math.Ceiling(width); + int h = (int) Math.Ceiling(height); // // Draw as if to a DeviceContext (DC)... @@ -333,7 +336,8 @@ static void DrawToByteArray(Page pg, Matrix matrix) } if (rawBytes == null) - { // didn't draw + { + // didn't draw return; } @@ -348,7 +352,7 @@ static void DrawToByteArray(Page pg, Matrix matrix) Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, - bitmap.PixelFormat); + bitmap.PixelFormat); Debug.Assert(stride == bitmapData.Stride); Marshal.Copy(rawBytes, 0, bitmapData.Scan0, rawBytes.Length); bitmap.UnlockBits(bitmapData); @@ -359,14 +363,14 @@ static void DrawToByteArray(Page pg, Matrix matrix) static void Main(string[] args) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -414,33 +418,40 @@ static void Main(string[] args) bool enableBlackPointCompensation = true; // ReSharper disable once ConditionIsAlwaysTrueOrFalse - using (DrawParams parms = ConstructDrawParams(matrix, pg.MediaBox, enableBlackPointCompensation)) + using (DrawParams parms = + ConstructDrawParams(matrix, pg.MediaBox, enableBlackPointCompensation)) { // Draw to Graphics Console.WriteLine("DrawToGraphicsWithMatrix: {0} {1} {2}", matrix, width, height); - DrawToGraphicsWithMatrix(pg, matrix, width, height); // Will NOT drive SampleRenderProgress(Cancel)Proc + DrawToGraphicsWithMatrix(pg, matrix, width, + height); // Will NOT drive SampleRenderProgress(Cancel)Proc // Draw to Graphics using DrawParams with turned on black point compensation - Console.WriteLine("DrawToGraphicsWithDrawParams: {0} {1} {2}", parms.Matrix, parms.UpdateRect.Width, parms.UpdateRect.Height); - DrawToGraphicsWithDrawParams(pg, parms); // Will drive SampleRenderProgress(Cancel)Proc + Console.WriteLine("DrawToGraphicsWithDrawParams: {0} {1} {2}", parms.Matrix, + parms.UpdateRect.Width, parms.UpdateRect.Height); + DrawToGraphicsWithDrawParams(pg, parms); // Will drive SampleRenderProgress(Cancel)Proc // Demonstrate drawing to Graphics with params and OCGs // Demonstrate drawing layers - Console.WriteLine("DrawLayersToGraphics: {0} {1} {2}", parms.Matrix, parms.UpdateRect.Width, parms.UpdateRect.Height); - DrawLayersToGraphics(doc, pg, parms); // Will NOT drive SampleRenderProgress(Cancel)Proc + Console.WriteLine("DrawLayersToGraphics: {0} {1} {2}", parms.Matrix, + parms.UpdateRect.Width, parms.UpdateRect.Height); + DrawLayersToGraphics(doc, pg, parms); // Will NOT drive SampleRenderProgress(Cancel)Proc // Demonstrate drawing to Bitmaps with params and OCGs // Demonstrate drawing layers - Console.WriteLine("DrawLayersToBitmap: {0} {1} {2}", parms.Matrix, parms.UpdateRect.Width, parms.UpdateRect.Height); + Console.WriteLine("DrawLayersToBitmap: {0} {1} {2}", parms.Matrix, + parms.UpdateRect.Width, parms.UpdateRect.Height); DrawLayersToBitmap(doc, pg, parms); // Will NOT drive SampleRenderProgressProc // Make a Bitmap Console.WriteLine("DrawToBitmapWithMatrix: {0} {1} {2}", matrix, width, height); - DrawToBitmapWithMatrix(pg, matrix, width, height); // Will NOT drive SampleRenderProgress(Cancel)Proc + DrawToBitmapWithMatrix(pg, matrix, width, + height); // Will NOT drive SampleRenderProgress(Cancel)Proc // Make a Bitmap using DrawParams with black point compensation turned on - Console.WriteLine("DrawToBitmapWithDrawParams: {0} {1} {2}", parms.Matrix, parms.UpdateRect.Width, parms.UpdateRect.Height); - DrawToBitmapWithDrawParams(pg, parms); // Will drive SampleRenderProgress(Cancel)Proc + Console.WriteLine("DrawToBitmapWithDrawParams: {0} {1} {2}", parms.Matrix, + parms.UpdateRect.Width, parms.UpdateRect.Height); + DrawToBitmapWithDrawParams(pg, parms); // Will drive SampleRenderProgress(Cancel)Proc // Demonstrate drawing to a byte array Console.WriteLine("DrawToByteArray: {0} {1} {2}", matrix, width, height); diff --git a/DotNETCore/Sample_Source/Images/EPSSeparations/EPSSeparations.cs b/DotNETCore/Sample_Source/Images/EPSSeparations/EPSSeparations.cs index e6f92c0e..42eaaf89 100644 --- a/DotNETCore/Sample_Source/Images/EPSSeparations/EPSSeparations.cs +++ b/DotNETCore/Sample_Source/Images/EPSSeparations/EPSSeparations.cs @@ -36,10 +36,11 @@ static void Main(string[] args) if (args.Length > 0) sInput1 = args[0]; - if(args.Length > 1) + if (args.Length > 1) sInput2 = args[1]; - Console.WriteLine("Will perform simple separation on " + sInput1 + " and complex separation on " + sInput2); + Console.WriteLine("Will perform simple separation on " + sInput1 + " and complex separation on " + + sInput2); SimpleSeparationsExample(sInput1); ComplexSeparationsExample(sInput2); @@ -48,42 +49,43 @@ static void Main(string[] args) static void SimpleSeparationsExample(String input) { - Document doc = new Document(input); Console.WriteLine("Opened " + input); // Loop through all pages in the document and make a set of EPS separations // for each page, using the default parameters. - for(int pgNum=0; pgNum < doc.NumPages; pgNum++) + for (int pgNum = 0; pgNum < doc.NumPages; pgNum++) { Page pg = doc.GetPage(pgNum); - + // First, list the inks on the page and create a SeparationPlate for each ink. IList pageinks = pg.ListInks(); List plates = new List(); - - foreach(Ink i in pageinks) + + foreach (Ink i in pageinks) { - Console.WriteLine("Found color " + i.ColorantName + " on page " + (pgNum+1) + "."); - SeparationPlate newplate = new SeparationPlate(i, new System.IO.FileStream("Simple-Pg" + (pgNum+1) + "-" + i.ColorantName + ".eps", System.IO.FileMode.Create)); + Console.WriteLine("Found color " + i.ColorantName + " on page " + (pgNum + 1) + "."); + SeparationPlate newplate = new SeparationPlate(i, + new System.IO.FileStream("Simple-Pg" + (pgNum + 1) + "-" + i.ColorantName + ".eps", + System.IO.FileMode.Create)); plates.Add(newplate); } // Set up the parameters for making separations using the plates that were just created. SeparationParams parms = new SeparationParams(plates); - - Console.WriteLine("Making separations for page " + (pgNum+1) + "..."); + + Console.WriteLine("Making separations for page " + (pgNum + 1) + "..."); pg.MakeSeparations(parms); // Close the output stream for each EPS file. - foreach(SeparationPlate p in plates) + foreach (SeparationPlate p in plates) { p.EPSOutput.Close(); } } } - + static void ComplexSeparationsExample(String input) { // This document has 4 pages, each with a combination of CMYK and spot colors. @@ -113,15 +115,17 @@ static void ComplexSeparationsExample(String input) // the new density values will be preserved. When lookups for these inks // are performed on the Dictionary for subsequent pages, these plates with // the new density values will be used. - if(i.ColorantName == "PANTONE 7442 C") + if (i.ColorantName == "PANTONE 7442 C") { i.Density = 0.75; } - else if(i.ColorantName == "PANTONE 7467 C") + else if (i.ColorantName == "PANTONE 7467 C") { i.Density = 0.50; } - SeparationPlate newplate = new SeparationPlate(i, new System.IO.FileStream("Complex-Pg1-" + i.ColorantName + ".eps", System.IO.FileMode.Create)); + + SeparationPlate newplate = new SeparationPlate(i, + new System.IO.FileStream("Complex-Pg1-" + i.ColorantName + ".eps", System.IO.FileMode.Create)); plates.Add(newplate); colors.Add(i.ColorantName, newplate); } @@ -151,24 +155,28 @@ static void ComplexSeparationsExample(String input) if (colors.ContainsKey(i.ColorantName)) { newplate = colors[i.ColorantName]; - newplate.EPSOutput = new System.IO.FileStream("Complex-Pg" + (pgNum+1) + "-" + i.ColorantName + ".eps", System.IO.FileMode.Create); + newplate.EPSOutput = new System.IO.FileStream( + "Complex-Pg" + (pgNum + 1) + "-" + i.ColorantName + ".eps", System.IO.FileMode.Create); } else { - newplate = new SeparationPlate(i, new System.IO.FileStream("Complex-Pg" + (pgNum+1) + "-" + i.ColorantName + ".eps", System.IO.FileMode.Create)); + newplate = new SeparationPlate(i, + new System.IO.FileStream("Complex-Pg" + (pgNum + 1) + "-" + i.ColorantName + ".eps", + System.IO.FileMode.Create)); colors.Add(i.ColorantName, newplate); } + plates.Add(newplate); } parms.Plates = plates; - - Console.WriteLine("Making separations for page " + (pgNum+1) + "..."); + + Console.WriteLine("Making separations for page " + (pgNum + 1) + "..."); pg.MakeSeparations(parms); foreach (SeparationPlate p in plates) { - p.EPSOutput.Close(); + p.EPSOutput.Close(); } } } diff --git a/DotNETCore/Sample_Source/Images/GetSeparatedImages/GetSeparatedImages.cs b/DotNETCore/Sample_Source/Images/GetSeparatedImages/GetSeparatedImages.cs index b1d65c9f..c1fac9d5 100644 --- a/DotNETCore/Sample_Source/Images/GetSeparatedImages/GetSeparatedImages.cs +++ b/DotNETCore/Sample_Source/Images/GetSeparatedImages/GetSeparatedImages.cs @@ -22,15 +22,17 @@ class GetSeparatedImages { static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -51,7 +53,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - Document doc = new Document(sInput); Page pg = doc.GetPage(0); @@ -75,7 +76,6 @@ static void Main(string[] args) // Save images as multi-paged tiff - each page is a separated color from the page bitmap. images.Save(sOutput, ImageType.TIFF); } - } } } diff --git a/DotNETCore/Sample_Source/Images/ImageEmbedICCProfile/ImageEmbedICCProfile.cs b/DotNETCore/Sample_Source/Images/ImageEmbedICCProfile/ImageEmbedICCProfile.cs index 2c733e06..e548994e 100644 --- a/DotNETCore/Sample_Source/Images/ImageEmbedICCProfile/ImageEmbedICCProfile.cs +++ b/DotNETCore/Sample_Source/Images/ImageEmbedICCProfile/ImageEmbedICCProfile.cs @@ -32,14 +32,12 @@ public void export_doc_images_type(Document doc, PDFStream profileStream, ImageT Page pg = doc.GetPage(pgno); Export_Image(pg.Content, cs, pg, pgno); - } } public void export_doc_images(Document doc, PDFStream profileStream) { export_doc_images_type(doc, profileStream, ImageType.TIFF); - } public void Export_Image(Content content, ColorSpace csp, Page pg, int pNum) @@ -48,7 +46,6 @@ public void Export_Image(Content content, ColorSpace csp, Page pg, int pNum) try { - isp = new ImageSaveParams(); isp.Compression = CompressionCode.LZW; @@ -78,15 +75,11 @@ public void Export_Image(Content content, ColorSpace csp, Page pg, int pNum) outImage = pg.GetImage(pg.CropBox, pip); filenamevar = "ImageEmbedICCProfile-out_rel" + pNum + ".tif"; outImage.Save(filenamevar, exporttype, isp); - - } catch (Exception ex) { Console.WriteLine("Cannot write file: " + ex.Message); } - - } } @@ -94,15 +87,17 @@ public class ImageEmbedICCProfile { static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; diff --git a/DotNETCore/Sample_Source/Images/ImageExport/ImageExport.cs b/DotNETCore/Sample_Source/Images/ImageExport/ImageExport.cs index 21050ae3..adf5adc7 100644 --- a/DotNETCore/Sample_Source/Images/ImageExport/ImageExport.cs +++ b/DotNETCore/Sample_Source/Images/ImageExport/ImageExport.cs @@ -24,13 +24,13 @@ namespace ImageExport { - public class ExportDocumentImages + public class ExportDocumentImages { - ImageType exporttype; + ImageType exporttype; int next; ImageCollection ic = new ImageCollection(); - - public void export_doc_images_type( Document doc, ImageType imtype) + + public void export_doc_images_type(Document doc, ImageType imtype) { exporttype = imtype; int pgno; @@ -40,21 +40,21 @@ public void export_doc_images_type( Document doc, ImageType imtype) Content content = pg.Content; Export_Element_Images(content); } - - if ( ic.Count != 0 ) + + if (ic.Count != 0) { try { ic.Save("ImageExport-page" + pgno + "-out.tif", ImageType.TIFF); } - catch( Exception ex) + catch (Exception ex) { Console.WriteLine("Cannot write file: " + ex.Message); } } } - public void export_doc_images( Document doc) + public void export_doc_images(Document doc) { export_doc_images_type(doc, ImageType.TIFF); export_doc_images_type(doc, ImageType.JPEG); @@ -63,17 +63,17 @@ public void export_doc_images( Document doc) export_doc_images_type(doc, ImageType.BMP); } - public void Export_Element_Images(Content content ) - { + public void Export_Element_Images(Content content) + { int i = 0; ImageSaveParams isp; - while (i < content.NumElements ) + while (i < content.NumElements) { Element e = content.GetElement(i); if (e is Image) { - Image img = (Image)e; + Image img = (Image) e; // Weed out impossible on nonsensical combinations. if (img.ColorSpace == ColorSpace.DeviceCMYK && exporttype != ImageType.JPEG) { @@ -81,7 +81,7 @@ public void Export_Element_Images(Content content ) continue; } - if ( exporttype == ImageType.TIFF) + if (exporttype == ImageType.TIFF) { ic.Append(img); isp = new ImageSaveParams(); @@ -91,7 +91,6 @@ public void Export_Element_Images(Content content ) try { - if (exporttype == ImageType.JPEG) { isp = new ImageSaveParams(); @@ -118,8 +117,8 @@ public void Export_Element_Images(Content content ) { Console.WriteLine("Cannot write file: " + ex.Message); } - next++; + next++; } else if (e is Container) { @@ -136,6 +135,7 @@ public void Export_Element_Images(Content content ) Console.WriteLine("Recursing through a Form"); Export_Element_Images((e as Form).Content); } + i++; } } @@ -145,15 +145,17 @@ class ImageExport { static void Main(String[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -174,7 +176,7 @@ static void Main(String[] args) Console.WriteLine("Input file: " + sInput); Document doc = new Document(sInput); - ExportDocumentImages expdoc= new ExportDocumentImages(); + ExportDocumentImages expdoc = new ExportDocumentImages(); expdoc.export_doc_images(doc); } } diff --git a/DotNETCore/Sample_Source/Images/ImageExtraction/ImageExtraction.cs b/DotNETCore/Sample_Source/Images/ImageExtraction/ImageExtraction.cs index 4393ce7b..bd84a3d5 100644 --- a/DotNETCore/Sample_Source/Images/ImageExtraction/ImageExtraction.cs +++ b/DotNETCore/Sample_Source/Images/ImageExtraction/ImageExtraction.cs @@ -35,7 +35,7 @@ static void ExtractImages(Content content) if (e is Datalogics.PDFL.Image) { Console.WriteLine("Saving an image"); - Datalogics.PDFL.Image img = (Datalogics.PDFL.Image)e; + Datalogics.PDFL.Image img = (Datalogics.PDFL.Image) e; Bitmap bitmap = img.Bitmap; bitmap.Save("ImageExtraction-extract-out" + (next) + ".bmp", ImageFormat.Bmp); @@ -65,15 +65,17 @@ static void ExtractImages(Content content) static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -102,4 +104,3 @@ static void Main(string[] args) } } } - diff --git a/DotNETCore/Sample_Source/Images/ImageFromStream/ImageFromStream.cs b/DotNETCore/Sample_Source/Images/ImageFromStream/ImageFromStream.cs index baef5938..2a26c166 100644 --- a/DotNETCore/Sample_Source/Images/ImageFromStream/ImageFromStream.cs +++ b/DotNETCore/Sample_Source/Images/ImageFromStream/ImageFromStream.cs @@ -27,15 +27,17 @@ class ImageFromStream { static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -61,14 +63,14 @@ static void Main(string[] args) if (args.Length > 2) docOutput = args[2]; - Console.WriteLine("using bitmap input " + bitmapInput + " and jpeg input " + jpegInput + ". Writing to output " + docOutput); + Console.WriteLine("using bitmap input " + bitmapInput + " and jpeg input " + jpegInput + + ". Writing to output " + docOutput); // Create a .NET MemoryStream object. // A MemoryStream is used here for demonstration only, but the technique // works just as well for other streams which support seeking. using (System.IO.MemoryStream BitmapStream = new System.IO.MemoryStream()) { - // Load a bitmap image into the MemoryStream. using (System.Drawing.Bitmap BitmapImage = new System.Drawing.Bitmap(bitmapInput)) { @@ -92,7 +94,6 @@ static void Main(string[] args) // Create a new MemoryStream for a new image file. using (System.IO.MemoryStream JpegStream = new System.IO.MemoryStream()) { - // Load a JPEG image into the MemoryStream. using (System.Drawing.Image JpegImage = System.Drawing.Image.FromFile(jpegInput)) { diff --git a/DotNETCore/Sample_Source/Images/ImageImport/ImageImport.cs b/DotNETCore/Sample_Source/Images/ImageImport/ImageImport.cs index 7586c741..cd3014f4 100644 --- a/DotNETCore/Sample_Source/Images/ImageImport/ImageImport.cs +++ b/DotNETCore/Sample_Source/Images/ImageImport/ImageImport.cs @@ -55,7 +55,6 @@ static void Main(string[] args) } doc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/Images/ImageResampling/ImageResampling.cs b/DotNETCore/Sample_Source/Images/ImageResampling/ImageResampling.cs index b9d939b8..bdee02e2 100644 --- a/DotNETCore/Sample_Source/Images/ImageResampling/ImageResampling.cs +++ b/DotNETCore/Sample_Source/Images/ImageResampling/ImageResampling.cs @@ -25,16 +25,17 @@ namespace ImageResampling class ImageResampling { static int numreplaced; - static void ResampleImages(Content content ) + + static void ResampleImages(Content content) { int i = 0; while (i < content.NumElements) { Element e = content.GetElement(i); - Console.WriteLine(i + " / "+content.NumElements+" = " + e.GetType()); + Console.WriteLine(i + " / " + content.NumElements + " = " + e.GetType()); if (e is Image) { - Image img = (Image)e; + Image img = (Image) e; try { Image newimg = img.ChangeResolution(400); @@ -66,6 +67,7 @@ static void ResampleImages(Content content ) ResampleImages(formcontent); (e as Form).Content = formcontent; } + i++; } } @@ -106,6 +108,7 @@ static void Main(string[] args) pg.UpdateContent(); } } + doc.Save(SaveFlags.Full | SaveFlags.CollectGarbage, sOutput); } catch (Exception ex) @@ -116,4 +119,3 @@ static void Main(string[] args) } } } - diff --git a/DotNETCore/Sample_Source/Images/ImageSoftMask/ImageSoftMask.cs b/DotNETCore/Sample_Source/Images/ImageSoftMask/ImageSoftMask.cs index 070ab9a3..d2636b29 100644 --- a/DotNETCore/Sample_Source/Images/ImageSoftMask/ImageSoftMask.cs +++ b/DotNETCore/Sample_Source/Images/ImageSoftMask/ImageSoftMask.cs @@ -73,5 +73,3 @@ static void Main(string[] args) } } } - - diff --git a/DotNETCore/Sample_Source/Images/RasterizePage/RasterizePage.cs b/DotNETCore/Sample_Source/Images/RasterizePage/RasterizePage.cs index d7dd692c..15e1182c 100644 --- a/DotNETCore/Sample_Source/Images/RasterizePage/RasterizePage.cs +++ b/DotNETCore/Sample_Source/Images/RasterizePage/RasterizePage.cs @@ -34,15 +34,17 @@ class RasterizePage { static void Main(string[] args) { - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && - !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .OSX) && + !System.IO.File.Exists("/usr/local/lib/libgdiplus.dylib")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on macOS."); return; } - if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) && - !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform + .Linux) && + !System.IO.File.Exists("/usr/lib64/libgdiplus.so")) { Console.WriteLine("Please install libgdiplus first to access the System.Drawing namespace on Linux."); return; @@ -98,7 +100,7 @@ static void Main(string[] args) // so the image will be DeviceRGB. Image inputImage = pg.GetImage(pg.CropBox, pip); inputImage.Save(sOutput + "-400pixel-width.jpg", ImageType.JPEG); - Console.WriteLine("Created " + sOutput + "-400pixel-width.jpg..."); + Console.WriteLine("Created " + sOutput + "-400pixel-width.jpg..."); ///////////////////////////////////////////////////////// // @@ -107,7 +109,8 @@ static void Main(string[] args) // //////////////////////////////////////////////////////// - CreatePageImageBasedOnPhysicalSize(pg, sOutput + "-grayscale-halfsize.jpg", ImageType.JPEG, ColorSpace.DeviceGray); + CreatePageImageBasedOnPhysicalSize(pg, sOutput + "-grayscale-halfsize.jpg", ImageType.JPEG, + ColorSpace.DeviceGray); ///////////////////////////////////////////////////////// @@ -126,11 +129,12 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable System.Drawing.Bitmap halfImage = CreateBitmapWithTopHalfOfPage(pg, sOutput + "-tophalf.jpg", - System.Drawing.Imaging.ImageFormat.Jpeg, ColorSpace.DeviceRGB); + System.Drawing.Imaging.ImageFormat.Jpeg, ColorSpace.DeviceRGB); } } - public static void CreatePageImageBasedOnPhysicalSize(Page pg, string filename, ImageType imgtype, ColorSpace cspace) + public static void CreatePageImageBasedOnPhysicalSize(Page pg, string filename, ImageType imgtype, + ColorSpace cspace) { // Get the dimensions, in pixels, of an image that is // half the physical size of the page at a resolution of 96 DPI. @@ -166,7 +170,7 @@ public static PageImageParams ScalePage(Page pg, double scalefactor, double reso // has a Rotate value of 90 or 270, the userWidth should be // calculated from the y-values and the userHeight should be // calculated from the x-values. - double userWidth; + double userWidth; double userHeight; if ((pg.Rotation == PageRotation.Rotate90) || (pg.Rotation == PageRotation.Rotate270)) @@ -194,17 +198,16 @@ public static PageImageParams ScalePage(Page pg, double scalefactor, double reso // to store this information. PageImageParams pip = new PageImageParams(); pip.PageDrawFlags = DrawFlags.UseAnnotFaces; - pip.PixelWidth = (int)(physWidth * resolution); - pip.PixelHeight = (int)(physHeight * resolution); + pip.PixelWidth = (int) (physWidth * resolution); + pip.PixelHeight = (int) (physHeight * resolution); pip.HorizontalResolution = resolution; pip.VerticalResolution = resolution; return pip; - } - public static System.Drawing.Bitmap CreateBitmapWithTopHalfOfPage(Page pg, string filename, - System.Drawing.Imaging.ImageFormat imgtype, ColorSpace cspace) + public static System.Drawing.Bitmap CreateBitmapWithTopHalfOfPage(Page pg, string filename, + System.Drawing.Imaging.ImageFormat imgtype, ColorSpace cspace) { // Create a PageImageParams with the default settings and set // the color space as appropriate. diff --git a/DotNETCore/Sample_Source/InformationExtraction/ListBookmarks/ListBookmarks.cs b/DotNETCore/Sample_Source/InformationExtraction/ListBookmarks/ListBookmarks.cs index c9ce64dc..62f9dc86 100644 --- a/DotNETCore/Sample_Source/InformationExtraction/ListBookmarks/ListBookmarks.cs +++ b/DotNETCore/Sample_Source/InformationExtraction/ListBookmarks/ListBookmarks.cs @@ -39,6 +39,7 @@ static void EnumerateBookmarks(Bookmark b) Console.Write(", zoom "); Console.Write(v.Zoom); } + Console.WriteLine(); EnumerateBookmarks(b.FirstChild); EnumerateBookmarks(b.Next); @@ -69,5 +70,3 @@ static void Main(string[] args) } } } - - diff --git a/DotNETCore/Sample_Source/InformationExtraction/ListLayers/ListLayers.cs b/DotNETCore/Sample_Source/InformationExtraction/ListLayers/ListLayers.cs index 03e53c51..e4f8311d 100644 --- a/DotNETCore/Sample_Source/InformationExtraction/ListLayers/ListLayers.cs +++ b/DotNETCore/Sample_Source/InformationExtraction/ListLayers/ListLayers.cs @@ -37,8 +37,8 @@ static void Main(string[] args) Document doc = new Document(sInput); - IList ocgs = doc.OptionalContentGroups; - foreach(OptionalContentGroup ocg in ocgs) + IList ocgs = doc.OptionalContentGroups; + foreach (OptionalContentGroup ocg in ocgs) { Console.WriteLine(ocg.Name); Console.Write(" Intent: ["); @@ -53,6 +53,7 @@ static void Main(string[] args) Console.Write(i.Current); } } + Console.WriteLine("]"); } @@ -70,6 +71,7 @@ static void Main(string[] args) Console.Write(i.Current); } } + Console.WriteLine("]"); } } diff --git a/DotNETCore/Sample_Source/InformationExtraction/Metadata/Metadata.cs b/DotNETCore/Sample_Source/InformationExtraction/Metadata/Metadata.cs index bd7937dc..52a965f1 100644 --- a/DotNETCore/Sample_Source/InformationExtraction/Metadata/Metadata.cs +++ b/DotNETCore/Sample_Source/InformationExtraction/Metadata/Metadata.cs @@ -27,7 +27,6 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput1 = Library.ResourceDirectory + "Sample_Input/sample.pdf"; String sInput2 = Library.ResourceDirectory + "Sample_Input/Ducky_with_metadata.pdf"; String sOutput = "sample-metadata-out.pdf"; @@ -41,7 +40,8 @@ static void Main(string[] args) if (args.Length > 2) sOutput = args[2]; - Console.WriteLine("Input files " + sInput1 + " and " + sInput2 + ". Writing to output file " + sOutput); + Console.WriteLine("Input files " + sInput1 + " and " + sInput2 + ". Writing to output file " + + sOutput); DisplayDocumentMetadata(sInput1, sOutput); DisplayImageMetadata(sInput2); @@ -50,24 +50,27 @@ static void Main(string[] args) private static void DisplayDocumentMetadata(String input, String output) { - - using (Document doc = new Document(input)) { // Parse some data out of the document metadata string string metadata = doc.XMPMetadata; Console.WriteLine("Title: {0}", GetTitle(metadata)); - Console.WriteLine("CreatorTool: {0}", doc.GetXMPMetadataProperty("http://ns.adobe.com/xap/1.0/", "CreatorTool")); - Console.WriteLine("format: {0}", doc.GetXMPMetadataProperty("http://purl.org/dc/elements/1.1/", "format")); + Console.WriteLine("CreatorTool: {0}", + doc.GetXMPMetadataProperty("http://ns.adobe.com/xap/1.0/", "CreatorTool")); + Console.WriteLine("format: {0}", + doc.GetXMPMetadataProperty("http://purl.org/dc/elements/1.1/", "format")); int numAuthors = doc.CountXMPMetadataArrayItems("http://ns.adobe.com/xap/1.0/", "Authors"); Console.WriteLine("Number of authors: {0}", numAuthors); for (int i = 1; i <= numAuthors; i++) { - Console.WriteLine("Author: {0}", doc.GetXMPMetadataArrayItem("http://ns.adobe.com/xap/1.0/", "Authors", i)); + Console.WriteLine("Author: {0}", + doc.GetXMPMetadataArrayItem("http://ns.adobe.com/xap/1.0/", "Authors", i)); } + // Demonstrate setting a property - doc.SetXMPMetadataArrayItem("http://ns.adobe.com/xap/1.0/", "tetractys", "Authors", 2, "Metadata Tester"); - doc.Save(SaveFlags.Full, output); + doc.SetXMPMetadataArrayItem("http://ns.adobe.com/xap/1.0/", "tetractys", "Authors", 2, + "Metadata Tester"); + doc.Save(SaveFlags.Full, output); } } @@ -77,8 +80,8 @@ private static void DisplayImageMetadata(String input) { // Demonstrate getting data from an image Content content = doc.GetPage(0).Content; - Container container = (Container)content.GetElement(0); - Image image = (Image)container.Content.GetElement(0); + Container container = (Container) content.GetElement(0); + Image image = (Image) container.Content.GetElement(0); String metadata = image.Stream.Dict.XMPMetadata; Console.WriteLine("Ducky CreatorTool: {0}\n", GetCreatorToolAttribute(metadata)); } @@ -88,7 +91,7 @@ static string GetTitle(string xmlstring) { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xmlstring); - XmlElement element = (XmlElement)xmldoc.GetElementsByTagName("dc:title")[0]; + XmlElement element = (XmlElement) xmldoc.GetElementsByTagName("dc:title")[0]; XmlNode titleNode = element.GetElementsByTagName("rdf:li")[0]; return GetText(titleNode.ChildNodes); } @@ -98,7 +101,7 @@ static string GetCreatorTool(string xmlstring) { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xmlstring); - XmlElement element = (XmlElement)xmldoc.GetElementsByTagName("xap:CreatorTool")[0]; + XmlElement element = (XmlElement) xmldoc.GetElementsByTagName("xap:CreatorTool")[0]; return GetText(element.ChildNodes); } @@ -108,10 +111,11 @@ static string GetCreatorToolAttribute(string xmlstring) xmldoc.LoadXml(xmlstring); foreach (XmlNode node in xmldoc.GetElementsByTagName("rdf:Description")) { - XmlElement e = (XmlElement)node; + XmlElement e = (XmlElement) node; if (e.HasAttribute("xap:CreatorTool")) return e.GetAttribute("xap:CreatorTool"); } + return null; } diff --git a/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToDocument/AddTextToDocument.cs b/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToDocument/AddTextToDocument.cs index cde172a5..02a16546 100644 --- a/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToDocument/AddTextToDocument.cs +++ b/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToDocument/AddTextToDocument.cs @@ -32,9 +32,9 @@ static void AddTextToImages(Document doc, Content content, OCREngine engine) //PlaceTextUnder creates a form with the image and the generated text //under the image. The original image in the page is then replaced by //by the form. - Form form = engine.PlaceTextUnder((Image)e, doc); + Form form = engine.PlaceTextUnder((Image) e, doc); content.RemoveElement(index); - content.AddElement(form, index -1); + content.AddElement(form, index - 1); } else if (e is Container) { @@ -81,9 +81,9 @@ static void Main(string[] args) //You could add additional languages for the OCR engine to detect by adding //more entries to the LanguageSetting list. - //LanguageSetting languageTwo = new LanguageSetting(Language.Japanese, false); - //langList.Add(languageTwo); - ocrParams.Languages = langList; + //LanguageSetting languageTwo = new LanguageSetting(Language.Japanese, false); + //langList.Add(languageTwo); + ocrParams.Languages = langList; using (OCREngine ocrEngine = new OCREngine(ocrParams)) { @@ -100,11 +100,11 @@ static void Main(string[] args) page.UpdateContent(); } } + doc.Save(SaveFlags.Full, sOutput); } } } } - } } diff --git a/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToImage/AddTextToImage.cs b/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToImage/AddTextToImage.cs index 6197d9a3..b6b6075e 100644 --- a/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToImage/AddTextToImage.cs +++ b/DotNETCore/Sample_Source/OpticalCharacterRecognition/AddTextToImage/AddTextToImage.cs @@ -72,24 +72,25 @@ static void Main(string[] args) docpage.UpdateContent(); } } + using (Page page = doc.GetPage(0)) { - Content content = page.Content; - Element elem = content.GetElement(0); - Image image = (Image)elem; - //PlaceTextUnder creates a form with the image and the generated text - //under the image. The original image in the page is then replaced by - //by the form. - Form form = ocrEngine.PlaceTextUnder(image, doc); - content.RemoveElement(0); - content.AddElement(form, -1); - page.UpdateContent(); + Content content = page.Content; + Element elem = content.GetElement(0); + Image image = (Image) elem; + //PlaceTextUnder creates a form with the image and the generated text + //under the image. The original image in the page is then replaced by + //by the form. + Form form = ocrEngine.PlaceTextUnder(image, doc); + content.RemoveElement(0); + content.AddElement(form, -1); + page.UpdateContent(); } + doc.Save(SaveFlags.Full, sOutput); } } } } - } } diff --git a/DotNETCore/Sample_Source/Other/StreamIO/StreamIO.cs b/DotNETCore/Sample_Source/Other/StreamIO/StreamIO.cs index c541f586..8d2ecf7c 100644 --- a/DotNETCore/Sample_Source/Other/StreamIO/StreamIO.cs +++ b/DotNETCore/Sample_Source/Other/StreamIO/StreamIO.cs @@ -32,36 +32,36 @@ class StreamIOSample /// The filename of the PDF document to read. /// A string to receive the contents of the PDF document. void ReadFromStream(String path, String output) - { - // Create a .NET FileStream object, opened using the path argument. - // A FileStream is used here for demonstration only, but the technique - // works just as well for MemoryStream, or other streams which support - // seeking. In practice, when dealing with files it is usually more - // appropriate to pass the path directly to the Document constructor. - FileStream fs = new FileStream(path, FileMode.Open); - - // A document is then opened, using the FileStream as its data source. - using (Document d = new Document(fs)) - { - // Add a watermark to have some visible change to the PDF - WatermarkParams wp = new WatermarkParams(); - wp.TargetRange.PageSpec = PageSpec.AllPages; - WatermarkTextParams wtp = new WatermarkTextParams(); - wtp.Text = "This PDF was opened\nfrom a Stream"; - d.Watermark(wtp, wp); - - // The document can not simply be saved at this point. - // d.Save(SaveFlags.Incremental); // This will throw an exception. - - // Instead, the document can be saved to a file. Saving the document - // to a file causes the document to use the file as its data source. - d.Save(SaveFlags.Full, output); - - // Make another minor change. - d.Creator = "PDFL StreamIO Sample"; - - // Since the document is now backed by a file, an incremental save is okay. - d.Save(SaveFlags.Incremental); + { + // Create a .NET FileStream object, opened using the path argument. + // A FileStream is used here for demonstration only, but the technique + // works just as well for MemoryStream, or other streams which support + // seeking. In practice, when dealing with files it is usually more + // appropriate to pass the path directly to the Document constructor. + FileStream fs = new FileStream(path, FileMode.Open); + + // A document is then opened, using the FileStream as its data source. + using (Document d = new Document(fs)) + { + // Add a watermark to have some visible change to the PDF + WatermarkParams wp = new WatermarkParams(); + wp.TargetRange.PageSpec = PageSpec.AllPages; + WatermarkTextParams wtp = new WatermarkTextParams(); + wtp.Text = "This PDF was opened\nfrom a Stream"; + d.Watermark(wtp, wp); + + // The document can not simply be saved at this point. + // d.Save(SaveFlags.Incremental); // This will throw an exception. + + // Instead, the document can be saved to a file. Saving the document + // to a file causes the document to use the file as its data source. + d.Save(SaveFlags.Full, output); + + // Make another minor change. + d.Creator = "PDFL StreamIO Sample"; + + // Since the document is now backed by a file, an incremental save is okay. + d.Save(SaveFlags.Incremental); } } @@ -101,7 +101,6 @@ void WriteToStream(String output) { Console.WriteLine("creator: " + d.Creator); } - } void AddContentToPage(Page p) @@ -124,9 +123,8 @@ static void Main(string[] args) // ReSharper disable once UnusedVariable using (Library lib = new Library()) { - String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; - String sOutput1 = "StreamIO-out1.pdf"; + String sOutput1 = "StreamIO-out1.pdf"; String sOutput2 = "StreamIO-out2.pdf"; if (args.Length > 0) @@ -143,9 +141,7 @@ static void Main(string[] args) sample.ReadFromStream(sInput, sOutput1); sample.WriteToStream(sOutput2); - } } } } - diff --git a/DotNETCore/Sample_Source/Printing/PrintPDF/PrintPDF.cs b/DotNETCore/Sample_Source/Printing/PrintPDF/PrintPDF.cs index 1426ae1f..45fedd19 100644 --- a/DotNETCore/Sample_Source/Printing/PrintPDF/PrintPDF.cs +++ b/DotNETCore/Sample_Source/Printing/PrintPDF/PrintPDF.cs @@ -57,6 +57,7 @@ public override void Call(int page, int totalPages, float stagePercent, string i { Console.WriteLine("Printing Page {0} of {1}", page + 1, totalPages); } + break; } } @@ -78,7 +79,8 @@ static void Main(string[] args) } try - { // Printing may fail for reasons that have nothing to do with APDFL. + { + // Printing may fail for reasons that have nothing to do with APDFL. // PDF documents may contain material that cannot be printed, etc. Given // that, it's always best to expect the printing step to fail and take // appropriate measures. Such care becomes critical for server-based 24/7 @@ -94,19 +96,24 @@ static void Main(string[] args) Console.WriteLine(@"Library initialized."); String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; - String outFileNamePrn = "PrintPDF_out.prn"; // HINT: you'll find the file (in the working directory) next to PrintPDF.exe - string outFileNamePs = "PrintPDF_out.ps"; // HINT: you'll find the file (in the working directory) next to PrintPDF.exe + + // HINT: you'll find the file (in the working directory) next to PrintPDF.exe + String outFileNamePrn = "PrintPDF_out.prn"; + + // HINT: you'll find the file (in the working directory) next to PrintPDF.exe + string outFileNamePs = "PrintPDF_out.ps"; if (args.Length > 0) sInput = args[0]; - Console.WriteLine("Input file: " + sInput + ". Writing to output " + outFileNamePrn + " and " + outFileNamePs ); + Console.WriteLine("Input file: " + sInput + ". Writing to output " + outFileNamePrn + " and " + + outFileNamePs); // Open a PDF document ("using" will automatically .Close and .Dispose it)... using (Document doc = new Document(sInput)) { - #region Print To File (via Printer Driver) + // Platform print to a file... // // Printed output from the following method is composed by the selected @@ -119,7 +126,8 @@ static void Main(string[] args) // ultimately transfer it to the target printer). using (PrintUserParams userParams = new PrintUserParams()) - { // NOTE: userParams are only valid for ONE print job... + { + // NOTE: userParams are only valid for ONE print job... userParams.NCopies = 1; userParams.PrintParams.ExpandToFit = true; @@ -150,18 +158,22 @@ static void Main(string[] args) // // The code below creates 3 page ranges... // As specified (below), PDFL will emit up to 8 pages (1-4, 2, 4, 1, 3). - int upToFourPages = ((doc.NumPages > 4) ? 3 : doc.NumPages - 1); // 0-based + int upToFourPages = ((doc.NumPages > 4) ? 3 : doc.NumPages - 1); // 0-based if (upToFourPages == 0) - { // the end page must always be >= 1 + { + // the end page must always be >= 1 upToFourPages = 1; } + IList pageRanges = new List(); - pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.AllPages)); // p1-4 + pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.AllPages)); // p1-4 if (doc.NumPages > 1) - { // you can't ask for even or odd pages from a 1 page document - pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.OddPagesOnly)); // p1,3 - pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.EvenPagesOnly)); // p2,4 + { + // you can't ask for even or odd pages from a 1 page document + pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.OddPagesOnly)); // p1,3 + pageRanges.Add(new PageRange(0, upToFourPages, PageSpec.EvenPagesOnly)); // p2,4 } + PrintParams printParams = userParams.PrintParams; printParams.PageRanges = pageRanges; @@ -175,11 +187,14 @@ static void Main(string[] args) // to PostScript produced via the ExportAsPostScript method. Console.WriteLine("Printing to File: {0}", outFileNamePrn); - doc.PrintToFile(userParams, null /* for cancel see the PrintPDFGUI sample */, new SamplePrintProgressProc(), outFileNamePrn); + doc.PrintToFile(userParams, null /* for cancel see the PrintPDFGUI sample */, + new SamplePrintProgressProc(), outFileNamePrn); } + #endregion #region Print To Printer (via Printer Driver) + // Now let's, print directly to a printer (without ui)... // // Printed output from the following method is composed by the selected @@ -192,7 +207,8 @@ static void Main(string[] args) // ultimately transfer it to the target printer). using (PrintUserParams userParams = new PrintUserParams()) - { // NOTE: userParams are only valid for ONE print job... + { + // NOTE: userParams are only valid for ONE print job... userParams.NCopies = 1; userParams.PrintParams.ExpandToFit = true; @@ -240,11 +256,14 @@ static void Main(string[] args) #if WINDOWS Console.WriteLine(String.Format("Printing (direct) to Printer: {0}", userParams.DeviceName)); #endif - doc.Print(userParams, null /* for cancel see the PrintPDFGUI sample */, new SamplePrintProgressProc()); + doc.Print(userParams, null /* for cancel see the PrintPDFGUI sample */, + new SamplePrintProgressProc()); } -#endregion + + #endregion #region Export As PostScript (Device Independent, DSC Compliant) + // Export as (PDFL composed) PostScript... // // PostScript files produced via this *export* method are suitable @@ -258,7 +277,8 @@ static void Main(string[] args) // https://partners.adobe.com/public/developer/en/ps/5001.DSC_Spec.pdf using (PrintUserParams userParams = new PrintUserParams()) - { // NOTE: userParams are only valid for ONE print job... + { + // NOTE: userParams are only valid for ONE print job... userParams.NCopies = 1; // When export as PostScript you MUST use 1+ page ranges... @@ -266,14 +286,17 @@ static void Main(string[] args) // // The code below exports the entire PDF document (to a PostScript file)... IList pageRanges = new List(); - pageRanges.Add(new PageRange(0, (((doc.NumPages > 1)) ? doc.NumPages - 1 : 1), PageSpec.AllPages)); // all pages + pageRanges.Add(new PageRange(0, (((doc.NumPages > 1)) ? doc.NumPages - 1 : 1), + PageSpec.AllPages)); // all pages PrintParams printParams = userParams.PrintParams; printParams.PageRanges = pageRanges; Console.WriteLine("Exporting as PostScript to File: {0}", outFileNamePs); - doc.ExportAsPostScript(userParams, null /* for cancel see the PrintPDFGUI sample */, new SamplePrintProgressProc(), outFileNamePs); + doc.ExportAsPostScript(userParams, null /* for cancel see the PrintPDFGUI sample */, + new SamplePrintProgressProc(), outFileNamePs); } -#endregion + + #endregion } } } diff --git a/DotNETCore/Sample_Source/Security/Redactions/Redactions.cs b/DotNETCore/Sample_Source/Security/Redactions/Redactions.cs index deaf5e1d..43086998 100644 --- a/DotNETCore/Sample_Source/Security/Redactions/Redactions.cs +++ b/DotNETCore/Sample_Source/Security/Redactions/Redactions.cs @@ -65,14 +65,16 @@ static void Main(string[] args) // Store the Quads of all "Cloudy" words in a list for later use in // creating the redaction object. if (w.Text.ToLower().Equals("cloudy") || - ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && - w.Text.ToLower().StartsWith("cloudy"))) + ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == + WordAttributeFlags.HasTrailingPunctuation && + w.Text.ToLower().StartsWith("cloudy"))) cloudyQuads.AddRange(w.Quads); // Store the Quads of all "Rain" words if (w.Text.ToLower().Equals("rain") || - ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && - w.Text.ToLower().StartsWith("rain"))) + ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == + WordAttributeFlags.HasTrailingPunctuation && + w.Text.ToLower().StartsWith("rain"))) rainQuads.AddRange(w.Quads); } @@ -84,7 +86,7 @@ static void Main(string[] args) /* fill the "normal" appearance with 20% red */ not_cloudy.FillNormal = true; - not_cloudy.SetFillColor (red, 0.25); + not_cloudy.SetFillColor(red, 0.25); Console.WriteLine("Found rain instances: " + rainQuads.Count); Redaction no_rain = new Redaction(docpage, rainQuads); diff --git a/DotNETCore/Sample_Source/Text/AddGlyphs/AddGlyphs.cs b/DotNETCore/Sample_Source/Text/AddGlyphs/AddGlyphs.cs index 48dc5c3a..3bf3d1b9 100644 --- a/DotNETCore/Sample_Source/Text/AddGlyphs/AddGlyphs.cs +++ b/DotNETCore/Sample_Source/Text/AddGlyphs/AddGlyphs.cs @@ -50,7 +50,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."); @@ -89,7 +90,6 @@ static void Main(string[] args) doc.EmbedFonts(EmbedFlags.None); doc.Save(SaveFlags.Full, sOutput); - } } } diff --git a/DotNETCore/Sample_Source/Text/AddUnicodeText/AddUnicodeText.cs b/DotNETCore/Sample_Source/Text/AddUnicodeText/AddUnicodeText.cs index fdb0363f..aed02217 100644 --- a/DotNETCore/Sample_Source/Text/AddUnicodeText/AddUnicodeText.cs +++ b/DotNETCore/Sample_Source/Text/AddUnicodeText/AddUnicodeText.cs @@ -48,11 +48,21 @@ static void Main(string[] args) strings.Add("Chinese (Mandarin) - \u4e16\u754c\u4eba\u6743\u5ba3\u8a00"); strings.Add("Japanese - \u300e\u4e16\u754c\u4eba\u6a29\u5ba3\u8a00\u300f"); - strings.Add("French - \u0044\u00e9\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u0075\u006e\u0069\u0076\u0065\u0072\u0073\u0065\u006c\u006c\u0065\u0020\u0064\u0065\u0073\u0020\u0064\u0072\u006f\u0069\u0074\u0073\u0020\u0064\u0065\u0020\u006c\u2019\u0068\u006f\u006d\u006d\u0065"); + strings.Add("French - \u0044\u00e9\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e" + + "\u0020\u0075\u006e\u0069\u0076\u0065\u0072\u0073\u0065\u006c\u006c\u0065\u0020\u0064" + + "\u0065\u0073\u0020\u0064\u0072\u006f\u0069\u0074\u0073\u0020\u0064\u0065\u0020\u006c" + + "\u2019\u0068\u006f\u006d\u006d\u0065"); strings.Add("Korean - \uc138\u0020\uacc4\u0020\uc778\u0020\uad8c\u0020\uc120\u0020\uc5b8"); - strings.Add("English - \u0055\u006e\u0069\u0076\u0065\u0072\u0073\u0061\u006c\u0020\u0044\u0065\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u006f\u0066\u0020\u0048\u0075\u006d\u0061\u006e\u0020\u0052\u0069\u0067\u0068\u0074\u0073"); - strings.Add("Greek - \u039f\u0399\u039a\u039f\u03a5\u039c\u0395\u039d\u0399\u039a\u0397\u0020\u0394\u0399\u0391\u039a\u0397\u03a1\u03a5\u039e\u0397\u0020\u0393\u0399\u0391\u0020\u03a4\u0391\u0020\u0391\u039d\u0398\u03a1\u03a9\u03a0\u0399\u039d\u0391\u0020\u0394\u0399\u039a\u0391\u0399\u03a9\u039c\u0391\u03a4\u0391"); - strings.Add("Russian - \u0412\u0441\u0435\u043e\u0431\u0449\u0430\u044f\u0020\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f\u0020\u043f\u0440\u0430\u0432\u0020\u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430"); + strings.Add("English - \u0055\u006e\u0069\u0076\u0065\u0072\u0073\u0061\u006c\u0020\u0044" + + "\u0065\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u006f\u0066\u0020" + + "\u0048\u0075\u006d\u0061\u006e\u0020\u0052\u0069\u0067\u0068\u0074\u0073"); + strings.Add("Greek - \u039f\u0399\u039a\u039f\u03a5\u039c\u0395\u039d\u0399\u039a\u0397\u0020" + + "\u0394\u0399\u0391\u039a\u0397\u03a1\u03a5\u039e\u0397\u0020\u0393\u0399\u0391\u0020" + + "\u03a4\u0391\u0020\u0391\u039d\u0398\u03a1\u03a9\u03a0\u0399\u039d\u0391\u0020\u0394" + + "\u0399\u039a\u0391\u0399\u03a9\u039c\u0391\u03a4\u0391"); + strings.Add("Russian - \u0412\u0441\u0435\u043e\u0431\u0449\u0430\u044f\u0020\u0434\u0435" + + "\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044f\u0020\u043f\u0440\u0430\u0432\u0020" + + "\u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430"); List fonts = new List(); try @@ -62,7 +72,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."); @@ -71,6 +82,7 @@ static void Main(string[] args) throw; } + fonts.Add(new Font("KozGoPr6N-Medium")); fonts.Add(new Font("AdobeMyungjoStd-Medium")); @@ -84,7 +96,8 @@ static void Main(string[] args) Font font = GetRepresentableFont(fonts, str); if (font == null) { - Console.WriteLine("Couldn't find a font that can represent all characters in the string: " + str); + Console.WriteLine( + "Couldn't find a font that can represent all characters in the string: " + str); } else { @@ -92,7 +105,6 @@ static void Main(string[] args) Matrix m = new Matrix(14, 0, 0, 14, x, y); TextRun tr = new TextRun(font.Name + " - " + str, font, gs, ts, m); unicodeText.AddRun(tr); - } // Start the next string lower down the page. @@ -107,7 +119,6 @@ static void Main(string[] args) Console.WriteLine("Embedding fonts."); doc.EmbedFonts(EmbedFlags.None); doc.Save(SaveFlags.Full, sOutput); - } } @@ -118,6 +129,7 @@ static Font GetRepresentableFont(List fonts, String str) if (font.IsTextRepresentable(str)) return font; } + return null; } } diff --git a/DotNETCore/Sample_Source/Text/AddVerticalText/AddVerticalText.cs b/DotNETCore/Sample_Source/Text/AddVerticalText/AddVerticalText.cs index f5551a49..7b8470a9 100644 --- a/DotNETCore/Sample_Source/Text/AddVerticalText/AddVerticalText.cs +++ b/DotNETCore/Sample_Source/Text/AddVerticalText/AddVerticalText.cs @@ -47,7 +47,9 @@ static void Main(string[] args) List strings = new List(); - strings.Add("\u0055\u006e\u0069\u0076\u0065\u0072\u0073\u0061\u006c\u0020\u0044\u0065\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u006f\u0066\u0020\u0048\u0075\u006d\u0061\u006e\u0020\u0052\u0069\u0067\u0068\u0074\u0073"); + strings.Add("\u0055\u006e\u0069\u0076\u0065\u0072\u0073\u0061\u006c\u0020\u0044\u0065\u0063" + + "\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u006f\u0066\u0020\u0048\u0075" + + "\u006d\u0061\u006e\u0020\u0052\u0069\u0067\u0068\u0074\u0073"); strings.Add("\u4e16\u754c\u4eba\u6743\u5ba3\u8a00"); strings.Add("\u300e\u4e16\u754c\u4eba\u6a29\u5ba3\u8a00\u300f"); strings.Add("\uc138\u0020\uacc4\u0020\uc778\u0020\uad8c\u0020\uc120\u0020\uc5b8"); @@ -68,7 +70,8 @@ static void Main(string[] args) Font font = GetRepresentableFont(fonts, str); if (font == null) { - Console.WriteLine("Couldn't find a font that can represent all characters in the string: " + str); + Console.WriteLine( + "Couldn't find a font that can represent all characters in the string: " + str); } else { @@ -76,7 +79,6 @@ static void Main(string[] args) Matrix m = new Matrix(14, 0, 0, 14, x, y); TextRun tr = new TextRun(str, font, gs, ts, m); unicodeText.AddRun(tr); - } // Start the next string moving across the page to the right @@ -91,7 +93,6 @@ static void Main(string[] args) Console.WriteLine("Embedding fonts."); doc.EmbedFonts(EmbedFlags.None); doc.Save(SaveFlags.Full, sOutput); - } } @@ -102,6 +103,7 @@ static Font GetRepresentableFont(List fonts, String str) if (font.IsTextRepresentable(str)) return font; } + return null; } } diff --git a/DotNETCore/Sample_Source/Text/ListWords/ListWords.cs b/DotNETCore/Sample_Source/Text/ListWords/ListWords.cs index 456990fd..53c3d77b 100644 --- a/DotNETCore/Sample_Source/Text/ListWords/ListWords.cs +++ b/DotNETCore/Sample_Source/Text/ListWords/ListWords.cs @@ -44,19 +44,19 @@ static void Main(string[] args) wordConfig.IgnoreCharGaps = true; wordConfig.IgnoreLineGaps = false; wordConfig.NoAnnots = true; - wordConfig.NoEncodingGuess = true; // leave non-Roman single-byte font alone + wordConfig.NoEncodingGuess = true; // leave non-Roman single-byte font alone // Std Roman treatment for custom encoding; overrides the noEncodingGuess option wordConfig.UnknownToStdEnc = false; - wordConfig.DisableTaggedPDF = true; // legacy mode WordFinder creation + wordConfig.DisableTaggedPDF = true; // legacy mode WordFinder creation wordConfig.NoXYSort = false; wordConfig.PreserveSpaces = false; wordConfig.NoLigatureExp = false; wordConfig.NoHyphenDetection = false; wordConfig.TrustNBSpace = false; - wordConfig.NoExtCharOffset = false; // text extraction efficiency - wordConfig.NoStyleInfo = false; // text extraction efficiency + wordConfig.NoExtCharOffset = false; // text extraction efficiency + wordConfig.NoStyleInfo = false; // text extraction efficiency WordFinder wordFinder = new WordFinder(doc, WordFinderVersion.Latest, wordConfig); IList pageWords = null; @@ -88,6 +88,7 @@ static void Main(string[] args) Console.WriteLine(s); } } + Console.WriteLine("Pages=" + nPages); } } diff --git a/DotNETCore/Sample_Source/Text/TextExtract/TextExtract.cs b/DotNETCore/Sample_Source/Text/TextExtract/TextExtract.cs index 83037c48..af37aed4 100644 --- a/DotNETCore/Sample_Source/Text/TextExtract/TextExtract.cs +++ b/DotNETCore/Sample_Source/Text/TextExtract/TextExtract.cs @@ -51,9 +51,9 @@ static void Main(string[] args) bool docIsTagged = false; PDFDict markInfoDict; PDFBoolean markedEntry; - if ((markInfoDict = (PDFDict)doc.Root.Get("MarkInfo")) != null) + if ((markInfoDict = (PDFDict) doc.Root.Get("MarkInfo")) != null) { - if ((markedEntry = (PDFBoolean)markInfoDict.Get("Marked")) != null) + if ((markedEntry = (PDFBoolean) markInfoDict.Get("Marked")) != null) { if (markedEntry.Value) docIsTagged = true; @@ -69,14 +69,14 @@ static void Main(string[] args) // Std Roman treatment for custom encoding; overrides the noEncodingGuess option wordConfig.UnknownToStdEnc = false; - wordConfig.DisableTaggedPDF = false; // legacy mode WordFinder creation + wordConfig.DisableTaggedPDF = false; // legacy mode WordFinder creation wordConfig.NoXYSort = true; wordConfig.PreserveSpaces = false; wordConfig.NoLigatureExp = false; wordConfig.NoHyphenDetection = false; wordConfig.TrustNBSpace = false; - wordConfig.NoExtCharOffset = false; // text extraction efficiency - wordConfig.NoStyleInfo = false; // text extraction efficiency + wordConfig.NoExtCharOffset = false; // text extraction efficiency + wordConfig.NoStyleInfo = false; // text extraction efficiency WordFinder wordFinder = new WordFinder(doc, WordFinderVersion.Latest, wordConfig); @@ -98,15 +98,15 @@ static void ExtractTextUntagged(Document doc, WordFinder wordFinder) for (int i = 0; i < nPages; i++) { pageWords = wordFinder.GetWordList(i); - + String textToExtract = ""; - + for (int wordnum = 0; wordnum < pageWords.Count; wordnum++) { Word wInfo; wInfo = pageWords[wordnum]; string s = wInfo.Text; - + // Check for hyphenated words that break across a line. if (((wInfo.Attributes & WordAttributeFlags.HasSoftHyphen) == WordAttributeFlags.HasSoftHyphen) && ((wInfo.Attributes & WordAttributeFlags.LastWordOnLine) == WordAttributeFlags.LastWordOnLine)) @@ -131,18 +131,20 @@ static void ExtractTextUntagged(Document doc, WordFinder wordFinder) { textToExtract += " "; } + // Check for a line break and add one if necessary if ((wInfo.Attributes & WordAttributeFlags.LastWordOnLine) == WordAttributeFlags.LastWordOnLine) textToExtract += "\n"; } - - logfile.WriteLine(""); + + logfile.WriteLine(""); logfile.WriteLine(textToExtract); // Release requested WordList for (int wordnum = 0; wordnum < pageWords.Count; wordnum++) pageWords[wordnum].Dispose(); } + Console.WriteLine("Extracted " + nPages + " pages."); logfile.Close(); } @@ -176,7 +178,7 @@ static void ExtractTextTagged(Document doc, WordFinder wordFinder) { // Remove the hyphen and combine the two parts of the word before adding to the extracted text. // Note that we pass in the Unicode character for soft hyphen. - string[] splitstrs = s.Split(new[] { '\u00ad' }); + string[] splitstrs = s.Split(new[] {'\u00ad'}); textToExtract += splitstrs[0] + splitstrs[1]; } else @@ -187,6 +189,7 @@ static void ExtractTextTagged(Document doc, WordFinder wordFinder) { textToExtract += " "; } + // Check for a line break and add one if necessary. // Normally this is accomplished using WordAttributeFlags.LastWordOnLine, // but for tagged PDFs, the LastWordOnLine flag is set according to the @@ -208,6 +211,7 @@ static void ExtractTextTagged(Document doc, WordFinder wordFinder) for (int wordnum = 0; wordnum < pageWords.Count; wordnum++) pageWords[wordnum].Dispose(); } + Console.WriteLine("Extracted " + nPages + " pages."); logfile.Close(); }