Export specific of PDF page to Images

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, 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.
Post Reply
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Export specific of PDF page to Images

Post by mbz »

Hi guys,

I need to export a specific rect of a pdf page to images. First I thought, I'm just setting my custom rect to

Code: Select all

FormatParams[CustomRect].v

But if I try to export then, I'm getting the following exception:

Code: Select all

Wrong Parameter
So, what type of rect is expected?
Can one export a specific rect of pdf page anyway?

Thanks in advance
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Export specific of PDF page to Images

Post by Sasha - Tracker Dev Team »

Hello mbz,

The Format parameters are not meant to use that way - use the forum search to find more if you need.
As for your problem, you can export the needed pages into a new temp doc, crop them there and then do the export.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Export specific of PDF page to Images

Post by mbz »

Hi Alex,
thanks for your fast replay. Unfortunately I cannot find any help in this forum for cropping pages in that way you suggested.
May you post a short example?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Export specific of PDF page to Images

Post by Sasha - Tracker Dev Team »

Hello mbz,

Have you tried using search on the SDK help wiki - I'm pretty sure there is a sample on the Crop Pages operation.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Export specific of PDF page to Images

Post by Sasha - Tracker Dev Team »

Hello mbz,

Just thought of a better method - you will have to use DrawToIXCPage methods of the IPXC_Page. Here's the link to the sample that should contain this:
https://github.com/tracker-software/PDFCoreSDKExamples
This will allow you to save the rectangle that you need.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Export specific of PDF page to Images

Post by mbz »

Hi Alex,
thank you for your reply. Im implementing the usage of DrawToIXCPage. But I cannot find any equivalent of PXC::FP_ID_XDPI in C# so I can't get the right ID to set the FmtInt of IIXC_Page. I'm unable to find any C# version of that Property.
So how shall I set the value of e.g. XDPI?

Thanks
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Export specific of PDF page to Images

Post by Sasha - Tracker Dev Team »

Hello mbz,

Use these:

Code: Select all

iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_XDPI, 300);
iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_YDPI, 300);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mbz
User
Posts: 39
Joined: Wed Jul 13, 2016 2:50 pm

Re: Export specific of PDF page to Images

Post by mbz »

Hi Alex,
thank you for your reply. However, I don't get the rect of the page exported, i'd selected.
In my case, the user has to select a rect of the pdf page (like snipping tool). After that, I calculate that selected rectangle with IPXV_PagesLayoutManager.DeviceRectToPageRect to the specified PXC_Rect, the user has selected.
After that, I try to export that rect as an image with the following code:

Code: Select all

const uint dpiX = 300;
const uint dpiY = 500;
var imgCore = (IIXC_Inst) inst.GetExtension("IXC");
var img = imgCore.CreateEmptyImage();
var page = doc.CoreDoc.Pages[0];

var cx = (uint)(customRect.right - customRect.left);
var cy = (uint)(customRect.top - customRect.bottom);

var iPage = imgCore.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8RGB, 0); 
var ipxcInst = (IPXC_Inst) inst.GetExtension("PXC");
var param = ipxcInst.CreateRenderParams();
if (param == null)
    throw new NullReferenceException("Cannot export with rect. Creating params failed.");

param.RenderFlags = (uint)PXC_RenderFlags.RF_OverrideBackgroundColor | (uint)PXC_RenderFlags.RF_SmoothImages | (uint)PXC_RenderFlags.RF_SmoothLineArts;

param.TextSmoothMode = PXC_TextSmoothMode.TSM_ClearType;

var matrix = new PXC_Matrix();

var tagRec = new tagRECT
{
    top = (int)customRect.bottom,
    left = (int)customRect.left,
    bottom = (int)customRect.top,
    right = (int)customRect.right
};

page.DrawToIXCPage(iPage, ref tagRec, ref matrix, param);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_XDPI, dpiX);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_YDPI, dpiY);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_FILTER, 0);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_FORMAT, (uint) IXC_ImageFileFormatIDs.FMT_BMP_ID);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_ITYPE, 16);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_COMP_LEVEL, 5);
iPage.set_FmtInt((uint) IXC_FormatParametersIDS.FP_ID_COMP_TYPE, 32773);

img.InsertPage(iPage, 0);
nPage++;
img.Save(fileName, IXC_CreationDisposition.CreationDisposition_Overwrite);
The problem is, I'm getting bitmaps like this image.
You can see, the background ist black and the defined rect, which needs to be exported, seems to be moved to the lower right corner of the bmp file. Also, the rect you can see in the picture is not in the range of the rectangle the user has selected.
So my problem is first that the rect I pass seems to be bigger than the actual selected one and second that I just cannot move the content to fit into its dimensions. I hope you can help me in some way.

Thanks in advance
mbz
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Export specific of PDF page to Images

Post by Sasha - Tracker Dev Team »

Hello mbz,

Well you are experiencing this problem, because you haven't specified a correct matrix. Try searching this forum on how to work with matrices and what they are. Here's a piece of code for you to start:
https://forum.pdf-xchange.com/ ... 42#p101442

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply