Page 1 of 1

ExportDocument

Posted: Fri Oct 02, 2009 6:05 am
by jeffp
I need to export each page of a pdf as a TIFF file (or other image format) in order to pass it along to my OCR engine. In the Viewer SDK there is a nice ExportDocument call that does it well. However, I'd like to do this without having to open the viewer.

As such, is there an equivalent to the Viewer's ExportDocument procedure in the PDF Tools SDK? Or is there a combination of calls I can make to get to the same result.

Re: ExportDocument

Posted: Fri Oct 02, 2009 1:57 pm
by Corwin - Tracker Sup
You can see an example of how export images from PDF in our PXCPro Sample (..\Examples\DelphiExamples\PXCProSample\).
HTH.

Re: ExportDocument

Posted: Fri Oct 02, 2009 2:32 pm
by jeffp
I saw that example but it seems to deal with extracting images that are already in the PDF page. ExportDocument in the Viewer actually creates a TIFF (or other image file) out of the PDF page whether or not that page contains images. Is there something similar in the PDF Tools SDK?

Re: ExportDocument

Posted: Fri Oct 02, 2009 2:49 pm
by Corwin - Tracker Sup
Well, to render PDF file to image you may use PXCView.dll or Viewer ActiveX.

Re: ExportDocument

Posted: Fri Oct 02, 2009 3:14 pm
by jeffp
As I mentioned, I can render the page to a TIFF file just fine in the ActiveX viewer using the ExportDocument call. But I'm looking to do it outside the ActiveX Viewer. As such, in looking at the Non-ActiveX Viewer SDK, I see the PXCV_DrawPageToDC function. Is that what you use? If so, the issue is how do I then convert the DC to a TIFF image?

Re: ExportDocument

Posted: Fri Oct 02, 2009 3:39 pm
by Corwin - Tracker Sup
If you’re current version of Delphi doesn’t allow saving images to TIFF format then you can use any additional components or libraries to do this or the PDF-XChange Viewer ActiveX SDK and I believe you are already aware of this ...

HTH

Re: ExportDocument

Posted: Tue Oct 06, 2009 3:12 am
by jeffp
I think I'd prefer to do my entire OCR process outside of the Viewer given the current Viewer limitations in this area. As such, I'd also like to create the TIFF images from each PDF page using your non-Viewer AX SDKs. I see in the normal Viewer SDK there is a way to convert the PDF page to a windows DC using PXCV_DrawPageToDC. However, I then need to convert it to a TIFF. Does your Image SDK do this for me? Delphi doesn't help me out here. And are you using PXCV_DrawPageToDC in ExportDocument?

Ideally, I'd like to replicate your ExportDocument call which is currently in the Viewer AX SDK. I assume that your are using your other components in some combination to produce your ExportDocument call. Would it be possible to for someone to direct me how to replicate this call using your other SDKs.

Thanks.

Re: ExportDocument

Posted: Tue Oct 06, 2009 1:42 pm
by Corwin - Tracker Sup
You can use PXCV_DrawPageToDIBSection to render PDF page to HBitmap and then use Image-XChange SDK functions to save HBitmap to Tiff file.
In Image-Xchange you should first create image (IMG_ImageCreateEmpty) and then create new page from HBitmap by using IMG_PageCreateFromHBITMAP function. Also you should specify that you want to create Tiff file by using next functions for each new page:

Code: Select all

hr := IMG_PageSetFormatLongParameter(page, FP_ID_FORMAT, FMT_TIFF_ID);
hr := IMG_PageSetFormatLongParameter(page, FP_ID_ITYPE, ImageFormat_RGB_8);
After that you can add page to image (IMG_ImageInsertPage). In such way you can add multiple pages to one image file.
To save existed image to Tiff file you need to use IMG_ImageSaveToFile.

Re: ExportDocument

Posted: Tue Oct 06, 2009 2:52 pm
by jeffp
Just a couple of follow ups:

1. I see that all the image functions like IMG_PageSetFormatLongParameter you refer to are in the ixclib40.dll. However, I can't seem to find the Delphi unit that wraps these functions and in turn exposes them to me. Am I missing a unit here?

2. Do you have a small Delphi example of how to setup PXCV_DrawPageToDIBSection. I'm not sure what to use for several of the parameters like hBaseDC, hSection, dwOffset. Below is a code snippet of how I was using PXCV_DrawePageToDC to produce a TBitmap.

Code: Select all

procedure TPDFViewer.DrawPage(B: TBitmap; APage: Integer);
var
  AParams: PXV_CommonRenderParameters;
  hr: HRESULT;
  AWidth, AHeight: Double;
  W, H: Integer;
  AWholePage: TRect;
begin
  PXCV_GetPageDimensions(hDoc, APage - 1, @AWidth, @AHeight);

  W := Round((AWidth / 72) * 100 * 3);
  H := Round((AHeight / 72) * 100 * 3);

  with AWholePage do
  begin
    Left := 0;
    Top := 0;
    Right := Left + W;
    Bottom := Top + H;
  end;

  B.Width := W;
  B.Height := H;

  AParams.WholePageRect := @AWholePage;
  AParams.DrawRect := nil;
  AParams.RenderTarget := pxvrm_Exporting;
  AParams.Flags := 0;

  hr := PXCV_DrawPageToDC(hDoc, APage - 1, B.Canvas.Handle, @AParams);
  ErrorCheck(hr);
end;

Re: ExportDocument

Posted: Tue Oct 06, 2009 4:11 pm
by Corwin - Tracker Sup
1. This function is declared in img_c.pas file.
2. If you already have TBitmap then you can pass it handle (b.handle) as HBitmap parameter in IMG_PageCreateFromHBITMAP function.

Re: ExportDocument

Posted: Tue Oct 06, 2009 4:36 pm
by jeffp
I can't find the img_c.pas in the SDK I've download. Can you send it to me?

So are you saying that I can use PXCV_DrawePageToDC instead of PXCV_DrawPageToDIBSection? What's the difference and is one better than the other?

Thanks again.

Re: ExportDocument

Posted: Tue Oct 06, 2009 4:50 pm
by Corwin - Tracker Sup
Try to search these files in your "Image-XChange\Include\" directory. Also I have attached these files to this post.
What's the difference and is one better than the other?
Well, in both cases you will get TBitmap, so there is no particular difference.

Re: ExportDocument

Posted: Tue Oct 06, 2009 5:33 pm
by jeffp
The pascal files were not in that directory, so thanks for your attachment.

So there is not real difference in the quality of the bitmap I get from PXCV_DrawePageToDC instead of PXCV_DrawPageToDIBSection? The reason I ask is because I'll be converting this bitmap to a TIFF in order to feed into my OCR engine. As such, I'm looking for the best quality of TIFF for the OCR engine since it helps the accuracy.

Re: ExportDocument

Posted: Wed Oct 07, 2009 7:04 am
by Lzcat - Tracker Supp
File quality depends only on bitmap (DC) dimensions and file save format. From PXCView you will almost always get 24bpp image, however you can convert it to any other suitable format using Image-XChange (before saving on during it).