From cc23a487e5a5a4fa4e649325e224f8acf69d4f22 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Mon, 18 Sep 2023 15:23:32 -0300 Subject: [PATCH] Resolve merge with master and PDFA implementation. (cherry picked from commit 404a2f9b36f41a8f5c7343d983c6edef6999b610) # Conflicts: # dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs # dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs --- .../GxPdfReportsCS/PDFReportItext7.cs | 60 +++++++++++++++++-- .../GxPdfReportsCS/PDFReportCommon.cs | 40 +++++++------ .../GxPdfReportsCS/PDFReportItext4.cs | 9 +-- 3 files changed, 80 insertions(+), 29 deletions(-) diff --git a/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext7.cs b/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext7.cs index 220013d69..b460dc4e7 100644 --- a/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext7.cs +++ b/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext7.cs @@ -94,14 +94,22 @@ protected override void init(ref int gxYPage, ref int gxXPage, int pageWidth, in else justifiedType = TextAlignment.JUSTIFIED; - writer = new PdfWriter(outputStream); + writer = new PdfWriter(outputStream); writer.SetCompressionLevel(CompressionConstants.BEST_COMPRESSION); try { + string level = props.getGeneralProperty(Const.COMPLIANCE_LEVEL); + if (Enum.TryParse(level, true, out complianceLevel)) + { + //if (SetComplainceLevel(complianceLevel)) + //writer.SetTagged(); + } + pdfDocument = new PdfDocument(writer); pdfDocument.SetDefaultPageSize(this.pageSize); document = new Document(pdfDocument); + } catch (PdfException de) { @@ -109,13 +117,27 @@ protected override void init(ref int gxYPage, ref int gxXPage, int pageWidth, in } } + internal override bool SetComplainceLevel(PdfConformanceLevel level) + { + /*switch (level) + { + case PdfConformanceLevel.Pdf_A1A: + writer.PDFXConformance = PdfWriter.PDFA1A; + return true; + case PdfConformanceLevel.Pdf_A1B: + writer.PDFXConformance = PdfWriter.PDFA1B; + return true; + default: + return false; + }*/ + return false; + } + /** + * @param hideCorners indicates whether corner triangles should be hidden when the side that joins them is hidden. + */ - /** - * @param hideCorners indicates whether corner triangles should be hidden when the side that joins them is hidden. - */ - - private void drawRectangle(PdfCanvas cb, float x, float y, float w, float h, + private void drawRectangle(PdfCanvas cb, float x, float y, float w, float h, int styleTop, int styleBottom, int styleRight, int styleLeft, float radioTL, float radioTR, float radioBL, float radioBR, float penAux, bool hideCorners) { @@ -505,6 +527,7 @@ public override void GxDrawBitMap(String bitmap, int left, int top, int right, i image.ScaleAbsolute(rightAux - leftAux, bottomAux - topAux); else image.ScaleToFit(rightAux - leftAux, bottomAux - topAux); + image.GetAccessibilityProperties().SetAlternateDescription(Path.GetFileName(bitmap)); document.Add(image); } } @@ -671,8 +694,17 @@ public override void GxAttris(String fontName, int fontSize, bool fontBold, bool baseFont = CreateDefaultFont(); } } + PdfFont defaultFont; private PdfFont CreateDefaultFont() { + if (defaultFont == null) + { + if (IsPdfA()) + defaultFont = PdfFontFactory.CreateFont("Helvetica", PdfEncodings.CP1252, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED); + else + defaultFont = PdfFontFactory.CreateFont("Helvetica", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED); + } + return PdfFontFactory.CreateFont("Helvetica", PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.PREFER_NOT_EMBEDDED); } public override void setAsianFont(String fontName, String style) @@ -1235,6 +1267,22 @@ public override void GxEndDocument() pdfDocument.GetCatalog().SetOpenAction(PdfAction.CreateJavaScript(javascript.ToString())); } + if (IsPdfA()) + { + /*using (Stream iccProfile = ReadResource("sRGB Color Space Profile.icm")) + { + ICC_Profile icc = ICC_Profile.GetInstance(iccProfile); + writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); + } + + writer.ExtraCatalog.Put(PdfName.LANG, new PdfString(Config.GetCultureForLang(language).Name)); + PdfDictionary markInfo = new PdfDictionary(PdfName.MARKINFO); + markInfo.Put(PdfName.MARKED, new PdfBoolean(PdfBoolean.TRUE)); + writer.ExtraCatalog.Put(PdfName.MARKINFO, markInfo); + + writer.CreateXmpMetadata();*/ + + } document.Close(); diff --git a/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs b/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs index 52b40229c..ec17fe9a5 100644 --- a/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs +++ b/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs @@ -30,18 +30,8 @@ internal enum VerticalAlign MIDDLE = 1, BOTTOM = 2, } - public enum PdfConformanceLevel - { - None, - Pdf_A1B, - Pdf_X1A2001, - Pdf_A1A, - Pdf_A2A, - Pdf_A2B, - Pdf_A3A, - Pdf_A3B - } - public class PDFReportItextBase : IReportHandler + + public abstract class PDFReportItextBase : IReportHandler { protected int lineHeight, pageLines; @@ -51,8 +41,7 @@ public class PDFReportItextBase : IReportHandler protected bool fontStrikethru; protected int fontSize; protected string language; - protected PdfConformanceLevel complianceLevel = PdfConformanceLevel.None; - + protected Stream outputStream = null; protected static object syncRoot = new Object(); @@ -89,6 +78,7 @@ public class PDFReportItextBase : IReportHandler public static float DOTS_UNITS_ON = 1; public bool lineCapProjectingSquare = true; public bool barcode128AsImage = true; + protected PdfConformanceLevel complianceLevel = PdfConformanceLevel.None; protected float[] STYLE_SOLID = new float[] { 1, 0 };//0 protected float[] STYLE_NONE = null;//1 protected float[] STYLE_DOTTED, //2 @@ -309,7 +299,7 @@ private void loadPrinterSettingsProps(String iniFile, String form, String printe } internal static void SetDefaultComplianceLevel(PdfConformanceLevel level) { - if (props != null) + if (props!=null) props.setGeneralProperty(Const.COMPLIANCE_LEVEL, level.ToString()); } private void loadProps() @@ -349,7 +339,7 @@ private void loadProps() props.setupGeneralProperty(Const.MARGINS_INSIDE_BORDER, Const.DEFAULT_MARGINS_INSIDE_BORDER.ToString().ToLower()); props.setupGeneralProperty(Const.OUTPUT_FILE_DIRECTORY, "."); props.setupGeneralProperty(Const.LEADING, "2"); - props.setupGeneralProperty(Const.COMPLIANCE_LEVEL, PdfConformanceLevel.None.ToString()); + props.setupGeneralProperty(Const.COMPLIANCE_LEVEL, PdfConformanceLevel.None.ToString()); props.setupGeneralProperty(Const.RUN_DIRECTION, Const.RUN_DIRECTION_LTR); props.setupGeneralProperty(Const.JUSTIFIED_TYPE_ALL, "false"); @@ -719,6 +709,7 @@ protected bool IsPdfA() { return complianceLevel != 0; } + public void GxEndPrinter() { } @@ -906,8 +897,9 @@ protected float reconvertScale(float value) { float result = value / (float)(SCALE_FACTOR / PPP); return result; - } + } + internal abstract bool SetComplainceLevel(PdfConformanceLevel level); } public class ParseINI @@ -1359,7 +1351,7 @@ public class Const public static String ADJUST_TO_PAPER = "AdjustToPaper"; //fit to page public static String LINE_CAP_PROJECTING_SQUARE = "LineCapProjectingSquare"; public static String BARCODE128_AS_IMAGE = "Barcode128AsImage"; - public static String LEADING = "Leading"; + public static String LEADING = "Leading"; internal static String COMPLIANCE_LEVEL = "ComplianceLevel"; //Printer settings @@ -1850,6 +1842,16 @@ public static ArrayList parseLine(String line, String separator) } } - + public enum PdfConformanceLevel + { + None, + Pdf_A1B, + Pdf_X1A2001, + Pdf_A1A, + Pdf_A2A, + Pdf_A2B, + Pdf_A3A, + Pdf_A3B + } } diff --git a/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs b/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs index 54cdf1b32..ec5337d36 100644 --- a/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs +++ b/dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs @@ -664,7 +664,7 @@ private BaseFont CreateDefaultFont() else defaultFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } - return defaultFont; + return defaultFont; } private void LoadAsianFontsDll() { @@ -1401,7 +1401,6 @@ public override void GxEndDocument() } } - if (IsPdfA()) { using (Stream iccProfile = ReadResource("sRGB Color Space Profile.icm")) @@ -1417,7 +1416,8 @@ public override void GxEndDocument() writer.CreateXmpMetadata(); - } + } + document.Close(); @@ -1532,7 +1532,8 @@ private void SetSimpleColumn(ColumnText col, Rectangle rect) { col.SetSimpleColumn(rect.Left, rect.Bottom, rect.Right, rect.Top); } - internal bool SetComplainceLevel(PdfConformanceLevel level) + + internal override bool SetComplainceLevel(PdfConformanceLevel level) { switch (level) {