I need to capture a multi page form in pdf format and then save it to the server with the record and not to the client. This is the code I wrote that send it to the client, how can I modify it to send it to the server instead
root.options.set("pdf", {
multiPage: 'true'
});
$('#formContainer .appPage').each(function (section) {
kendo.drawing.drawDOM(this).then(function (group) {
group.options.set("pdf", {
margin: {
left: "1cm",
right: "1cm",
top: "1cm",
bottom: "1cm"
}
});
root.append(group);
});
});
kendo.drawing.pdf.saveAs(root, "App.pdf");
10 Answers, 1 is accepted
Saving the files on the server is not supported out of the box, since Kendo UI is a client-side library. You can achieve the desired results by posting the dataURI to the server via Ajax request, then storing it there, either as a file or as a dataURI string.
Regards,
Alexander Popov
Telerik
Hi,
do you have a rough example of this method?
Thanks
posting went well.
$.ajax({
type: "POST",
url: "/home/pdfpost",
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
data: '{ "imageData" : "' + data + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
});
the problem is creating the pdf file from the datauri in the controller. any clues how to do that?
As mentioned previously, creating a PDF file on the server is not supported as Kendo UI is a client-side library. You could however, use third-party libraries that do that. Here is an example that you might find helpful:
Regards,
Alexander Popov
Telerik
found a way to do it..
kendo.drawing.drawDOM($(
".pdf-content"
))
.then(
function
(group) {
// Render the result as a PDF file
return
kendo.drawing.exportPDF(group, {
paperSize:
"auto"
,
margin: { left:
"1cm"
, top:
"1cm"
, right:
"1cm"
, bottom:
"1cm"
}
});
})
.done(
function
(data) {
$.ajax({
type:
"POST"
,
url: publish +
"/home/pdfpost"
,
processData:
false
,
// tell jQuery not to process the data
contentType:
false
,
// tell jQuery not to set contentType
data:
'{ "imageData" : "'
+ data +
'" ,"id": "'
+ self.customerGuid() +
'"}'
,
contentType:
'application/json; charset=utf-8'
,
dataType:
'json'
,
});
});
// controller (MVC)
imageData = imageData.Replace(
"data:application/pdf;base64,"
,
""
);
byte
[] bytes = Convert.FromBase64String(imageData);
Stream stream =
new
MemoryStream(bytes);
EmailMessage email =
new
EmailMessage(service);
email.Attachments.AddFileAttachment(
"SALOR.pdf"
,stream);
i have problem save pdf server side but in local easy save pdf plz help me save pdf server side
{
done(function (dataURI) {
kendo.saveAs({
dataURI: dataURI,
fileName: "test.pdf",
proxyURL: "/path/to/proxy",
forceProxy: true
});
});
This function is used server side save pdf but it is can't working plz help me save the pdf server side plz send me with example
I am not sure I understand your question very well. Saving PDF files on the server is not supported, as Kendo UI is a client-side library and as such it does not have server-side part and filesystem handling capabilities.
Regards,
Alexander Popov
Telerik by Progress
As noted by my colleague, saving PDF files on the server is not supported by Kendo UI, as it is a client-side library. Thus, it does not provide filesystem handling. It would be beneficial for the community, if Wyatt could share their solution.
Apart from Kendo UI, Telerik UI for ASP.NET MVC provides integration with Telerik Document Processing Library, which is capable of server-side operations. The following demos show PdfProcessing in action. And PdfProcessing documentation can be found here.
Regards,
Dimitar
Progress Telerik
Mission accomplished: Generate pdf and send to the server instead of the client.
Using Asp.net core webapi
1. Create a html page in wwwroot folder.
2. Load kendogrid using jQuery.
3. Next, from any controller or c# class , call this url and convert html page as string and pdf using some url to pdf library.
4. Save file to folder
5. Using C# Mail class, send it as attachment.