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


All forums · Statistics · Search ·

Two Pilots forum / For software developers / ratio problems
Author Message
eco
Member
# Posted: 12 Feb 2008 03:29


I get a ratio problem on rendering.
On 2 machines (xp) with only 1 printer network printer installed, same screen resolution, same printer parameters.
Printing on a userdefined page) - 2100x2970 pixel, resolution set to 96dpi.
When drawing the same EMF using PDFPAGE_PlayMetaFileEx,

One the first machine, I need to set a YScale of 1.09375 to fill the page,
One the second machine the YScale must be 1.0000.

I cannot figure why.

Vitaliy Shibaev
Member
# Posted: 12 Feb 2008 13:03


Hi!

Unfortunately I need more detailed description. Could you please specify your actions step by step? Could you send to us your code and emf?

Best regards,
Vitaliy Shibaev
Two Pilots

Anonymous
# Posted: 13 Feb 2008 05:13


ok, sending little source to you by mail to http://www.colorpilot.com/support.html .
on my machine, there is one inch missing on the bottom of the generated pdf

Anonymous
# Posted: 13 Feb 2008 05:15


ok, sending little source to you by mail to http://www.colorpilot.com/support.html .
on my machine, there is one inch missing on the bottom of the generated pdf

eco
Member
# Posted: 13 Feb 2008 05:19


oops mail ?
there is the code:

#include <windows.h>
#include <ocidl.h>
#include "pdfcreator.h"

#define TOPIX( x ) MulDiv(x,96,254)

void main( )
{
CoInitialize( 0 );

IPDFDocument3* pdf = NULL;
CoCreateInstance( __uuidof(PDFDocument3), NULL, CLSCTX_ALL, __uuidof(pdf), (void**)&pdf );

pdf->StartEngine( L"demo", L"demo" );
pdf->put_OnePass( VARIANT_TRUE );
pdf->put_Compression( ctFlate );
pdf->put_InitialZoom2( zlFitPage );
pdf->put_AutoLaunch( VARIANT_TRUE );

pdf->put_FileName( L"c:/test.pdf" );
pdf->put_DocumentInfo_Title( L"test" );


pdf->put_Resolution( 96 );
pdf->BeginDoc( );
pdf->put_PDFPAGE_Orientation( poPageLandscape );

pdf->put_PDFPAGE_Size( psUserDefined );
pdf->put_PDFPAGE_Width( TOPIX(2970) );
pdf->put_PDFPAGE_Height( TOPIX(2100) );

HDC hdc = CreateEnhMetaFile( NULL, NULL, NULL, NULL );
HPEN pen = CreatePen( PS_SOLID, 0, 0 );
HGDIOBJ sav = SelectObject( hdc, pen );

MoveToEx( hdc, TOPIX(0), TOPIX(0), NULL );
LineTo( hdc, TOPIX(2970), TOPIX(2100) );

DeleteObject( SelectObject(hdc,sav) );


HENHMETAFILE hMeta = CloseEnhMetaFile( hdc );
pdf->PDFPAGE_PlayMetaFileEx( (long)hMeta, 0.0, 0.0, 1.0, 1.0 );
DeleteEnhMetaFile( hMeta );

pdf->EndDoc( );
pdf->Release( );
CoUninitialize( );
}

Vitaliy Shibaev
Member
# Posted: 14 Feb 2008 08:02


Hi!

Analogously to another you post I can tell, that developer who was written this part of library is away now. I'll reply some later.

Best regards,
Vitaliy Shibaev
Two Pilots

eco
Member
# Posted: 18 Feb 2008 02:46


hummm, I thought I pay for support is'nt it ?
do you get a date ?
can you send me sources ?

Vitaliy Shibaev
Member
# Posted: 18 Feb 2008 05:23


Hi!

The problem is that you are wrong with coordinates recalculation.
Here is the sample (C++):

PDF->Resolution = 72;
PDF->BeginDoc();
PDF->put_UseScreenDC(VARIANT_TRUE);
DrawLines(PDF);

PDF->Resolution = 96;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_TRUE);
DrawLines(PDF);

PDF->Resolution = 300;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_TRUE);
DrawLines(PDF);

PDF->Resolution = 600;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_TRUE);
DrawLines(PDF);

// with printer DC

PDF->Resolution = 72;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_FALSE);
DrawLines(PDF);

PDF->Resolution = 96;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_FALSE);
DrawLines(PDF);

PDF->Resolution = 300;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_FALSE);
DrawLines(PDF);

PDF->Resolution = 600;
PDF->NewPage();
PDF->put_UseScreenDC(VARIANT_FALSE);
DrawLines(PDF);

PDF->EndDoc();


void DrawLines(IPDFDocument3* PDF)
{
CString sDevice = "printer-based";
if (PDF->UseScreenDC == VARIANT_TRUE)
sDevice = "screen-based";

CString sBanner;
sBanner.Format("Page resolution is %d, using %s virtual device context", PDF->Resolution, sDevice);

double dPDFScale = PDF->Resolution / 72.0f;
double dBannerTop = 20;
PDF->PDFPAGE_SetActiveFont("Arial", VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, VARIANT_FALSE, 14, charsetANSI_CHARSET);
PDF->PDFPAGE_TextOut(100 * dPDFScale, dBannerTop, 0, (BSTR)CComBSTR(sBanner));
double dBannerHeight = PDF->PDFPAGE_GetTextHeight((BSTR)CComBSTR(sBanner) );

HDC hDC = 0;
PDF->get_HDC((long*)&hDC);

double dPDFTop = dBannerTop + dBannerHeight * 3;
double dPDFLeft = 120 * dPDFScale;

long lPDFResolution = PDF->Resolution;
long lDCResolution = PDF->GetUsedDCResolution();
double dScale = (double)lPDFResolution / (double)lDCResolution;

for (int i = 0; i < 5; i++)
{
int lineWidthPDF = i;
int lineWidthDC = (int)(lineWidthPDF * lDCResolution / 72.0f);

double dPDFRight = dPDFLeft + 360 * dPDFScale;
PDF->PDFPAGE_SetLineWidth(lineWidthPDF);
PDF->PDFPAGE_MoveTo(dPDFLeft, dPDFTop);
PDF->PDFPAGE_LineTo(dPDFRight, dPDFTop);
PDF->PDFPAGE_Stroke();

HPEN pen = CreatePen(PS_SOLID, lineWidthDC, RGB(0, 0, 0xFF));
HPEN oldPen = (HPEN)SelectObject(hDC, pen);

double dShiftedPDFTop = dPDFTop + 25 * dPDFScale;
double dGDILeft = dPDFLeft * dScale;
double dGDITop = dShiftedPDFTop * dScale;
double dGDIRight = dPDFRight * dScale;

MoveToEx(hDC, (int)dGDILeft, (int)dGDITop, 0);
LineTo(hDC, (int)dGDIRight, (int)dGDITop);
SelectObject(hDC, oldPen);

dPDFTop += 50 * dPDFScale;
}
}


Best regards,
Vitaliy Shibaev.

eco
Member
# Posted: 25 Feb 2008 02:21


Hi, I do not agree with you, if you try my sample, and add the following lines

pdf->PDFPAGE_MoveTo( 0, 0 );
pdf->PDFPAGE_LineTo( TOPIX(2970), TOPIX(2100) );
pdf->PDFPAGE_Stroke();

just before pdf->EndDoc( );
you will see that there is a difference between emf printing & direct line printing.

Emf printing is 2.54cm above direct line printing...

Your response do not take in account that there is a difference between two machines printing on the same printer.

eco
Member
# Posted: 25 Feb 2008 03:52


OK !
I found the ratio problem: you use the screen informations stored in the emf (computed with screen that explain the differences between computers).
To correct the emf problem I use this:

double calcEnhRatio( HENHMETAFILE hMeta )
{
ENHMETAHEADER header;
GetEnhMetaFileHeader( hMeta, sizeof(header), &header );

double x1 = 25.4 / (double(header.szlMicrometers.cx) / (double(header.szlDevice.cx) * 1000.0));
double y1 = 25.4 / (double(header.szlMicrometers.cy) / (double(header.szlDevice.cy) * 1000.0));

x1 = ceil( x1 );
y1 = ceil( y1 );

return x1 / y1;
}

And I can use the returned ratio in

pdf->PDFPAGE_PlayMetaFileEx( (long)hMeta, 0.0, 0.0, 1.0, 1.0/ratio );

now it's ok.

Conclusion:
I think you use that to keep screen presentation but in my (maybe someone else) it's not a good idea.

 

 

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

 

Page top