ExportDocument

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: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Tracker Supp-Stefan

Post Reply
jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

ExportDocument

Post by jeffp » Fri Oct 02, 2009 6:05 am

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.

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Fri Oct 02, 2009 1:57 pm

You can see an example of how export images from PDF in our PXCPro Sample (..\Examples\DelphiExamples\PXCProSample\).
HTH.

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Fri Oct 02, 2009 2:32 pm

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?

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Fri Oct 02, 2009 2:49 pm

Well, to render PDF file to image you may use PXCView.dll or Viewer ActiveX.

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Fri Oct 02, 2009 3:14 pm

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?

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Fri Oct 02, 2009 3:39 pm

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

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Tue Oct 06, 2009 3:12 am

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.

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Tue Oct 06, 2009 1:42 pm

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.

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Tue Oct 06, 2009 2:52 pm

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;

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Tue Oct 06, 2009 4:11 pm

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.

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Tue Oct 06, 2009 4:36 pm

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.

Corwin - Tracker Sup
User
Posts: 670
Joined: Tue Nov 14, 2006 12:23 pm

Re: ExportDocument

Post by Corwin - Tracker Sup » Tue Oct 06, 2009 4:50 pm

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.
Attachments
ImgXchange.zip
(11.34 KiB) Downloaded 116 times

jeffp
User
Posts: 859
Joined: Wed Sep 30, 2009 6:53 pm

Re: ExportDocument

Post by jeffp » Tue Oct 06, 2009 5:33 pm

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.

Lzcat - Tracker Supp
Site Admin
Posts: 718
Joined: Thu Jun 28, 2007 8:42 am

Re: ExportDocument

Post by Lzcat - Tracker Supp » Wed Oct 07, 2009 7:04 am

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).
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

Post Reply