Skip to content

Commit

Permalink
Resolve merge with master and PDFA implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiamurialdo committed Sep 18, 2023
1 parent 51de452 commit 404a2f9
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 15 deletions.
3 changes: 3 additions & 0 deletions dotnet/src/dotnetcore/GxPdfReportsCS/GxPdfReportsCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<Compile Include="..\..\dotnetframework\GxPdfReportsCS\PDFReportCommon.cs" Link="PDFReportCommon.cs" />
<Compile Include="..\..\dotnetframework\GxPdfReportsCS\PDFReportItext4.cs" Link="PDFReportItext4.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\dotnetframework\GxPdfReportsCS\sRGB Color Space Profile.icm" Link="sRGB Color Space Profile.icm" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="itext7" Version="8.0.0" PrivateAssets="All" />
Expand Down
60 changes: 54 additions & 6 deletions dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,50 @@ 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)
{
GXLogging.Debug(log, "GxDrawRect error", de);
}
}

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)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();


Expand Down
52 changes: 44 additions & 8 deletions dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal enum VerticalAlign
BOTTOM = 2,
}

public class PDFReportItextBase : IReportHandler
public abstract class PDFReportItextBase : IReportHandler
{
protected int lineHeight, pageLines;

Expand All @@ -40,6 +40,7 @@ public class PDFReportItextBase : IReportHandler
protected bool fontUnderline;
protected bool fontStrikethru;
protected int fontSize;
protected string language;

protected Stream outputStream = null;

Expand Down Expand Up @@ -77,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
Expand Down Expand Up @@ -295,7 +297,11 @@ private void loadPrinterSettingsProps(String iniFile, String form, String printe
printerSettings.setupProperty(form, Const.COLOR, color + "");
printerSettings.setupProperty(form, Const.DUPLEX, duplex + "");
}

internal static void SetDefaultComplianceLevel(PdfConformanceLevel level)
{
if (props!=null)
props.setGeneralProperty(Const.COMPLIANCE_LEVEL, level.ToString());
}
private void loadProps()
{
if (props == null)
Expand Down Expand Up @@ -333,6 +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.RUN_DIRECTION, Const.RUN_DIRECTION_LTR);
props.setupGeneralProperty(Const.JUSTIFIED_TYPE_ALL, "false");

Expand Down Expand Up @@ -419,6 +426,7 @@ private float[] parsePattern(String patternStr)

public void GxRVSetLanguage(String lang)
{
language = lang;
}

public void GxSetTextMode(int nHandle, int nGridX, int nGridY, int nPageLength)
Expand Down Expand Up @@ -526,9 +534,14 @@ protected Hashtable GetFontLocations()

protected bool IsEmbeddedFont(string fontName)
{
bool generalEmbeedFont = props.getBooleanGeneralProperty(Const.EMBEED_SECTION, false);
bool generalEmbeedNotSpecified = props.getBooleanGeneralProperty(Const.EMBEED_NOT_SPECIFIED_SECTION, false);
return generalEmbeedFont && props.getBooleanProperty(Const.EMBEED_SECTION, fontName, generalEmbeedNotSpecified);
if (IsPdfA())
return true;
else
{
bool generalEmbeedFont = props.getBooleanGeneralProperty(Const.EMBEED_SECTION, false);
bool generalEmbeedNotSpecified = props.getBooleanGeneralProperty(Const.EMBEED_NOT_SPECIFIED_SECTION, false);
return generalEmbeedFont && props.getBooleanProperty(Const.EMBEED_SECTION, fontName, generalEmbeedNotSpecified);
}
}

public virtual void setAsianFont(String fontName, String style)
Expand Down Expand Up @@ -684,6 +697,17 @@ public virtual void GxEndDocument()
{


}
protected Stream ReadResource(string fileName)
{
Assembly assembly = GetType().Assembly;
string resourcePath = $"{assembly.GetName().Name}.{fileName}";
return assembly.GetManifestResourceStream(resourcePath);
}

protected bool IsPdfA()
{
return complianceLevel != 0;
}

public void GxEndPrinter()
Expand Down Expand Up @@ -873,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
Expand Down Expand Up @@ -1326,7 +1351,8 @@ 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
public static String PRINTER = "Printer";
Expand Down Expand Up @@ -1816,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
}
}

50 changes: 49 additions & 1 deletion dotnet/src/dotnetframework/GxPdfReportsCS/PDFReportItext4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Reflection;
using GeneXus.Metadata;
using com.genexus.reports;
using GeneXus.Configuration;

namespace com.genexus.reports
{
Expand Down Expand Up @@ -73,6 +74,13 @@ protected override void init(ref int gxYPage, ref int gxXPage, int pageWidth, in
try
{
writer = PdfWriter.GetInstance(document, outputStream);
string level = props.getGeneralProperty(Const.COMPLIANCE_LEVEL);
if (Enum.TryParse(level, true, out complianceLevel))
{
if (SetComplainceLevel(complianceLevel))
writer.SetTagged();
}

}
catch (DocumentException de)
{
Expand Down Expand Up @@ -467,6 +475,7 @@ public override void GxDrawBitMap(String bitmap, int left, int top, int right, i
image.ScaleToFit(rightAux - leftAux, bottomAux - topAux);

PdfContentByte cb = writer.DirectContent;
image.Alt = Path.GetFileName(bitmap);
cb.AddImage(image);
}
}
Expand Down Expand Up @@ -645,9 +654,17 @@ public override void GxAttris(String fontName, int fontSize, bool fontBold, bool
baseFont = CreateDefaultFont();
}
}
BaseFont defaultFont;
private BaseFont CreateDefaultFont()
{
return BaseFont.CreateFont("Helvetica", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
if (defaultFont == null)
{
if (IsPdfA())
defaultFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
else
defaultFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
return defaultFont;
}
private void LoadAsianFontsDll()
{
Expand Down Expand Up @@ -1384,6 +1401,22 @@ public override void GxEndDocument()
}

}
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();

Expand Down Expand Up @@ -1499,6 +1532,21 @@ private void SetSimpleColumn(ColumnText col, Rectangle rect)
{
col.SetSimpleColumn(rect.Left, rect.Bottom, rect.Right, rect.Top);
}

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;
}
}
}

}

0 comments on commit 404a2f9

Please sign in to comment.