"Conversion" of NetCode to 4GL | PdfSharp

balta

Member
Hi,

I am trying to use PDFsharp in 4gl and I am having difficulties converting code to to 4gl.


Anyone have an example or can help in converting this code?

At this moment I have difficult in xFontStyle and DrawString.

Code:
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";

// Create an empty page
PdfPage page = document.AddPage();

// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);

// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height),
  XStringFormats.Center);

// Save the document...
const string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);

OpenEdge 12.2.12 | Windows 11

Baltazar
 
What have you tried? What does you attempted translation of that code look like? And what is the nature of the "difficulties" that you are experiencing?
 

Port existing PDFsharp projects to
PDFsharp 6​

Version 6.1.0

In this article

This article describes how to upgrade your existing PDFsharp 1.x projects to PDFsharp 6.

Upgrade existing code​

Upgrading an existing PDFsharp project is described in Upgrade existing projects to PDFsharp 6.

Breaking changes​

PDFsharp Library 6 is the successor of PDFsharp 1.5. It has the following breaking changes.

  • The class XFontStyle is renamed to XFontStyleEx
  • The Core build now has no dependencies on the System.Drawing namespace anymore. If your code relies on functionality of GDI+ use the PDFsharp GDI+ build.
  • Some of the implicit conversions in XUnit became obsolete because they led to misunderstandings and unexpected behavior. Consider initiating XUnit passing the desired unit type or use the new XUnitPt class instead to deal with point values and benefit from implicit conversions and value conversions.
 
What have you tried? What does you attempted translation of that code look like? And what is the nature of the "difficulties" that you are experiencing?
Hi Tom.

I have the code in .NET to generate the PDF (tested successful in Visual Studio), the difficult is to "convert" the NET code to 4GL Code.

I am "stuck" in this code. Give this error. (messages are in Portuguese)

1722586542570.png

Code:
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height),
  XStringFormats.Center);
 
So you are simply trying to copy & paste the C# code into an OpenEdge editor?

Do you have any OpenEdge experience at all? Or are we starting from scratch?
 
So you are simply trying to copy & paste the C# code into an OpenEdge editor?

Do you have any OpenEdge experience at all? Or are we starting from scratch?
Yes and no. I am do a copy paste and convert line by line.

Yes, a lot of experience in OE "native", in NET learning a lot. I have been able to use other DLL net libraries but in that 2 lines that I refer I having difficulties to convert the NET code to OE Code.
 
Can you show us your ABL code including any "using" statements, plus the assemblies you are using.

I trying to get experiment with PDFSharp too, but Visual Studio is not showing the nested namespaces.
 
However, I'm having trouble in getting the PDFSharp assemblies to load correctly, so I can't help fully.
I can't see the namespaces or classes. So, this is all guess work.

1722824196824.png

In theory this code should work in the Progress Developer Studio.

C#:
using System.*.
using System.Diagnostics.*.
using PdfSharp.*.
using PdfSharp.Drawing.*.
using PdfSharp.Pdf.*.

BLOCK-LEVEL ON ERROR UNDO, THROW.

DEFINE VARIABLE pdfDocObj  as class PdfDocument NO-UNDO.
DEFINE VARIABLE pdfPageObj as class PdfPage     NO-UNDO.
DEFINE VARIABLE gfxObj     AS class XGraphics   NO-UNDO.
DEFINE VARIABLE xFontObj   AS class XFont       NO-UNDO.

// Create a new PDF document
pdfDocObj = new PdfDocument().
pdfDocObj.Info:Title = "Created by OpenEdge".

// Create an empty page
pdfPageObj = pdfDocObj:AddPage().

// Get an XGraphics object for drawing
gfxObj = XGraphics:FromPdfPage(pdfPageObj).

xFontObj = new XFont("Verdana", 20, XFontStyle:BoldItalic).

// Draw the text
gfxObj:DrawString("Hello, World!", xFontObj XBrushes:Black,
                new XRect(0, 0, pdfPageObj:Width, pdfPageObj:Height),
                XStringFormats:Center);
               
pdfDocObj:Save("HelloWorld.pdf");
 
Last edited:
Back
Top