gpt4 book ai didi

javascript - JSPDF 保存在本地系统上,但我想将它保存在服务器上

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:49 26 4
gpt4 key购买 nike

我正在使用 JSPDF 保存 PDF 文件。我得到了这个,但下一个任务是将我的 PDF 保存在服务器文件夹中,而不是在我的本地计算机上。我的功能是:

function generatePDFFile(elem) {
var date = new Date();
var filename = date.getUTCDate()+date.getTime();
const el = document.querySelector('#divInvoiceDLG')
el.scrollIntoView()
$(el).css("overflow", "hidden");
html2canvas(el, {
useCORS: true,
allowTaint: true,
letterRendering: true,
logging: true,
onrendered: function (canvas) {


var quality = [0.0, 1.0];
var img = canvas.toDataURL("img/png",quality);
var doc1 = new jsPDF();
doc1.addImage(img, "JPEG", 1, 1);
doc1.save( filename);
},
});
}

最佳答案

我可以用 C# 代码做到这一点。

%@ WebHandler Language="C#" Class="Attachments" %>

using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

public class Attachments : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
try
{
HttpPostedFile postedFile = context.Request.Files[0];
string PracticeId = HttpContext.Current.Profile.GetPropertyValue("PracticeId").ToString();
string directory = HttpContext.Current.Request.Form["Directory"];

Guid newGuid = Guid.NewGuid();
string savepath = context.Server.MapPath(ConfigurationManager.AppSettings["DocumentsPath"] + "/" + PracticeId + "/" + directory);

if (!Directory.Exists(savepath))
{
Directory.CreateDirectory(savepath);
}
string filename = newGuid + "." + postedFile.FileName.Split('.').Last();
postedFile.SaveAs(savepath + @"\" + filename);

ResponseFile objResponse = new ResponseFile
{
path = newGuid + "." + filename.Split('.').Last(),
fileName = postedFile.FileName
};

var jSon = new JavaScriptSerializer();
var outPut = jSon.Serialize(objResponse);
context.Response.Write(outPut);
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
}

public bool IsReusable {
get {
return false;
}
}

}

关于javascript - JSPDF 保存在本地系统上,但我想将它保存在服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47867930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com