0
Asposeを使用してBMPをPDFにレンダリングしてダウンロードする必要があります。ASP.NET Aspose PDF with embedded BMP
ダウンロードしたPDFが破損していて、Adobeが開きません。ファイルに保存されたPDFは問題ありません。ダウンロードのPDFが壊れている理由を知っている人は誰ですか?
protected void ASPxButton1_OnClick(object sender, EventArgs e)
{
WebsiteToImage websiteToImage = new WebsiteToImage(HttpContext.Current.Request.Url.AbsoluteUri, @"C:\Temp\Test.jpg");
var generate = websiteToImage.Generate();
// Create a MemoryStream object from image Byte array
MemoryStream ms = new MemoryStream();
websiteToImage.Bitmap.Save(ms, ImageFormat.Jpeg);
// create a PDF object
Pdf pdf = new Pdf();
// create a section and add it to pdf document
Aspose.Pdf.Generator.Section MainSection = pdf.Sections.Add();
//Add the radio form field to the paragraphs collection of the section
// create an image object
Aspose.Pdf.Generator.Image sample_image = new Aspose.Pdf.Generator.Image();
// specify the image file path information
//sample_image.ImageInfo.File = @"d:/pdftest/untitled.bmp";
sample_image.ImageInfo.ImageStream = ms;
// specify the image file type
sample_image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
// specify the image width information equal to page width
sample_image.ImageInfo.FixWidth = MainSection.PageInfo.PageWidth - MainSection.PageInfo.Margin.Left - MainSection.PageInfo.Margin.Right;
// specify the image Height information equal to page Height
sample_image.ImageInfo.FixWidth = MainSection.PageInfo.PageHeight - MainSection.PageInfo.Margin.Top - MainSection.PageInfo.Margin.Bottom;
// create bitmap image object to load image information
Bitmap myimage = websiteToImage.Bitmap;
// check if the width of the image file is greater than Page width or not
if (myimage.Width > MainSection.PageInfo.PageWidth)
// if the Image width is greater than page width, then set the page orientation to Landscape
MainSection.IsLandscape = true;
else
// if the Image width is less than page width, then set the page orientation to Portrait
MainSection.IsLandscape = false;
// add image to paragraphs collection of section
MainSection.Paragraphs.Add(sample_image);
// save the resultant PDF
pdf.Save(@"C:\Temp\Test.pdf");
pdf.Save(ms);
byte[] bytes = ms.GetBuffer();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + Operator.Emplid + "Gudiance.pdf");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();
ms.Close();