diff --git a/DocXToPdfConverter/DocXToPdfConverter.csproj b/DocXToPdfConverter/DocXToPdfConverter.csproj index 9bdd12e..252bc28 100644 --- a/DocXToPdfConverter/DocXToPdfConverter.csproj +++ b/DocXToPdfConverter/DocXToPdfConverter.csproj @@ -2,7 +2,7 @@ Library - netcoreapp2.1 + net7.0 true @@ -19,7 +19,8 @@ - + + diff --git a/DocXToPdfConverter/DocXToPdfHandlers/ImageHandler.cs b/DocXToPdfConverter/DocXToPdfHandlers/ImageHandler.cs index 90b52e0..e4b53c8 100644 --- a/DocXToPdfConverter/DocXToPdfHandlers/ImageHandler.cs +++ b/DocXToPdfConverter/DocXToPdfHandlers/ImageHandler.cs @@ -1,18 +1,17 @@ using System; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using DocumentFormat.OpenXml.Packaging; +using IronSoftware.Drawing; +using static IronSoftware.Drawing.AnyBitmap; namespace DocXToPdfConverter.DocXToPdfHandlers { public static class ImageHandler { - - public static Image GetImage(this MemoryStream ms) + public static AnyBitmap GetImage(this MemoryStream ms) { ms.Position = 0; - var image = Image.FromStream(ms); + var image = AnyBitmap.FromStream(ms); ms.Position = 0; return image; } @@ -20,28 +19,28 @@ public static Image GetImage(this MemoryStream ms) public static ImagePartType GetImagePartType(this MemoryStream stream) { stream.Position = 0; - using (var image = Image.FromStream(stream)) + using (var image = AnyBitmap.FromStream(stream)) { stream.Position = 0; - if (ImageFormat.Jpeg.Equals(image.RawFormat)) + if (ImageFormat.Jpeg.Equals(image.GetImageFormat())) { return ImagePartType.Jpeg; } - else if (ImageFormat.Png.Equals(image.RawFormat)) + else if (ImageFormat.Png.Equals(image.GetImageFormat())) { return ImagePartType.Png; } - else if (ImageFormat.Gif.Equals(image.RawFormat)) + else if (ImageFormat.Gif.Equals(image.GetImageFormat())) { return ImagePartType.Gif; } - else if (ImageFormat.Bmp.Equals(image.RawFormat)) + else if (ImageFormat.Bmp.Equals(image.GetImageFormat())) { return ImagePartType.Bmp; } - else if (ImageFormat.Tiff.Equals(image.RawFormat)) + else if (ImageFormat.Tiff.Equals(image.GetImageFormat())) { return ImagePartType.Tiff; } @@ -53,27 +52,27 @@ public static ImagePartType GetImagePartType(this MemoryStream stream) public static string GetImageType(this MemoryStream stream) { stream.Position = 0; - using (var image = Image.FromStream(stream)) + using (var image = AnyBitmap.FromStream(stream)) { stream.Position = 0; - if (ImageFormat.Jpeg.Equals(image.RawFormat)) + if (ImageFormat.Jpeg.Equals(image.GetImageFormat())) { return "jpeg"; } - else if (ImageFormat.Png.Equals(image.RawFormat)) + else if (ImageFormat.Png.Equals(image.GetImageFormat())) { return "png"; } - else if (ImageFormat.Gif.Equals(image.RawFormat)) + else if (ImageFormat.Gif.Equals(image.GetImageFormat())) { return "gif"; } - else if (ImageFormat.Bmp.Equals(image.RawFormat)) + else if (ImageFormat.Bmp.Equals(image.GetImageFormat())) { return "bmp"; } - else if (ImageFormat.Tiff.Equals(image.RawFormat)) + else if (ImageFormat.Tiff.Equals(image.GetImageFormat())) { return "tiff"; } diff --git a/DocXToPdfConverter/Documentation/Readme.md b/DocXToPdfConverter/Documentation/Readme.md index c351188..ecca7f4 100644 --- a/DocXToPdfConverter/Documentation/Readme.md +++ b/DocXToPdfConverter/Documentation/Readme.md @@ -28,16 +28,16 @@ Report from DOCX / HTML to PDF Converter can parse the source document and intro Don't get scared away that I use LibreOffice, it is easier than you may think! 1. LibreOffice - just get the PORTABLE EDITION as you don't screw up your webserver with an installation. The portable version just runs without any installation. We need LibreOffice for converting from DOCX or from HTML to PDF and DOCX, etc -2. Nuget: -* Microsoft.NetCore.App +2. Nuget: * Document.Format.OpenXml -* System.Drawing.Common +* IronSoftware.System.Drawing; +* SkiaSharp 3. The OpenXml PowerTools (thanks to Eric White for this great work), which I already included into the project, the whole code! ## Get started here! -1. Add dependencies to a) Document.Format.OpenXml (by Microsoft). For the OpenXml Powertools by Eric White (which are already included in the project), add System.Drawing.Common (for .NET Core). The regular System.Drawing won't work! +1. Add dependencies to a) Document.Format.OpenXml (by Microsoft). For the OpenXml Powertools by Eric White (which are already included in the project). 2. Download LibreOffice (https://www.libreoffice.org/download/portable-versions/). I recommend the portable edition as it does not install anything in your server. It is like unzipping files onto your harddrive. Note the path to "soffice.exe" (I don't know what the file is called in Linux / MacOS, probably just soffice. It is an executable to run a headless, mute version of LibreOffice for conversion processes). On my Windows machine, it is under: C:\PortableApps\LibreOfficePortable\App\libreoffice\program\soffice.exe. diff --git a/DocXToPdfConverter/OpenXmlPowerTools/ColorParser.cs b/DocXToPdfConverter/OpenXmlPowerTools/ColorParser.cs index 7539e9f..b7d25a7 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/ColorParser.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/ColorParser.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Drawing; +using IronSoftware.Drawing; namespace OpenXmlPowerTools { @@ -18,7 +17,7 @@ public static bool TryFromName(string name, out Color color) { color = Color.FromName(name); - return color.IsNamedColor; + return color != null; } catch { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlComparer.Private.NestedTypes.cs b/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlComparer.Private.NestedTypes.cs index 136a5f3..49c1e7c 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlComparer.Private.NestedTypes.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlComparer.Private.NestedTypes.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Drawing; +using IronSoftware.Drawing; using System.Xml.Linq; namespace OpenXmlPowerTools diff --git a/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlRevisedDocumentInfo.cs b/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlRevisedDocumentInfo.cs index c0d8000..989aa83 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlRevisedDocumentInfo.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/Comparer/WmlRevisedDocumentInfo.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Drawing; +using IronSoftware.Drawing; namespace OpenXmlPowerTools { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/FontFamily.cs b/DocXToPdfConverter/OpenXmlPowerTools/FontFamily.cs new file mode 100644 index 0000000..83a215d --- /dev/null +++ b/DocXToPdfConverter/OpenXmlPowerTools/FontFamily.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using SkiaSharp; + +namespace DocXToPdfConverter +{ + public static class FontFamily + { + public static IEnumerable GetFontFamilies() + { + using (var fontManager = SKFontManager.Default) + { + return fontManager.FontFamilies; + } + } + } +} diff --git a/DocXToPdfConverter/OpenXmlPowerTools/FormattingAssembler.cs b/DocXToPdfConverter/OpenXmlPowerTools/FormattingAssembler.cs index 9cb85d9..f1da03d 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/FormattingAssembler.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/FormattingAssembler.cs @@ -7,7 +7,7 @@ using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; -using System.Drawing; +using IronSoftware.Drawing; namespace OpenXmlPowerTools { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverter.cs b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverter.cs index 5268553..4d2e4bd 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverter.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverter.cs @@ -2,17 +2,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; -using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; -using OpenXmlPowerTools; using OpenXmlPowerTools.HtmlToWml; -using OpenXmlPowerTools.HtmlToWml.CSS; using System.Text.RegularExpressions; namespace OpenXmlPowerTools diff --git a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverterCore.cs b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverterCore.cs index 438c57a..46babd1 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverterCore.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlConverterCore.cs @@ -98,8 +98,6 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; @@ -109,6 +107,8 @@ using OpenXmlPowerTools.HtmlToWml; using OpenXmlPowerTools.HtmlToWml.CSS; using System.Text.RegularExpressions; +using IronSoftware.Drawing; +using DocXToPdfConverter; namespace OpenXmlPowerTools.HtmlToWml { @@ -1159,10 +1159,10 @@ private static XElement FontMerge(XElement higherPriorityFont, XElement lowerPri return 0; // in theory, all unknown fonts are found by the above test, but if not... - FontFamily ff; + string ff; try { - ff = new FontFamily(fontName); + ff = (fontName); } catch (ArgumentException) { @@ -1885,9 +1885,9 @@ private static HashSet KnownFamilies if (_knownFamilies == null) { _knownFamilies = new HashSet(); - var families = FontFamily.Families; + var families = FontFamily.GetFontFamilies(); foreach (var fam in families) - _knownFamilies.Add(fam.Name); + _knownFamilies.Add(fam); } return _knownFamilies; } @@ -2279,7 +2279,7 @@ private static XElement TransformImageToWml(XElement element, HtmlToWmlConverter { string srcAttribute = (string)element.Attribute(XhtmlNoNamespace.src); byte[] ba = null; - Bitmap bmp = null; + AnyBitmap bmp = null; if (srcAttribute.StartsWith("data:")) { @@ -2289,14 +2289,14 @@ private static XElement TransformImageToWml(XElement element, HtmlToWmlConverter ba = Convert.FromBase64String(base64); using (MemoryStream ms = new MemoryStream(ba)) { - bmp = new Bitmap(ms); + bmp = new AnyBitmap(ms); } } else { try { - bmp = new Bitmap(settings.BaseUriForImages + "/" + srcAttribute); + bmp = new AnyBitmap(settings.BaseUriForImages + "/" + srcAttribute); } catch (ArgumentException) { @@ -2307,13 +2307,13 @@ private static XElement TransformImageToWml(XElement element, HtmlToWmlConverter return null; } MemoryStream ms = new MemoryStream(); - bmp.Save(ms, bmp.RawFormat); + bmp.ExportStream(ms, bmp.GetImageFormat()); ba = ms.ToArray(); } MainDocumentPart mdp = wDoc.MainDocumentPart; string rId = "R" + Guid.NewGuid().ToString().Replace("-", ""); - ImagePartType ipt = ImagePartType.Png; + var ipt = ImagePartType.Png; ImagePart newPart = mdp.AddImagePart(ipt, rId); using (Stream s = newPart.GetStream(FileMode.Create, FileAccess.ReadWrite)) s.Write(ba, 0, ba.GetUpperBound(0) + 1); @@ -2352,7 +2352,7 @@ private static XElement TransformImageToWml(XElement element, HtmlToWmlConverter return null; } - private static XElement GetImageAsInline(XElement element, HtmlToWmlConverterSettings settings, WordprocessingDocument wDoc, Bitmap bmp, + private static XElement GetImageAsInline(XElement element, HtmlToWmlConverterSettings settings, WordprocessingDocument wDoc, AnyBitmap bmp, string rId, int pictureId, string pictureDescription) { XElement inline = new XElement(WP.inline, // 20.4.2.8 @@ -2369,7 +2369,7 @@ private static XElement GetImageAsInline(XElement element, HtmlToWmlConverterSet return inline; } - private static XElement GetImageAsAnchor(XElement element, HtmlToWmlConverterSettings settings, WordprocessingDocument wDoc, Bitmap bmp, + private static XElement GetImageAsAnchor(XElement element, HtmlToWmlConverterSettings settings, WordprocessingDocument wDoc, AnyBitmap bmp, string rId, string floatValue, int pictureId, string pictureDescription) { Emu minDistFromEdge = (long)(0.125 * Emu.s_EmusPerInch); @@ -2550,13 +2550,12 @@ private static XElement GetRunPropertiesForImage() new XElement(W.noProof)); } - private static SizeEmu GetImageSizeInEmus(XElement img, Bitmap bmp) + private static SizeEmu GetImageSizeInEmus(XElement img, AnyBitmap bmp) { - double hres = bmp.HorizontalResolution; - double vres = bmp.VerticalResolution; - Size s = bmp.Size; - Emu cx = (long)((double)(s.Width / hres) * (double)Emu.s_EmusPerInch); - Emu cy = (long)((double)(s.Height / vres) * (double)Emu.s_EmusPerInch); + double? hres = bmp.HorizontalResolution; + double? vres = bmp.VerticalResolution; + Emu cx = (long)((double)(bmp.Width / hres) * (double)Emu.s_EmusPerInch); + Emu cy = (long)((double)(bmp.Height / vres) * (double)Emu.s_EmusPerInch); CssExpression width = img.GetProp("width"); CssExpression height = img.GetProp("height"); @@ -2583,7 +2582,7 @@ private static SizeEmu GetImageSizeInEmus(XElement img, Bitmap bmp) return new SizeEmu(cx, cy); } - private static XElement GetImageExtent(XElement img, Bitmap bmp) + private static XElement GetImageExtent(XElement img, AnyBitmap bmp) { SizeEmu szEmu = GetImageSizeInEmus(img, bmp); return new XElement(WP.extent, @@ -2616,7 +2615,7 @@ private static XElement GetCNvGraphicFramePr() new XAttribute(NoNamespace.noChangeAspect, 1))); } - private static XElement GetGraphicForImage(XElement element, string rId, Bitmap bmp, int pictureId, string pictureDescription) + private static XElement GetGraphicForImage(XElement element, string rId, AnyBitmap bmp, int pictureId, string pictureDescription) { SizeEmu szEmu = GetImageSizeInEmus(element, bmp); XElement graphic = new XElement(A.graphic, diff --git a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlCssParser.cs b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlCssParser.cs index 56d86d5..2eaf498 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlCssParser.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/HtmlToWmlCssParser.cs @@ -17,7 +17,7 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Drawing; +using IronSoftware.Drawing; using System.Globalization; using System.IO; using System.Linq; diff --git a/DocXToPdfConverter/OpenXmlPowerTools/MetricsGetter.cs b/DocXToPdfConverter/OpenXmlPowerTools/MetricsGetter.cs index 597d6a7..597d906 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/MetricsGetter.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/MetricsGetter.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.IO; using System.IO.Packaging; using System.Linq; @@ -12,6 +11,8 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Validation; using System.Globalization; +using IronSoftware.Drawing; +using SkiaSharp; namespace OpenXmlPowerTools { @@ -25,12 +26,6 @@ public class MetricsGetterSettings public class MetricsGetter { - private static Lazy Graphics { get; } = new Lazy(() => - { - Image image = new Bitmap(1, 1); - return System.Drawing.Graphics.FromImage(image); - }); - public static XElement GetMetrics(string fileName, MetricsGetterSettings settings) { FileInfo fi = new FileInfo(fileName); @@ -108,24 +103,33 @@ public static XElement GetDocxMetrics(WmlDocument wmlDoc, MetricsGetterSettings return metrics; } - private static int _getTextWidth(FontFamily ff, FontStyle fs, decimal sz, string text) + private static SKFontStyle MapFontStyle(FontStyle fontStyle) { - try - { - using (var f = new Font(ff, (float)sz / 2f, fs)) - { - var proposedSize = new Size(int.MaxValue, int.MaxValue); - var sf = Graphics.Value.MeasureString(text, f, proposedSize); - return (int) sf.Width; - } - } - catch + var weight = (fontStyle & FontStyle.Bold) != 0 ? SKFontStyleWeight.Bold : SKFontStyleWeight.Normal; + var width = SKFontStyleWidth.Normal; // No direct mapping in .NET's FontStyle + var slant = (fontStyle & FontStyle.Italic) != 0 ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright; + + return new SKFontStyle(weight, width, slant); + } + + private static int _getTextWidth(string fontFamily, FontStyle fontStyle, decimal size, string text) + { + var skFontStyle = MapFontStyle(fontStyle); + + using (var paint = new SKPaint()) { - return 0; + paint.Typeface = SKTypeface.FromFamilyName(fontFamily, skFontStyle); + paint.TextSize = (float)size; + + // Measure the text's width and height + var bounds = new SKRect(); + paint.MeasureText(text, ref bounds); + + return (int)bounds.Width; } } - public static int GetTextWidth(FontFamily ff, FontStyle fs, decimal sz, string text) + public static int GetTextWidth(string ff, FontStyle fs, decimal sz, string text) { try { @@ -149,7 +153,7 @@ public static int GetTextWidth(FontFamily ff, FontStyle fs, decimal sz, string t { // if both regular and bold fail, then get metrics for Times New Roman // use the original FontStyle (in fs) - var ff2 = new FontFamily("Times New Roman"); + var ff2 = "Times New Roman"; return _getTextWidth(ff2, fs, sz, text); } } diff --git a/DocXToPdfConverter/OpenXmlPowerTools/OxPtHelpers.cs b/DocXToPdfConverter/OpenXmlPowerTools/OxPtHelpers.cs index b48bed1..3f00b20 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/OxPtHelpers.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/OxPtHelpers.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.IO; using System.Linq; using System.Xml; @@ -11,10 +10,10 @@ using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml.Validation; -using OpenXmlPowerTools; using System.Text; using DocumentFormat.OpenXml; -using System.Drawing.Imaging; +using IronSoftware.Drawing; +using static IronSoftware.Drawing.AnyBitmap; namespace OpenXmlPowerTools { @@ -374,7 +373,7 @@ public static void ConvertToHtml(string file, string outputDirectory) localDirInfo.Create(); ++imageCounter; string extension = imageInfo.ContentType.Split('/')[1].ToLower(); - ImageFormat imageFormat = null; + ImageFormat? imageFormat = null; if (extension == "png") { // Convert png to jpeg. @@ -408,7 +407,7 @@ public static void ConvertToHtml(string file, string outputDirectory) imageCounter.ToString() + "." + extension; try { - imageInfo.Bitmap.Save(imageFileName, imageFormat); + imageInfo.Bitmap.SaveAs(imageFileName, imageFormat.Value); } catch (System.Runtime.InteropServices.ExternalException) { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/Previous/WmlComparer.cs b/DocXToPdfConverter/OpenXmlPowerTools/Previous/WmlComparer.cs index 1a02bb7..69f5eab 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/Previous/WmlComparer.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/Previous/WmlComparer.cs @@ -10,7 +10,7 @@ using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; -using System.Drawing; +using IronSoftware.Drawing; using System.Security.Cryptography; using OpenXmlPowerTools; diff --git a/DocXToPdfConverter/OpenXmlPowerTools/PtOpenXmlUtil.cs b/DocXToPdfConverter/OpenXmlPowerTools/PtOpenXmlUtil.cs index fe84586..fe47d08 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/PtOpenXmlUtil.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/PtOpenXmlUtil.cs @@ -12,9 +12,8 @@ using System.Xml.Linq; using System.Collections.Generic; using DocumentFormat.OpenXml.Packaging; -using System.Drawing; -using Font = System.Drawing.Font; -using FontFamily = System.Drawing.FontFamily; +using IronSoftware.Drawing; +using DocXToPdfConverter; // ReSharper disable InconsistentNaming @@ -637,9 +636,9 @@ public static int CalcWidthOfRunInTwips(XElement r) if (KnownFamilies == null) { KnownFamilies = new HashSet(); - var families = FontFamily.Families; + var families = FontFamily.GetFontFamilies(); foreach (var fam in families) - KnownFamilies.Add(fam.Name); + KnownFamilies.Add(fam); } var fontName = (string)r.Attribute(PtOpenXml.pt + "FontName"); @@ -668,10 +667,10 @@ public static int CalcWidthOfRunInTwips(XElement r) if (!KnownFamilies.Contains(fontName)) return 0; // in theory, all unknown fonts are found by the above test, but if not... - FontFamily ff; + string ff; try { - ff = new FontFamily(fontName); + ff = (fontName); } catch (ArgumentException) { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/SmlCellFormatter.cs b/DocXToPdfConverter/OpenXmlPowerTools/SmlCellFormatter.cs index 274a2d7..bcba3fd 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/SmlCellFormatter.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/SmlCellFormatter.cs @@ -3,14 +3,9 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Drawing; using System.Globalization; using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Xml.Linq; -using DocumentFormat.OpenXml.Packaging; namespace OpenXmlPowerTools { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/SmlDataRetriever.cs b/DocXToPdfConverter/OpenXmlPowerTools/SmlDataRetriever.cs index 46f5091..8f62da0 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/SmlDataRetriever.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/SmlDataRetriever.cs @@ -3,15 +3,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Drawing; -using System.Globalization; using System.Linq; -using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; using System.IO; -using OpenXmlPowerTools; namespace OpenXmlPowerTools { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/SmlToHtmlConverter.cs b/DocXToPdfConverter/OpenXmlPowerTools/SmlToHtmlConverter.cs index 7c97f39..b5d747f 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/SmlToHtmlConverter.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/SmlToHtmlConverter.cs @@ -4,13 +4,12 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Drawing; -using System.Globalization; using System.Linq; using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; using System.IO; +using DocXToPdfConverter; namespace OpenXmlPowerTools { @@ -236,9 +235,9 @@ private static HashSet KnownFamilies if (_knownFamilies == null) { _knownFamilies = new HashSet(); - var families = FontFamily.Families; + var families = FontFamily.GetFontFamilies(); foreach (var fam in families) - _knownFamilies.Add(fam.Name); + _knownFamilies.Add(fam); } return _knownFamilies; } diff --git a/DocXToPdfConverter/OpenXmlPowerTools/WmlToHtmlConverter.cs b/DocXToPdfConverter/OpenXmlPowerTools/WmlToHtmlConverter.cs index 8c908cf..fcf4867 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/WmlToHtmlConverter.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/WmlToHtmlConverter.cs @@ -4,12 +4,13 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Drawing; using System.Globalization; using System.Linq; using System.Text; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; +using DocXToPdfConverter; +using IronSoftware.Drawing; // 200e lrm - LTR // 200f rlm - RTL @@ -120,7 +121,7 @@ public static XElement ConvertToHtml(WordprocessingDocument wDoc, HtmlConverterS [SuppressMessage("ReSharper", "UnusedMember.Global")] public class ImageInfo { - public Bitmap Bitmap; + public AnyBitmap Bitmap; public XAttribute ImgStyleAttribute; public string ContentType; public XElement DrawingElement; @@ -2247,9 +2248,9 @@ private static HashSet KnownFamilies if (_knownFamilies == null) { _knownFamilies = new HashSet(); - var families = FontFamily.Families; + var families = FontFamily.GetFontFamilies(); foreach (var fam in families) - _knownFamilies.Add(fam.Name); + _knownFamilies.Add(fam); } return _knownFamilies; } @@ -2275,10 +2276,10 @@ private static int CalcWidthOfRunInTwips(XElement r) return 0; // in theory, all unknown fonts are found by the above test, but if not... - FontFamily ff; + string ff; try { - ff = new FontFamily(fontName); + ff = (fontName); } catch (ArgumentException) { @@ -3078,7 +3079,7 @@ private static XElement ProcessDrawing(WordprocessingDocument wordDoc, return null; using (var partStream = imagePart.GetStream()) - using (var bitmap = new Bitmap(partStream)) + using (var bitmap = new AnyBitmap(partStream)) { if (extentCx != null && extentCy != null) { @@ -3144,7 +3145,7 @@ private static XElement ProcessPictureOrObject(WordprocessingDocument wordDoc, { try { - using (var bitmap = new Bitmap(partStream)) + using (var bitmap = new AnyBitmap(partStream)) { var imageInfo = new ImageInfo() { diff --git a/DocXToPdfConverter/OpenXmlPowerTools/WmlToXml.cs b/DocXToPdfConverter/OpenXmlPowerTools/WmlToXml.cs index c7006e2..bbfa85b 100644 --- a/DocXToPdfConverter/OpenXmlPowerTools/WmlToXml.cs +++ b/DocXToPdfConverter/OpenXmlPowerTools/WmlToXml.cs @@ -17,7 +17,6 @@ using System.IO; using System.Xml.Linq; using DocumentFormat.OpenXml.Packaging; -using System.Drawing; namespace OpenXmlPowerTools { diff --git a/ExampleApplication/ExampleApplication.csproj b/ExampleApplication/ExampleApplication.csproj index 0edf066..9a325b7 100644 --- a/ExampleApplication/ExampleApplication.csproj +++ b/ExampleApplication/ExampleApplication.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + net7.0 diff --git a/ExampleApplication/Program.cs b/ExampleApplication/Program.cs index 027f960..9bb88a6 100644 --- a/ExampleApplication/Program.cs +++ b/ExampleApplication/Program.cs @@ -37,7 +37,7 @@ public static void Main(string[] args) //or anything you have in Linux... string locationOfLibreOfficeSoffice = - @"F:\PortableApps\LibreOfficePortable\App\libreoffice\program\soffice.exe"; + @"C:\utils\LibreOfficePortable\App\libreoffice\program\soffice.exe"; //This is only to get this example to work (find the word docx and the html file, which were