如何将图像(以字节为单位)转换为没有物理路径的PDF [英] How to convert image (in bytes) to PDF without physical path

查看:79
本文介绍了如何将图像(以字节为单位)转换为没有物理路径的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将图像文件(转换为字节)转换为pdf文件,而不需要物理路径。我正在使用ABCPDF。请帮忙。下面是我当前的代码,但它需要有一个物理路径转换为PDF。



string image = @C:\ Users\osmtft\Desktop\Teemee\NSO_ReportOfBirth2013_h800.jpg;

param.ImageData = System.IO.File.ReadAllBytes(image);



MemoryStream ms2 = new MemoryStream();

ms2.Write (param.ImageData,0,param.ImageData.Length);



XImage theImg = new XImage();

theImg.SetData( param.ImageData);



Doc theDoc = new Doc();

theDoc.MediaBox.String = theImg.BoundingBox.String;

theDoc.Rect.String = theDoc.MediaBox.String;

theDoc.AddImageObject(theImg,false);

theDoc.Save(ms2) ;



Doc theDoc2 = new Doc();

theDoc2.Read(theDoc.GetData());

// theDoc2.Save(newFilename);



imageBytes = theDoc2.GetData();



Doc theDoc3 = new Doc();

theDoc3.Read(theDoc.GetData());

theDoc3.Save(@C:\ Users \ osmtft \ Desktop\Teemee \helloXXX.pdf);



我尝试过:



我试过在ABCPDF文档中搜索任何方法。但无济于事。

I am required to convert image files (converted to bytes) into a pdf file without having a physical path. I am using ABCPDF. Please help. Below is my current code but it requires to have a physical path to be converted into PDF.

string image = @"C:\Users\osmtft\Desktop\Teemee\NSO_ReportOfBirth2013_h800.jpg";
param.ImageData = System.IO.File.ReadAllBytes(image);

MemoryStream ms2 = new MemoryStream();
ms2.Write(param.ImageData, 0, param.ImageData.Length);

XImage theImg = new XImage();
theImg.SetData(param.ImageData);

Doc theDoc = new Doc();
theDoc.MediaBox.String = theImg.BoundingBox.String;
theDoc.Rect.String = theDoc.MediaBox.String;
theDoc.AddImageObject(theImg, false);
theDoc.Save(ms2);

Doc theDoc2 = new Doc();
theDoc2.Read(theDoc.GetData());
//theDoc2.Save(newFilename);

imageBytes = theDoc2.GetData();

Doc theDoc3 = new Doc();
theDoc3.Read(theDoc.GetData());
theDoc3.Save(@"C:\Users\osmtft\Desktop\Teemee\helloXXX.pdf");

What I have tried:

I have tried searching for any methods in the ABCPDF documentation. But to no avail.

推荐答案

这取决于以后生成的PDF的使用位置。



如果您不想保存PDF,请使用 Doc GetData函数。将文档保存到内存。 ABCpdf.NET PDF库。 [ ^ ]。返回的字节数组包含原始PDF数据(与写入文件时相同的数据)。在您的应用程序中使用它,例如使用剪贴板将其传递给其他应用程序,或通过网络发送。
It depends on where the generated PDF should be used later.

If you don't want to save the PDF, use the Doc GetData Function. Saves a document to memory. ABCpdf.NET PDF Library.[^]. The returned byte array contains the raw PDF data (same data as when written to a file). Use it within your application, pass it to other applications using the clipboard for example, or send it via network.


这篇关于如何将图像(以字节为单位)转换为没有物理路径的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆