Hi all,
I'm working with licended 'Core API SDK Version 6.0.318.0' and I try to get image data from an IPXC_Image inside a pdf page.
(finally I would like to save this image data into a separate Image file on disk).
C# snipped:
PDFXCoreAPI.IMemBlock block = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
=> image is a valid PDFXCoreAPI.IPXC_Image inside an open PDFXCoreAPI.IPXC_Document
But method 'GetImageData' throws a System.NotImplementedExeption
So, is it an other way to save an Images inside a pdf file to a separate Image file on disk ?
Many thanks.
GetImageData from IPXC_Image throws System.NotImplementedExeption
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
-
- User
- Posts: 5
- Joined: Sun May 07, 2017 2:38 am
-
- Site Admin
- Posts: 17949
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hello SonGokuOnBike,
It is Sunday - so our devs won't be able to look at this and reply until tomorrow, but in the mean time - please update to build 321 (the current latest) - and let us know if the problem still persists!
Also if you can prepare a small sample project that compiles and shows the errors, and post it here - this will greatly help my colleagues with the investigation tomorrow.
Regards,
Stefan
It is Sunday - so our devs won't be able to look at this and reply until tomorrow, but in the mean time - please update to build 321 (the current latest) - and let us know if the problem still persists!
Also if you can prepare a small sample project that compiles and shows the errors, and post it here - this will greatly help my colleagues with the investigation tomorrow.
Regards,
Stefan
-
- User
- Posts: 5
- Joined: Sun May 07, 2017 2:38 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hi Stefan,
thank you very much for your quick answer. And of course, nobody of devs will replay on Sunday
So I updated to latest Version 321 and the exception still exists.
I created a simple WinForms-Project in c#, containing one button btnGetImageData.
Inside the click event 'btnGetImageData_Click' NotImplementedException occurs at line
PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
// ############### sample project ###########################################
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TestPDFXCoreAPI
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private PDFXCoreAPI.PXC_Inst g_Inst = new PDFXCoreAPI.PXC_Inst();
private void MainForm_Load(object sender, EventArgs e)
{
// Initialialize Core SDK
g_Inst.Init(@"... < my key > ...");
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
FinalizeCoreSDK();
}
public void FinalizeCoreSDK()
{
g_Inst.Finalize();
g_Inst = null;
}
private void btnGetImageData_Click(object sender, EventArgs e)
{
// A PDF file, containing one or more pages with one image at least
FileInfo fi = new FileInfo("Test.pdf");
if (fi.Exists)
{
PDFXCoreAPI.IPXC_Document pDoc = g_Inst.OpenDocumentFromFile(fi.FullName, null);
if (pDoc != null && pDoc.Pages != null && pDoc.Pages.Count > 0)
{
PDFXCoreAPI.IPXC_Page pPage = pDoc.Pages[0];
PDFXCoreAPI.IPXC_Content content = pPage.GetContent(PDFXCoreAPI.PXC_ContentAccessMode.CAccessMode_Readonly);
PDFXCoreAPI.IPXC_ContentItems items = content.Items;
for (uint j = 0; j < items.Count; j++)
{
PDFXCoreAPI.IPXC_ContentItem item = items[j];
if (item.Type.ToString().ToUpper().Equals("CIT_IMAGE"))
{
PDFXCoreAPI.IPXC_ContentItem it = content.Items[j];
PDFXCoreAPI.IPXC_Image image = it.Image_Object;
if (image != null)
{
try
{
try
{
// Try to get raw data fails with a NotImplemented exception
// for all possible ImageDataTypes
PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
}
catch (System.NotImplementedException ex)
{
Console.WriteLine("NotImplementedException:\t" + ex.Message);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception:\t" + ex.Message);
}
}
// I'm interrested only at the first image
break;
}
}
}
if (pDoc != null)
pDoc.Close();
pDoc = null;
}
}
}
// #################################################
But may be, I will be able to find an other solution to get image data:
- Create a PDFXCoreAPI.IIXC_Page from Image and
- Finally 'draw' bitmap myself with the help of IIXC_Page method DrawToDC
Thanks and best regards.
Roland
thank you very much for your quick answer. And of course, nobody of devs will replay on Sunday
So I updated to latest Version 321 and the exception still exists.
I created a simple WinForms-Project in c#, containing one button btnGetImageData.
Inside the click event 'btnGetImageData_Click' NotImplementedException occurs at line
PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
// ############### sample project ###########################################
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TestPDFXCoreAPI
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private PDFXCoreAPI.PXC_Inst g_Inst = new PDFXCoreAPI.PXC_Inst();
private void MainForm_Load(object sender, EventArgs e)
{
// Initialialize Core SDK
g_Inst.Init(@"... < my key > ...");
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
FinalizeCoreSDK();
}
public void FinalizeCoreSDK()
{
g_Inst.Finalize();
g_Inst = null;
}
private void btnGetImageData_Click(object sender, EventArgs e)
{
// A PDF file, containing one or more pages with one image at least
FileInfo fi = new FileInfo("Test.pdf");
if (fi.Exists)
{
PDFXCoreAPI.IPXC_Document pDoc = g_Inst.OpenDocumentFromFile(fi.FullName, null);
if (pDoc != null && pDoc.Pages != null && pDoc.Pages.Count > 0)
{
PDFXCoreAPI.IPXC_Page pPage = pDoc.Pages[0];
PDFXCoreAPI.IPXC_Content content = pPage.GetContent(PDFXCoreAPI.PXC_ContentAccessMode.CAccessMode_Readonly);
PDFXCoreAPI.IPXC_ContentItems items = content.Items;
for (uint j = 0; j < items.Count; j++)
{
PDFXCoreAPI.IPXC_ContentItem item = items[j];
if (item.Type.ToString().ToUpper().Equals("CIT_IMAGE"))
{
PDFXCoreAPI.IPXC_ContentItem it = content.Items[j];
PDFXCoreAPI.IPXC_Image image = it.Image_Object;
if (image != null)
{
try
{
try
{
// Try to get raw data fails with a NotImplemented exception
// for all possible ImageDataTypes
PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
}
catch (System.NotImplementedException ex)
{
Console.WriteLine("NotImplementedException:\t" + ex.Message);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception:\t" + ex.Message);
}
}
// I'm interrested only at the first image
break;
}
}
}
if (pDoc != null)
pDoc.Close();
pDoc = null;
}
}
}
// #################################################
But may be, I will be able to find an other solution to get image data:
- Create a PDFXCoreAPI.IIXC_Page from Image and
- Finally 'draw' bitmap myself with the help of IIXC_Page method DrawToDC
Thanks and best regards.
Roland
-
- User
- Posts: 5
- Joined: Sun May 07, 2017 2:38 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hi Stefan,
I found a solution for me to get a 'copy' of a bitmap, contained inside a pdf page:
I replaced only the line PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
with following code:
// create CreateIXCPage
PDFXCoreAPI.IIXC_Page ip = image.CreateIXCPage(false, PDFXCoreAPI.PXC_RenderingIntent.RI_RelativeColorimetric);
// create bitmap with correct size based on page size
Bitmap img = new Bitmap((int)(ip.Rect.right - ip.Rect.left), (int)(ip.Rect.bottom - ip.Rect.top));
// create and using graphics
using (Graphics g = Graphics.FromImage(img))
{
// init bitmap
g.Clear(Color.White);
IntPtr hdc = g.GetHdc();
// draw bitmap
ip.DrawToDC((uint)hdc, 0, 0, ip.Rect.right - ip.Rect.left, ip.Rect.bottom - ip.Rect.top, 0, 0);
// release handle
g.ReleaseHdc(hdc);
}
// Bitmap img is now ready to save on disk, to crop parts or to display in a picture box, ...
Or would be method GetImageData a better solution ?
Many thanks and best regards
Roland
I found a solution for me to get a 'copy' of a bitmap, contained inside a pdf page:
I replaced only the line PDFXCoreAPI.IMemBlock mem = image.GetImageData(PDFXCoreAPI.PXC_ImageDataType.kIDT_Raw);
with following code:
// create CreateIXCPage
PDFXCoreAPI.IIXC_Page ip = image.CreateIXCPage(false, PDFXCoreAPI.PXC_RenderingIntent.RI_RelativeColorimetric);
// create bitmap with correct size based on page size
Bitmap img = new Bitmap((int)(ip.Rect.right - ip.Rect.left), (int)(ip.Rect.bottom - ip.Rect.top));
// create and using graphics
using (Graphics g = Graphics.FromImage(img))
{
// init bitmap
g.Clear(Color.White);
IntPtr hdc = g.GetHdc();
// draw bitmap
ip.DrawToDC((uint)hdc, 0, 0, ip.Rect.right - ip.Rect.left, ip.Rect.bottom - ip.Rect.top, 0, 0);
// release handle
g.ReleaseHdc(hdc);
}
// Bitmap img is now ready to save on disk, to crop parts or to display in a picture box, ...
Or would be method GetImageData a better solution ?
Many thanks and best regards
Roland
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hello Roland,
The GetImageData method is not yet implemented as you can see from the exception.
The code should look like this:
1) You convert the IPXC_Image into the IIXC_Page.
2) Then you should create the IIXC_Image with the IIXC_Inst::CreateEmptyImage method, specifying the format, and insert the IIXC_Page into it.
3) Then you can save the IIXC_Image to disk.
Cheers,
Alex
The GetImageData method is not yet implemented as you can see from the exception.
The code should look like this:
1) You convert the IPXC_Image into the IIXC_Page.
2) Then you should create the IIXC_Image with the IIXC_Inst::CreateEmptyImage method, specifying the format, and insert the IIXC_Page into it.
3) Then you can save the IIXC_Image to disk.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
-
- User
- Posts: 5
- Joined: Sun May 07, 2017 2:38 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hello Alex,
thank you very much for your solution.
It works like a charm
And without any GDI+-drawings
But it's possible to get a description of different supported FormatIDs ( TIF, PNG, BMP, ...) ?
As a 'draft' solution I created a TIF-Picture (CCITT Group4), loaded this Picture into an IIXC_Image and checked the FormatID.
Best regards
Roland
thank you very much for your solution.
It works like a charm
And without any GDI+-drawings
But it's possible to get a description of different supported FormatIDs ( TIF, PNG, BMP, ...) ?
As a 'draft' solution I created a TIF-Picture (CCITT Group4), loaded this Picture into an IIXC_Image and checked the FormatID.
Best regards
Roland
-
- User
- Posts: 5
- Joined: Sun May 07, 2017 2:38 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hello Alex,
I found FormatIDs inside one of your earlier posts:
https://sdkhelp.pdf-xchange.com/vie ... eFormatIDs
And again, thank you very much for your solution.
Best regards
Roland
I found FormatIDs inside one of your earlier posts:
https://sdkhelp.pdf-xchange.com/vie ... eFormatIDs
And again, thank you very much for your solution.
Best regards
Roland
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
Re: GetImageData from IPXC_Image throws System.NotImplementedExeption
Hello Roland,
You can also check the ImagesTest utility available here:
https://forum.pdf-xchange.com/ ... 67&t=25944
It will show you possible format parameters.
Cheers,
Alex
You can also check the ImagesTest utility available here:
https://forum.pdf-xchange.com/ ... 67&t=25944
It will show you possible format parameters.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ