MigraDoc Through the Back Door
MigraDoc documents can persist in
MigraDoc DDL files. Those MDDDL files are text files.
Any application that can write text files can also write MDDDL files. After creating the file, you just have to invoke an EXE file that uses MigraDoc to turn the MDDDL file into a PDF file (or RTF file).
Sample MDDDL File
Here is a simple MDDDL sample, displaying the text "Hello, World!":
\document
{
\section
{
\paragraph
{
Hello, World!
}
}
}
You can refine this sample as needed, adding attributes to document, section, or paragraph. Or by defining styles.
MDDDL does not require line breaks or indentation. Indentation makes it easier for humans to read the file, maintain it, and find errors.
Developing MDDDL Files
To get started, you can use the Document Viewer sample that comes with the PDFsharp/MigraDoc samples.
With this sample you can open MDDDL files and see them in a window. You can create PDF files as needed.
The Document Viewer allows you to test MDDDL files created with your application quickly and easily.
Using MDDDL Files
Finally you have to create a console application with .NET that gets an MDDDL file as a command-line parameter and creates a PDF file from it.
If your application can invoke EXE files created with .NET, then that is all you need. Otherwise you may have to create a web service that receives the MDDDL via HTTPS and returns a PDF file. Or a server application in your LAN that periodically checks an INPUT folder on a server and writes the PDF file to an OUTPUT folder.
A Sample "Application"
Here is a sample batch file that lists all the files in a directory and writes their names into an MDDDL file. It would be easy to invoke the EXE file to create a PDF file at the same time. To keep the sample short, it creates an MDDDL file without indentation.
set MDDDLfile=dirlist.mdddl
echo \document{\section{ >%MDDDLfile%
for /F %%f in ('dir/b') do echo \paragraph{%%f} >>%MDDDLfile%
echo }} >>%MDDDLfile%
Listing the files in the current folder is not really useful. The sample does not use any formatting or advanced PDF features. But it shows that batch files can create MDDDL. You can use it to create nicer log files from batch files.
If batch files can use, then other, more advanced programming environments can use it even better.