Click here to Skip to main content
15,913,279 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 21-Jun-18 0:09am
Comments
Richard MacCutchan 21-Jun-18 3:36am    
Then you need to do what the application requires.
F-ES Sitecore 21-Jun-18 5:29am    
Which path are you trying to eliminate? The path to the original image or the path to the resulting PDF?
TeemeeT 21-Jun-18 7:41am    
I need to eliminate the physical path to the resulting PDF while converting the image to PDF. After conversion, I will upload the PDF file to a http file server. Our application is deployed in azure. Is there any way to use a physical path for processing while an application is deployed in azure?

1 solution

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.
 
Share this answer
 
Comments
TeemeeT 21-Jun-18 7:56am    
I need to eliminate the physical path to the resulting PDF while converting the image to PDF. After conversion, I will upload the PDF file to a http file server. Our application is deployed in azure. Is there any way to use a physical path for processing while an application is deployed in azure?
Jochen Arndt 21-Jun-18 8:31am    
Just use the raw data for uploading to the server (they are required anyway by that task). If that is done by a different application, you have to pass the data to that application. If using a physical file for passing is not an option, you have to use a different method. But I don't know your setup and don't know therefore which methods can be used.

[EDIT]
To make it more clear:
Just don't call the Save() function but use the byte array returned by GetData() instead.

The Save() function does nothing more than creating the file and writing the raw data to it.
[/EDIT]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900