You have "filename" first and then "filesname" second.
I don't find any definition for "doc" in this line of code.
MIMEEntity m = doc.createMIMEEntity("Files");
When you add the template into the blank PDF the code looks like this:
cb.addTemplate(page, 0, 0);
I'm guessing the "0,0" is the coordinates of where to add the template page. The code to add the new paragraph looks like this:
//Now do the usual addition of text atop the template
new Paragraph("Here some text added to the template")
But this codes has no coordinates. How do you know where it's going to land on the PDF page?
In fact the relationship between these variables is confusing:
"document" appears to be a Notes document;
"writer" a PdfWriter associated with "document";
"os" a ByteArrayOutputStream associates with "writer";
"cb" a PdfContentByte seems to be a temp to hold template page but I never see it used again once written to.
I guess they are all different ways to write to the same document.
Is "document" a Notes document?
It appears that "os" is only used when creating the final attached PDF while "writer" gets used in creating the PDF.
Well, I'm stopping right here because I'm not where I can access the documentation that might clear up some of my questions. Clearly you've put a lot of work into figuring out how to do this and I know it's asking a lot, but please consider could walking us through the convoluted transformations happening in this code.