Two Pilots™    Home  |  Navigation  |  Site Map  |  Products  |  Download  |  Prices  |  For Partners  |  Support


All forums · Statistics · Search ·

Two Pilots forum / For software developers / Clipping has no effect when creating PDF with HDC
Author Message
SFI
# Posted: 11 Dec 2008 10:35


Good day.

We are using PDF Creator Pilot 3.5 to create PDF files of our documents. We obtain a HDC and use it to perform "printing". But for some reason clipping doesn't seem to work. I read here on the forums that SelectClipRegion is not supported so we tried using paths but nothing changed, the "clipped-off" parts are being drawn on. We did something like this:

dc.BeginPath();
dc.MoveTo(Rect.left , Rect.top );
dc.LineTo(Rect.right, Rect.top );
dc.LineTo(Rect.right, Rect.bottom);
dc.LineTo(Rect.left , Rect.bottom);
dc.LineTo(Rect.left , Rect.top );
dc.EndPath();
dc.SelectClipPath(RGN_COPY);

And then perform various GDI operations like MoveTo, LineTo, drawing text, and so on...but drawing outside of the rectangle occurs. We tested this with DCs from other "sources", like Microsoft's Office Document Image Writer, it works fine with those.
Are we doing something wrong?

Thanks for your answer in advance.

Vitaliy Shibaev
Member
# Posted: 12 Dec 2008 04:25


Hi,

In old versions work with paths and clipping regions was wrong. In the current version we highly improved it, here is the current build:
http://www.colorpilot.com/~builds/PDFCreatorPilot4 _1_2497.zip

Best regards,
Vitaliy Shibaev
Two Pilots

Anonymous
# Posted: 15 Dec 2008 10:51


Thank you for your answer.

I downloaded and installed the new version. I changed our code to use the IPDFDocument4 interface, and have hit a new problem. I did -so about- the dollowing (PDF is a pointer to IPDFDocument4) when creating a document:

PDF->Clear();
PDF->PageWidth = widh_to_use;
PDF->PageHeight = height_to_use;
PDF->PageResolution = dpi_to_use;
HDC hdc = PDF->GetDC();
...draw first page using GDI calls...
while (there_are_pages_to_print_left)
{
PDF->NewPage();
hdc = PDF->GetDC();
...draw the current page using GDI calls...
}
PDF->SaveToFile(path_to_save_to, TRUE);

My problem is that the very first page really seems to use the right size and DPI, but the rest of the pages all get 96 for the DPI. After the first save all the new PDF documents i try to save without exiting the program also seem to work with 96 as DPI (i call PDF->Clear() before starting witha new document), i tried to put the PDF->PageResolution right before or after NewPage, i tried setting PDF->UseScreenBasedDC to FALSE but doesn't seem to change anything.
I checked PDF->PageResolution, it seems to be what i set it to all the time but the HDC i get is the set DPI the very first time (determined by using GetDeviceCaps(LOGPIXELSY)) and 96 for all the other pages. What am i doing wrong?

Thanks again for your answer in advance.

Vitaliy Shibaev
Member
# Posted: 16 Dec 2008 01:31 · Edited by: Vitaliy Shibaev


Hi,

For correct output using GetDC it is recommended to set PageResolution equal to GetDCResolution. It simplifies a code.
PageWidth and PageHeight are affect only on current page.
PageResolution sets resolution for current page and sets default resolution for all new page.

Here is the update for your code:
PDF->Clear();
PDF->PageWidth = width_to_use;
PDF->PageHeight = height_to_use;
//PDF->PageResolution = dpi_to_use;
PDF->PageResolution = PDF->GetDCResolution();
HDC hdc = PDF->GetDC();
...draw first page using GDI calls...
while (there_are_pages_to_print_left)
{
PDF->NewPage();
PDF->PageWidth = (long)(width_to_use * PDF->PageResolution / 72.0f);
PDF->PageHeight = (long)(height_to_use * PDF->PageResolution / 72.0f);
hdc = PDF->GetDC();
...draw the current page using GDI calls...
}
PDF->SaveToFile(path_to_save_to, TRUE);

Best regards,
Vitaliy Shibaev
Two Pilots

 

 

Powered by miniBB 2.0 RC7 © 2001-2004 Page creation time (sec.): 0.013

 

Page top