Converting any image to PDF/A by using Aspose.Imaging

As I see PdfOptions class of the Aspose.Imaging library, is very poor. There is almost no custom settings.


For example; PDF format types (pdf -pdf/aversions ), quality, etc.

I also see that Aspose.PDF converts images to the PDF but it only create a shape into an empty pdf file and save as as pdf

(http://www.aspose.com/docs/display/pdfnet/Working+with+Images+%28Generator%29)

What do you suggess me?

Hi Ertan,

Thank you for your inquiry.

Please forward us your complete requirement. What you want to do? What type of PDF you want to generate? How the image should be after conversion? Share any sample of input & output with us, if possible. We will look into it and update you accordingly.

Hello, Thank you for your reply.


For example, i wrote a code for Aspose.Imaging like

             _image = Image.Load(originalFileContent.ConvertToMemoryStream());
var options = new PdfOptions();
          <span style="color:blue;">var</span> outStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();

          _image.Save(outStream, options);

          outStream.Seek(0, <span style="color:#2b91af;">SeekOrigin</span>.Begin);


I got an exception in this line  _image.Save(outStream, options);
and the exception is that

{“Cannot save to the specified format as it is not supported at the moment.\r\nParameter name: optionsBase”}
" at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)\r\n
at Aspose.Imaging.Image.Save(Stream stream, ImageOptionsBase optionsBase)\r\n
at Imageware.Converter.BusinessLogic.AsposeSdk.AsposeImageDoc.Convert(ConversionJob job, Byte[] originalFileContent)
in C:\ConverterLibrary\BusinessLogic\AsposeSdk\AsposeImageDoc.cs:line 58"

So as it is obviously seen, PdfOptions are not supported for that kind of usage (i dont know why it is exist in imaging module)
And the link that I gave you above, contains only adding a section and adding an image into the page and save it as PDF.
I was expecting that a direct image convertion to PDF not like adding image into the page.

and for PDF/A, I was expecting PdfOptions class would have a property which is Compliance that helps us to set PDF type like
option.Compliance = PdfCompliance.PdfA1a;

but in Imaging, PdfOptions does not contain anything and even pdfoptions is not supported for pdf convertion.

for example;for aspose word
I can directly save a doc file to pdf like
var option = new PdfSaveOptions
{
ZoomBehavior = _settings.AsposeWordSaveOption.ZoomBehavior,
ZoomFactor = _settings.AsposeWordSaveOption.ZoomFactor,
Compliance = _settings.AsposeWordSaveOption.PdfFormat
};

_wordDocument.Save(outStream, option);

but aspose imaging does not support that kind of way as i understand
Hi Ertan,

Thank you for sharing details.

You can use System.IO.Stream objects to load an existing Image file using Aspose.Imaging. Following is the code demonstration. For details, please visit the links:


CODE:
//Create an instance of FileStream
using(System.IO.FileStream stream = new System.IO.FileStream(@"Path & name of any raster image",System.IO.FileMode.Open))
{
//Create an instance of Image class and load an existing file through FileStream object by calling Load method
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(stream))
{
//do some image processing.
}
}

Furthermore Aspose.Imaging can be used for image manipulation and Aspose.Pdf can be used for generating Pdf file. It is proposed that you may try manipulating the image using Aspose.Imaging and then convert/add that image to PDF using Aspose.Pdf. Aspose.Pdf is a feature rich API here you can find the options for PDF/A. Please visit the following links for details:


Hello Ikram,


Thank you for your reply. I already know these things but I was expecting that Aspose.Imaging also could support “image to pdf” convertion, like Aspose.Words does. For convertion (even its not a convertion only adding an image to a pdf file"), i have to use Aspose.Pdf. But I understand that there is not direct convertion for the image, only adding an image to a pdf file is available in this concept.
Hi Ertan,

Thank you for writing us back.

Please go through the detail on the link PdfOptions Class for details on features offered by PdfOptions Class. This can be of your interest.

Thank you for your reply. I see that this class is not for common image formats such as png, jpeg etc. For these format i have to use PDF module.


Thank you.
Hi Ertan,

Thank you for update.

I am moving this post to Aspose.Total forum. Where my colleague from Aspose.Pdf support team will look into this and update you accordingly.

Hi Ertan,

ertan2002:

Thank you for your reply. I see that this class is not for common image formats such as png, jpeg etc. For these format i have to use PDF module.

Thank you.

Thanks for your feedback. Yes you are right, Aspose.Imaging does not support Raster images(TIFF,PNG,JPEG etc) conversion to PDF but DjVu file format . So for your requirement you have to use Aspose.Pdf for images to PDF conversion and PDFA as following. Please feel free to contact us if you need any assistance in this regard.

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();

Aspose.Pdf.Page page = pdfDocument.Pages.Add();

Aspose.Pdf.Image img = new Aspose.Pdf.Image();

img.File = "input.bmp";

page.Paragraphs.Add(img);

// Convert to PDF/A compliant document

pdfDocument.Convert("log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

String output = "PDFToPDFA_out.pdf";

// Save output document

pdfDocument.Save(output);

Best Regards,

Hey, we’re getting same problem as with jpg files as @iwagbe, here is how our code looks like:
public void ConvertToPdf(Stream inputStream, Stream outputStream)
{
using (var image = Aspose.Imaging.Image.Load(inputStream))
{
image.Save(outputStream, new Aspose.Imaging.ImageOptions.PdfOptions());
}
}

All PDF files are getting blank page after that, what are we doing wrong? Was that fixed in some aspose version? (we are on 19.11.0, .net core 3.1).

I also see that it should be possible:

@ivanperever.

I have observed that you are using older product version. I suggest you to please try using latest Aspose.Imaging for .NET 20.5 on your end. In case there is still an issue then please share the source file reproducing the issue on your end along with generated PDF.

Our license does not allow us to get to 20.5. See file attached.

image (7).png (19.3 KB)

It’s strange cause we paid for full license for all products. How can we get the new license key?

@ivanperever,

In order to get new license, you may please need to consult Aspose.Purchase forum for renewal of license file. For any technical query related to API, you are always welcome.

thanks, opened issue on that forum:
https://forum.aspose.com/t/get-license-key-for-latest-version/213217