1
votes

I have a lot of instructions to print a text file using the PrintDocument class of .NET. You can pretend my code is this -> https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2. In that code you see only a DrawString image, but I have a lot of instructions since the document is more complex.

I want to convert my text file to PDF so I chose PDFsharp (I like their MIT license since it's for a commercial product).

Now I can't figure out how to modify my code to use PDFsharp. I don't want to use their "X" Classes (XFont, XSize, ...) since I need to replace all the occurrences in my big source code. If sometimes in the future I want to change PDFsharp for something else, I don't want to rewrite my source code because they have "ABC" Class (ABCFont, ABCSize,...).

Neither I want 2 methods of printing: PrintWithDotNet and PrintWithPdfSharp with all the code nearly the same (new Font vs new XFont, ...). It would be a debug nightmare.

I prefer not to write adapters or make use of bridge pattern: too much classes to create.

It seems strange that PDFsharp's developer didn't think of an easy way to pass from standard .NET printing to PDFsharp printing... or I have not found it?

Thanks in advance for your suggestions.

1

1 Answers

1
votes

The PDFsharp developers are open for suggestions how it can be done better.

What you can do now: use the X-classes for both PDF and for .NET printing. That's how it is meant to be used as it is now.

You have to change your code once, adding many Xs everywhere, but you keep a single code base.