Page 1 of 1

Export PDF-page as image

Posted: Fri Jun 13, 2014 6:30 am
by prosozial_schmitt
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

Re: Export PDF-page as image

Posted: Fri Jun 13, 2014 8:23 pm
by John - Tracker Supp
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.

Re: Export PDF-page as image

Posted: Mon Jun 16, 2014 5:17 am
by prosozial_schmitt
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 https://help.pdf-xchange.com/DEV/de ... =vwrdllsdk
Only PXCV_DrawPageToDC and PXCV_DrawPageToDIBSection are listed.
:wink:

Greetings
Hans-Peter

Re: Export PDF-page as image

Posted: Mon Jun 16, 2014 4:15 pm
by John - Tracker Supp
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 ?

Re: Export PDF-page as image

Posted: Tue Jun 17, 2014 5:09 am
by prosozial_schmitt
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

Re: Export PDF-page as image

Posted: Tue Jun 17, 2014 5:06 pm
by John - Tracker Supp
Hi Hans,

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

Thanks for your patience.

Re: Export PDF-page as image

Posted: Fri Nov 21, 2014 10:58 am
by michael wagmann
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... [https://help.pdf-xchange.com/DEV/de ... mageparams]

An updated PXCView example would be very helpful.

Thanks and Regards,
Simon

Re: Export PDF-page as image

Posted: Fri Nov 21, 2014 1:47 pm
by Tracker Supp-Stefan
Hello Simon,

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

Regards,
Stefan

Re: Export PDF-page as image

Posted: Thu Mar 05, 2015 4:26 pm
by Dorwol
Hello!

Is there a little VB6 example available?

Re: Export PDF-page as image

Posted: Thu Mar 05, 2015 4:41 pm
by Tracker Supp-Stefan
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

Re: Export PDF-page as image

Posted: Thu Mar 05, 2015 5:19 pm
by Dorwol
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?

Re: Export PDF-page as image

Posted: Thu Mar 05, 2015 5:40 pm
by Dorwol
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)?

Re: Export PDF-page as image

Posted: Fri Mar 06, 2015 12:02 pm
by Tracker Supp-Stefan
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