We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to convert file to memory in Aspose.Pdf Product Family?

In my situation, I converted PDF to BMP and then converted BMP to PDF in C#. All of this has been output to the file. By the way, I want to be the input file first, the memory in the middle, and the output file at the end. Especially, can memory support be provided by Aspose? I wonder if I should do otherwise.
Blue color is a input file and a output file. Red color is that I want to process it as memory instead of files.
Here is an example.
AsposeMemory.png (36.4 KB)

@YoungLEE

Thanks for contacting support.

Please check following code snippet in order to export image file into memory stream object and add same image into another PDF from stream object.

Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + @"input.pdf");

var resolution = new Aspose.Pdf.Devices.Resolution(100);
var bmpDevice = new Aspose.Pdf.Devices.BmpDevice(resolution);

// Export image file to stream
MemoryStream bmpStream = new MemoryStream();
bmpDevice.Process(document.Pages[1], bmpStream);


Document doc = new Document();
Page currpage = doc.Pages.Add();
Image img = new Image();
img.ImageStream = bmpStream;
img.ImageScale = 1;
currpage.PageInfo.Margin.Top = currpage.PageInfo.Margin.Bottom = currpage.PageInfo.Margin.Right = currpage.PageInfo.Margin.Left = 0;
currpage.Paragraphs.Add(img);

doc.Save(dataDir + "output.pdf");

Furthermore, you can notice that I did not use Aspose.Pdf.Generator approach in order to implement the required functionality, as old Aspose.Pdf.Generator approach has been deprecated in new version of the API and we strongly recommend to use new Aspose.Pdf (DOM) model.

Please try updating to latest release Aspose.Pdf for .NET 17.6 and to use new DOM model, please refer to “Working with Aspose.Pdf” section in our API documentation. In case of any further assistance, please feel free to contact us.


Best Regards,
Asad Ali

@asad.ali

Thank you so much for your detailed answer.
In your code, I found that memory processing is done by per-page memory streaming. I did not know that ago.
I modified the code and it works fine. Also Thank you so much for giving me good information. I am studying latest Aspose.PDF 17.6… I could do anything in case of any further assistance.
Thank you so much again.

@YoungLEE

Thanks for your feedback.

It is good to know that your requirement has been fulfilled by suggested approach. Please keep using our API and in event of any further query, please feel free to contact us.


Best Regards,
Asad Ali

         Dear asad.ali 
          Thank you for your answer.
           Could I ask a question? While coding, I have a problem. I added your reference last time. By the way,
           This (Image img = new Image ();  ) was created an error.
           An error message was 'Image' is an ambiguous reference between 'System.Drawing.Image' and 
           'Aspose.Pdf.Generator.Image'.
          So I did in case of 'System.Drawing.Image' and 'Aspose.Pdf.Generator.Image'. But it continues an error.
          I don't know what causes. Please tell me what causes.

          Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
           Page currpage = doc.Pages.Add();
           Image img = new Image();
            img. = bmpStream;
            img.ImageScale = 1;

@YoungLEE

Thanks for contacting support.

The Image class can be accessed by including reference to Aspose.Pdf namespace or you can use it with full name like Aspose.Pdf.Image. As shared earlier, I am afraid that you are using quite old version of the API and Aspose.Pdf.Generator approach, which has been declared deprecated in latest version of the API.

We recommend you to update the version of the API and use DOM (Document Object Model) approach in order to implement API features. In case if you still face any issue in using latest version, please let us know. We will try to assist you accordingly.


Best Regards,
Asad Ali

Dear asad.ali

Thank you for your answer.
My API is Aspose.Total for dotNET. I bought it on 3 2017.

I think that this version is the latest. If it wouldn’t work, I will update the version as you answered.
I input the namespace Aspose.Pdf.Image and then it does well. Thank you so much.