Export PDF-page as image
Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan
-
- User
- Posts: 49
- Joined: Tue Dec 28, 2004 9:49 am
Export PDF-page as image
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
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: 5219
- Joined: Tue Jun 29, 2004 10:34 am
- Location: United Kingdom
- Contact:
Re: Export PDF-page as image
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.
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
Best regards
Tracker Support
http://www.tracker-software.com
-
- User
- Posts: 49
- Joined: Tue Dec 28, 2004 9:49 am
Re: Export PDF-page as image
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.
Greetings
Hans-Peter
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.
Greetings
Hans-Peter
- John - Tracker Supp
- Site Admin
- Posts: 5219
- Joined: Tue Jun 29, 2004 10:34 am
- Location: United Kingdom
- Contact:
Re: Export PDF-page as image
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 ?
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
Best regards
Tracker Support
http://www.tracker-software.com
-
- User
- Posts: 49
- Joined: Tue Dec 28, 2004 9:49 am
Re: Export PDF-page as image
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
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: 5219
- Joined: Tue Jun 29, 2004 10:34 am
- Location: United Kingdom
- Contact:
Re: Export PDF-page as image
Hi Hans,
I have passed this along to the project team members responsible.
Thanks for your patience.
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
Best regards
Tracker Support
http://www.tracker-software.com
-
- User
- Posts: 7
- Joined: Fri Sep 09, 2011 9:21 am
Re: Export PDF-page as image
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
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
- Tracker Supp-Stefan
- Site Admin
- Posts: 17910
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Export PDF-page as image
Hello Simon,
I will check again with the person maintaining the help pages, and we will see to get that updated asap.
Regards,
Stefan
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
Hello!
Is there a little VB6 example available?
Is there a little VB6 example available?
- Tracker Supp-Stefan
- Site Admin
- Posts: 17910
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Export PDF-page as image
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
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
Sorry, no way. Because same problem like in VB6. The code demonstrate only PDF opening by PXCV_ReadDocumentW.Tracker Supp-Stefan wrote: The Delphi sample project should be in:
C:\Program Files\Tracker Software\PDF-XChange Viewer SDK\Examples\DelphiExamples\PXCViewSample
But I think, I need to open the PDF as Stream to save it as TIF. Or not?
Re: Export PDF-page as image
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)?
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)?
- Tracker Supp-Stefan
- Site Admin
- Posts: 17910
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Export PDF-page as image
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
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