Export PDF-page as image

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Export PDF-page as image

Post by prosozial_schmitt » Fri Jun 13, 2014 6:30 am

Hello,

we need to create an image from a page of a PDF-document and save this image as file (png/jpeg or another suitable format). We can't do this with your component PDFX-Change Viewer SDK, because at the moment we have to create this image, we don't have a program which could create a visible component (we are running like a service).

I did not find a highlevel function to export/save a page as an image in PDF-Tools SDK samples or documentation.

Is there a way to do this and do you have a sample?

Greetings
Hans-Peter

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: Export PDF-page as image

Post by John - Tracker Supp » Fri Jun 13, 2014 8:23 pm

Hi,

this can be done using our Viewer Simple DLL SDK (and then can run as required as a Service) - here is some sample code for C++ which you will need to adapt as required should you be using another development environment;

here is some sample code for C++ that converts from PDF (in the sample only first page) to image:

PXVDocument pDoc = NULL;
HRESULT hr = S_OK;
RECT rect;
PXV_CommonRenderParameters crp = {0}; // common render parameters - used to specify which part of the page and to what
// size it should rasterised (in our example the whole page into 600x800 rect)
// also defines different render options
PXV_DrawToImageParams dip = {0}; // specify resulting image parameters, like format, bits per pixel etc

IStream* pDocumentStream = NULL; // there should be a stream with your PDF file
IStream* pImage = NULL; // in a real app it will be the stream where the image should be stored; here I'm using stream on file

HRESULT hr = S_OK;
// create document
hr = PXCV_Init(&pDoc, "SerialKey", "DevCode");
// load it from stream
hr = PXCV_ReadDocumentFromIStream(pDoc, pDocumentStream, 0);
// lets create a stream on file where our rendered image will be stored
hr = SHCreateStreamOnFile(L"C:\\sample.png", STGM_CREATE | STGM_READWRITE, &pImage);
// lets specify parameters for rendering
rect.left = 0; rect.top = 0;
rect.right = 600; rect.bottom = 800;
crp.WholePageRect = ▭
crp.DrawRect = ▭
crp.Flags = pxvrpf_EmbeddedFontAsCurves | pxvrpf_NoTransparentBkgnd;
crp.RenderTarget = pxvrm_Exporting;
dip.ImageFormat = IMGF_PNG;
dip.Flags = 0; // reserved
dip.Bpp = 24;

// rendering
hr = PXCV_DrawPageToIStream(pDoc, 0, &crp, RGB(255, 255, 255) | 0xFF000000, &dip, pImage);

pImage->Release();
PXCV_Delete(pDoc);

For more info please see the relevant documentation for the SDK concerned.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Re: Export PDF-page as image

Post by prosozial_schmitt » Mon Jun 16, 2014 5:17 am

Hello John,

thank you for your sample. Looks good.
:)

Your documentation of Viewer Simple DLL SDK seems to be a little outdated?
I can't find the function PXCV_DrawPageToIStream in your chm-file and your online-help http://help.tracker-software.com/DEV/de ... =vwrdllsdk
Only PXCV_DrawPageToDC and PXCV_DrawPageToDIBSection are listed.
:wink:

Greetings
Hans-Peter

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: Export PDF-page as image

Post by John - Tracker Supp » Mon Jun 16, 2014 4:15 pm

I will ask our dev team to take a look and update as required.

Can you advise if this was the online doc's or those included in the SDK as a download ?
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Re: Export PDF-page as image

Post by prosozial_schmitt » Tue Jun 17, 2014 5:09 am

Hello John,

both of the Simple Viewer documentations (online and download-package) are not up to date and also the (VB.NET) samples in the SDK are containing old definitions with missing functions.

Greetings
Hans-Peter

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: Export PDF-page as image

Post by John - Tracker Supp » Tue Jun 17, 2014 5:06 pm

Hi Hans,

I have passed this along to the project team members responsible.

Thanks for your patience.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

michael wagmann
User
Posts: 7
Joined: Fri Sep 09, 2011 9:21 am

Re: Export PDF-page as image

Post by michael wagmann » Fri Nov 21, 2014 10:58 am

Hi,

do you have any news concerning the examples or documentation?
The online help now shows an entry for PXV_DrawToImageParams, but the "flags" property used in the example code above is missing... [http://help.tracker-software.com/DEV/de ... mageparams]

An updated PXCView example would be very helpful.

Thanks and Regards,
Simon

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13508
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Export PDF-page as image

Post by Tracker Supp-Stefan » Fri Nov 21, 2014 1:47 pm

Hello Simon,

I will check again with the person maintaining the help pages, and we will see to get that updated asap.

Regards,
Stefan

Dorwol
User
Posts: 278
Joined: Mon Aug 04, 2008 5:04 pm

Re: Export PDF-page as image

Post by Dorwol » Thu Mar 05, 2015 4:26 pm

Hello!

Is there a little VB6 example available?

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13508
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Export PDF-page as image

Post by Tracker Supp-Stefan » Thu Mar 05, 2015 4:41 pm

Hi Dorwool,

The Delphi sample project should be in:
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\DelphiExamples\PXCViewSample
And you should have no troubles integrating the above snippet John provided in the existing sample project.

Regards,
Stefan

Dorwol
User
Posts: 278
Joined: Mon Aug 04, 2008 5:04 pm

Re: Export PDF-page as image

Post by Dorwol » Thu Mar 05, 2015 5:19 pm

Tracker Supp-Stefan wrote: The Delphi sample project should be in:
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\DelphiExamples\PXCViewSample
Sorry, no way. Because same problem like in VB6. The code demonstrate only PDF opening by PXCV_ReadDocumentW.

But I think, I need to open the PDF as Stream to save it as TIF. Or not?

Dorwol
User
Posts: 278
Joined: Mon Aug 04, 2008 5:04 pm

Re: Export PDF-page as image

Post by Dorwol » Thu Mar 05, 2015 5:40 pm

For a better understanding:

See the parameters of "PXCV_DrawPageToIStream":

Doc = No problem!
PageNum = No problem!
pParams = No problem!
backcolor = No problem!
pImageParams = No problem!
pDest = BIG Problem, because VB6 doesn't support the IStream-API.

So my question ist, HOW can I open a PDF and save a page as TIFF (or all pages as multipage-TIF)?

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13508
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Export PDF-page as image

Post by Tracker Supp-Stefan » Fri Mar 06, 2015 12:02 pm

Hello Dorwool,

If you can't use the PXCV_DrawPageToIStream - have you tried the
PXCV_DrawPageToDC and PXCV_DrawPageToDIBSection methods instead?

As for creating the tiff from that raster data - you will need a separate tool.

Regards,
Stefan

Post Reply