I am getting a corrupted pdf being sent.
The pdf renders on screen in the viewer properly. If I manually encode the saved rendered report (pdf) as Base64 , hard code it in the JSON message base64Content and send it to the mail server, it attaches correctly.
However, when I try to encode the quote programmatically, I am getting a corrupted pdf. Console Logging the base64data output and comparing it to the same report base64 are different.
I have an onEmailReport which calls sendMail function
Code: Select all
viewer.onEmailReport = () => sendEmail(viewer);
async function sendEmail(viewer) {
const report = viewer.report
console.log(report)
// Export report as PDF
const pdf = report.exportDocument(Stimulsoft.Report.StiExportFormat.Pdf);
// Convert to Base64 string
const base64data = btoa(pdf)
console.log(base64data );
const data = {
"Messages": [
{
"From": {
"Email": "ron@demomail.com",
"Name": "Ronald "
},
"To": [
{
"Email": "doghousedev@demomail.com",
"Name": "Rogue "
}
],
"Subject": "Email PDF Quote Testing!",
"TextPart": "Dear customer find attached quote",
"HTMLPart": "<h3>Dear Rogue , Here us you quote!",
"Attachments": [
{
"ContentType": "application/pdf",
"Filename": "quote.pdf",
"Base64Content": base64data
}
]
}
]
};
// Send the email
try {
const response = await fetch('MY SERVER.COM', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) throw new Error('Email sending failed');
const responseData = await response.json();
console.log("Response Data:", responseData);
// Handle success here
} catch (error) {
console.error('Error:', error);
// Handle error here
}
};