Я получаю это предупреждение всякий раз, когда запускаю загрузку PDF. В этом предупреждении, похоже, нет никаких негативов, но я хотел бы знать, почему Google Chrome уведомляет меня об этом. Я попытался добавить явный заголовок ответа и длину содержимого, но безрезультатно.
export: function () {
_stage.toDataURL(function (dataURL) {
//POST the data because dataURL is too large to pass using a GET.
$.post('../PlanView/GeneratePDF', { DataURL: dataURL }, function (imageURL) { location.href = imageURL; });
});
}
[CompressionFilterAttribute]
public string GeneratePDF(string dataURL)
{
dataURL = Regex.Replace(dataURL, "^data:image/(png|jpg);base64,", string.Empty);
byte[] imageBytes = Convert.FromBase64String(dataURL);
System.Drawing.Image image;
using (MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
memoryStream.Write(imageBytes, 0, imageBytes.Length);
image = System.Drawing.Image.FromStream(memoryStream, true);
}
Document document;
float maxHeight;
float maxWidth;
if (image.Height > image.Width)
{
document = new Document(PageSize.A4);
maxHeight = PageSize.A4.Height - (document.TopMargin + document.BottomMargin);
maxWidth = PageSize.A4.Width - (document.LeftMargin + document.RightMargin);
}
else
{
document = new Document(PageSize.A4.Rotate());
maxHeight = PageSize.A4.Width - (document.LeftMargin + document.RightMargin);
maxWidth = PageSize.A4.Height - (document.TopMargin + document.BottomMargin);
}
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter.GetInstance(document, memoryStream);
document.Open();
iTextSharp.text.Image planViewImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Png);
///894604/izmenit-razmer-izobrazheniya-chtoby-ono-pomestilos-v-ogranichitelnoi-ramke
//Find the scaling factor by determining which is smaller: MaxWidth/w or MaxHeight/h, then multiply w and h by that number.
float scale = (maxHeight / image.Height < maxWidth / image.Width) ? (maxHeight / image.Height) : (maxWidth / image.Width);
planViewImage.ScalePercent(scale * 100);
document.Add(planViewImage);
document.Close();
//Store the image in a buffer because its hard to download an image during POST.
Session["PlanViewPDF"] = memoryStream.ToArray();
}
//Return URL to another MVC URL which can GET the image.
return "../PlanView/ExportPDF";
}
[CompressionFilterAttribute]
public ActionResult ExportPDF()
{
byte[] buffer = Session["PlanViewPDF"] as byte[];
Response.Headers.Add("Content-Type", "application/pdf");
Response.AddHeader("Content-Length", buffer.Length.ToString());
return File(buffer, "application/pdf", string.Format("Plan View {0:yyyy-MM-dd_hh-mm-ss-tt}.pdf", DateTime.Now));
}