web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Convert PDF as Image

(0) ShareShare
ReportReport
Posted on by 1,254

Hi,

I tried to convert PDF into image in AX 2012 by X++ with following code and this code is working fine but the problem is, I can't able to view the converted image

CODE

========================================================

System.Byte[] pdfDocBuffer;
System.IO.FileInfo fi_pdfDoc;
System.IO.FileStream fs;
str Content;
// Grant clrinterop permission.
new InteropPermission(InteropKind::ClrInterop).assert();
//Load the file
fi_pdfDoc = new System.IO.FileInfo(@'C:/CodeCamp2009.pdf');
//Initiallize the byte array by setting the length of the file
pdfDocBuffer= new System.Byte[int642int(fi_pdfDoc.get_Length())]();
// Stream the file
fs= new System.IO.FileStream(fi_pdfDoc.get_FullName(), System.IO.FileMode::Open, System.IO.FileAccess::Read);
fs.Read(pdfDocBuffer, 0, pdfDocBuffer.get_Length());
// Convert the file into a base64 string
Content = System.Convert::ToBase64String(pdfDocBuffer, 0, pdfDocBuffer.get_Length());
//Revert the access
CodeAccessPermission::revertAssert();

AifUtil::saveBase64ToFile(@"C:\testfsdsdsds.jpg", Content);

=============================================================

Parameter is not valid -  this error is also related to this issue.

1261.q.png

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    238,609 Most Valuable Professional on at

    That's not surprising, because it's not an image at all. Your code takes the binary content of the PDF file, encodes it to text (using base64) and stores this text file as testfsdsdsds.jpg.

    Why are do you want to convert PDF to image in the first place?

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Storing a binary file as a base64 string is very different from being an actual image that is also encoded to a binary file, like Martin has pointed it out.

    You would have to use a third-party library, since such conversion does not exist out-of-the-box neither for AX nor for the .Net Framework. You can read up on some of the solutions here:

    stackoverflow.com/.../how-to-convert-pdf-files-to-image

  • Kanagaraj A Profile Picture
    1,254 on at

    Hi Martin,

    Thank you, I would like to embed PDF into SSRS Report.

  • Kanagaraj A Profile Picture
    1,254 on at

    I will follow the given link.

  • Anand AX Profile Picture
    2,172 on at

    Hi Kanagaraj A,

    I have a same scenario to embed pdf and all file types from attachment into SSRS report in D365 FO. Do you have any working solution for this?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans