DSL iText Java generation code
Hello.
I am a newbie to Jetbrains MPS and I am wondering how to use classes from e.g java.io package inside my generator. Additionally, I want to use classes from iText inside of the generated class (because Editor2Pdf plugin seems not to be working anymore). How to do it, should I extend the Java language provided?
Here is the java code I want to achieve with the editor I have so far:
```
public class PdfGenerator {
public static final String DEST = "results/chapter01/hello_world.pdf";
public static void main(String args[]) throws IOException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new PdfGenerator().createPdf(DEST);
}
public void createPdf(String dest) throws IOException {
//Initialize PDF writer
PdfWriter writer = new PdfWriter(dest);
//Initialize PDF document
PdfDocument pdf = new PdfDocument(writer);
// Initialize document
Document document = new Document(pdf);
//Add paragraph to the document
document.add(new Paragraph("Hello World!"));
//Close document
document.close();
}
}
// MPS generator
root template
input TreatmentDocument
public class map_TreatmentDocument {
public static final String DEST = "results/chapter01/hello_world.pdf";
public static void main(string[] args) {
}
public void createPdf(String dest) {
<no statements>
}
}
Please sign in to leave a comment.
Hello,
for java.io you have to import the model into the generator model.
For a custom jar, you first have to make it part of your project by creating a runtime solution with that jar and then import it into the generator, as well (https://www.jetbrains.com/help/mps/2021.1/getting-the-dependencies-right.html#addingexternaljavaclassesandjarstoaproject-runtimesolutions).
Vaclav Pech thanks! Additional question - is it possible to generate e.g Ruby code?
Yes. There is no MPS implementation of Ruby, so you should target the plainTextGen language with your generator - https://plugins.jetbrains.com/plugin/8444-com-dslfoundry-plaintextgen