string[] aDataSet = { "ADVANCE GROUPAMA", "00030007637016103000", "Dr. Dias Neto", "17339",
"Regina Maria da Silva Deus Conde", "pelo Arquivo de", "a", "portadora", "esta",
"Bilhete de Identidade", "123456", "London", "04/04/2022", "25", "four",
"April", "2022", "dois", "dois", "Rua de Nampula 34 3 D", "Portugal",
"Disease", "Care message that we should have with the patient", "Windsor" };
string[] aFieldNames = { "Acordo", "Beneficiario", "Medico", "Cedula",
"NomeUtente", "Origem", "Genero", "Portador", "Este",
"TipoDocumento", "BI", "Arquivo", "ValidadeBI", "Dia", "ExtensoDia",
"Mes", "Ano", "Dias", "ExtensoDias", "Morada", "Naturalidade",
"Doenca", "Cuidados", "LocalEmissao" };
document.MailMerge.Execute(fieldNames, fieldValues);
FileStream fileOutputStreamPath = new FileStream(sOutputWord, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
document.Save(fileOutputStreamPath, FormatType.Docx);
document.Close();
sOutputWord = @"C:\NewProjects\Clinicasoft\ClinicaSoft.Web\wwwroot\Medical_Documents\\Certificates\Certificate_a_1.docx";
sOutputPDF = @"C:\NewProjects\Clinicasoft\ClinicaSoft.Web\wwwroot\Medical_Documents\\Certificates\Certificate_a_1.pdf";
GeneratePDF_FromDocx(sOutputWord, sOutputPDF);
.....
private bool GeneratePDF_FromDocx(string docWord, string docWordPDF)
{
try
{
FileStream fileStreamPath = new FileStream(docWord, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
// **** Error in next line ****
WordDocument wordDocument = new WordDocument(fileStreamPath, FormatType.Docx);
// Sets page size as A5 for each sections.
foreach (IWSection iWSection in wordDocument.Sections)
iWSection.PageSetup.PageSize = Syncfusion.DocIO.DLS.PageSize.A5;
DocIORenderer render = new DocIORenderer();
//Sets Chart rendering Options.
render.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Jpeg;
//Converts Word document into PDF document
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
//Releases all resources used by the Word document and DocIO Renderer objects
render.Dispose();
wordDocument.Dispose();
//Saves the PDF file
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object
pdfDocument.Close();
//Process.Start(docWordPDF);
pdfDocument.Close(true);
wordDocument.Close();
if (wordDocument != null)
{
wordDocument = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
return true;
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
The text of the document, after translation would look something like this:
"Doctor Name, physician, with Professional Certificate no. 17339,
attests for his Professional Honor that Patient Name,
holder of Identity Card No. 123456, passed by the London Archives,
valid until 04/04/2022, is unable to attend the service from the 4th (four) of April 2022,
and for a probable period of two (two) days, due to Disease disease,
which requires urgent, indispensable and permanent Care message
that we should have with the patient."
Word document (dotx) attached.
I would appreciate your help, I have many similar documents to generate.
Regards,
Fausto