我有一个图像字节数组想要转换为PDF字节数组。
我浏览了该文档,并以完全相同的方式实施了该文档。
我想使用Aspose.pdf v19将图像字节数组动态转换为PDF
https://docs.aspose.com/display/pdfnet/Convert+PDF+Pages#ConvertPDFPages-ConvertanImagetoPDF
Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.Pages.Add();
// Load the source image file to Stream object
MemoryStream outstream = new MemoryStream();
MemoryStream mystream = new MemoryStream(tmpBytes);
// Instantiate BitMap object with loaded image stream
Bitmap b = new Bitmap(mystream);
// Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);
// Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
// Set the image file stream
image1.ImageStream = mystream;
// Save resultant PDF file
doc.Save(outstream ,SaveFormat.Pdf);
// Close memoryStream object
mystream.Close(); ```
我得到一个错误:
参数无效
用加载的图像流实例化BitMap对象时。
我尝试执行此代码,它与MVC兼容,但在Aspose.pdf 10.0.0中不适用于ASP.net
var pdfFile = new MemoryStream(imageFile);
Aspose.Pdf.Generator.Pdf pdfFilePdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section pdfSection = pdfFilePdf.Sections.Add();
Aspose.Pdf.Generator.Image objImage = new Aspose.Pdf.Generator.Image(pdfSection);
pdfSection.Paragraphs.Add(objImage);
objImage.ImageInfo.ImageStream = new MemoryStream(imageFile);
pdfFilePdf.Save(pdfFile);
return pdfFile.ToArray();
但是这里我也有一个错误:
参数在
pdfFilePdf.Save(pdfFile)
无效