if lUseImage2PDF
YourI2PDFFunction(...)
else
oPreview:SaveAs( .T., ; // .T. for PDF and .F. for docx
cFileName, ;
lView ) // .T. displays the PDF after saving.
endif
nageswaragunupudi wrote:Good option.
Can you also please guide a normal user how to use and what libs to link to save preview to pdf?
nageswaragunupudi wrote:May I ask? At present, how are you saving preview to pdf? (i.e., emf to pdf)
function FWSavePreviewToPDF( oDevice, cPDF, lOpen, lQuality, nQuality ) // oDevice can be oPrinter or oPreview
local cOrient, oPDF
local hWnd
LOCAL aDatos:= {}
DEFAULT lQuality := .f.
IF Empty( nQuality )
nQuality := 50
nDensity := 300
lQuality := .t.
ENDIF
if lQuality
EDITVARS nQuality,nDensity TITLE "Atencion" PROMPTS "Calidad", "Densidad" ;
PICTURES "999", "999"
// aDatos:= { @nQuality, @nDensity }
// MsgGet( "Atencion",{ "Calidad", "Densidad" }, aDatos ) // @nQuality )
endif
if oDevice:IsKindOf( "TPREVIEW" )
hWnd := oDevice:oWnd:hWnd
oDevice := oDevice:oDevice
endif
DEFAULT cPDF := cGetFile( FWString( "PDF files | *.pdf |" ),;
FWString( "Select PDF File to Save" ),, ;
CurDir(), .T.,,,;
hb_CurDrive() + ":\" + CurDir() + "\" + ;
If( oDevice:IsKindOf( "TPreview" ),;
oDevice:cName, oDevice:cDocument ) + ".pdf" )
if ! Empty( cPDF )
cPDF = cFileSetExt( cPDF, "pdf" )
CursorWait()
cOrient = If( oDevice:nHorzSize() > oDevice:nVertSize(), 'L', 'P' )
oPdf = fwPdf():New( cPdf, cOrient, nQuality, nDensity )
AEval( oDevice:aMeta, { | cMeta | oPdf:AddMeta( cMeta ) } )
oPdf:Close()
CursorArrow()
DEFAULT lOpen := MsgYesNo( If( FWLanguageID() == 2, FWString( "¿" ) + " ", "" ) + ;
FWString( "View" ) + ;
" " + cPDF + " " + FWString( "(Y/N)" ) + " ?",;
FWString( "Please select" ) )
if lOpen
ShellExecute( IfNil( hWnd, GetWndDefault() ), "open", cPDF )
endif
else
cPDF := nil
endif
return cPDF
static function Emf2Jpeg( cEMF , nCalidad, nDensity )
local cJpeg := cFileSetExt( cEMF, "jpg" )
local cBuf, lRet := .f.
DEFAULT nCalidad := 20
DEFAULT nDensity := 300
NewEMFtoJPG ( cEMF , cJPeg , nCalidad, nDensity )
cBuf := If( File( cJpeg ), MemoRead( cJpeg ), "" )
FErase( cJpeg )
return cBuf
Function NewEMFtoJPG ( cFileIni , cFileFin , nQuality, nDensity )
local hbmp
local cBuffer
local obmp:=GDIbmp():new() // inicializa sistema gdi+
DEFAULT nQuality := 100
DEFAULT nDensity := 300
if upper(right(cfileIni,3)) == "EMF"
GDIPLUSEMFTOJPG( cFileIni , AllTrim( cFileFin ) , nQuality, nDensity )
endif
Return nil
HB_FUNC( GDIPLUSEMFTOJPG )
{
FILE * fil = fopen ( hb_parc(1) , "rb" ) ;
fseek ( fil , 0 , SEEK_END ) ;
int filesize = ftell ( fil ) ;
fseek ( fil , 0 , SEEK_SET ) ;
HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;
char * adr = (char *)GlobalLock ( hglobal ) ;
int nbytes = fread ( adr , 1 , filesize , fil ) ;
fclose ( fil ) ;
if ( nbytes != filesize )
{
MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );
} ;
LPSTREAM pstm = NULL ;
GlobalUnlock ( hglobal ) ;
CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ;
Metafile * original = new Metafile( pstm ) ;
LPWSTR filefin = AnsiToWide( ( char * ) hb_parc( 2 ) );
long quality = hb_parnl(3) ;
double nDensity = hb_parnl(4) ;
int nWidth = original->GetWidth() ;
int nHeight = original->GetHeight() ;
CLSID EncoderQuality ;
double nAlto ;
double nAncho ;
if ( nWidth > nHeight )
{
nAlto = ( 210 * nDensity ) / 25.4 ;
nAncho = ( 297 * nDensity ) / 25.4 ;
}
else
{
nAncho = ( 210 * nDensity) / 25.4 ;
nAlto = ( 297 * nDensity ) / 25.4 ;
}
nHeight = (int) nAlto ;
nWidth = (int) nAncho ;
Bitmap * newImage = new Bitmap(nWidth, nHeight );
newImage->SetResolution( nDensity, nDensity );
Graphics * g = new Graphics( newImage );
g->Clear( Color::White ) ;
g->SetSmoothingMode( SmoothingModeAntiAlias );
g->DrawImage( original,0, 0, nWidth, nHeight);
CLSIDFromString( L"{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}", &EncoderQuality ) ;
EncoderParameters encoderParameters;
encoderParameters.Count = 1;
encoderParameters.Parameter[0].Guid = EncoderQuality ;
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1;
encoderParameters.Parameter[0].Value = &quality ;
CLSID cClsid ;
CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;
newImage->Save( filefin , &cClsid, &encoderParameters );
delete newImage ;
delete g ;
delete original ;
pstm->Release();
}
mastintin wrote:Depending on the case .
To print directly to pdf I use Tharupdf code to build printer job.
For Preview, i use Standard code from fivewin .
I have a small modification in prv2pdf.prg code to determine Quality and density in images in pdf files ( use gdiplus code )
- Code: Select all Expand view RUN
function FWSavePreviewToPDF( oDevice, cPDF, lOpen, lQuality, nQuality ) // oDevice can be oPrinter or oPreview
local cOrient, oPDF
local hWnd
LOCAL aDatos:= {}
DEFAULT lQuality := .f.
IF Empty( nQuality )
nQuality := 50
nDensity := 300
lQuality := .t.
ENDIF
if lQuality
EDITVARS nQuality,nDensity TITLE "Atencion" PROMPTS "Calidad", "Densidad" ;
PICTURES "999", "999"
// aDatos:= { @nQuality, @nDensity }
// MsgGet( "Atencion",{ "Calidad", "Densidad" }, aDatos ) // @nQuality )
endif
if oDevice:IsKindOf( "TPREVIEW" )
hWnd := oDevice:oWnd:hWnd
oDevice := oDevice:oDevice
endif
DEFAULT cPDF := cGetFile( FWString( "PDF files | *.pdf |" ),;
FWString( "Select PDF File to Save" ),, ;
CurDir(), .T.,,,;
hb_CurDrive() + ":\" + CurDir() + "\" + ;
If( oDevice:IsKindOf( "TPreview" ),;
oDevice:cName, oDevice:cDocument ) + ".pdf" )
if ! Empty( cPDF )
cPDF = cFileSetExt( cPDF, "pdf" )
CursorWait()
cOrient = If( oDevice:nHorzSize() > oDevice:nVertSize(), 'L', 'P' )
oPdf = fwPdf():New( cPdf, cOrient, nQuality, nDensity )
AEval( oDevice:aMeta, { | cMeta | oPdf:AddMeta( cMeta ) } )
oPdf:Close()
CursorArrow()
DEFAULT lOpen := MsgYesNo( If( FWLanguageID() == 2, FWString( "¿" ) + " ", "" ) + ;
FWString( "View" ) + ;
" " + cPDF + " " + FWString( "(Y/N)" ) + " ?",;
FWString( "Please select" ) )
if lOpen
ShellExecute( IfNil( hWnd, GetWndDefault() ), "open", cPDF )
endif
else
cPDF := nil
endif
return cPDF
- Code: Select all Expand view RUN
static function Emf2Jpeg( cEMF , nCalidad, nDensity )
local cJpeg := cFileSetExt( cEMF, "jpg" )
local cBuf, lRet := .f.
DEFAULT nCalidad := 20
DEFAULT nDensity := 300
NewEMFtoJPG ( cEMF , cJPeg , nCalidad, nDensity )
cBuf := If( File( cJpeg ), MemoRead( cJpeg ), "" )
FErase( cJpeg )
return cBuf
- Code: Select all Expand view RUN
Function NewEMFtoJPG ( cFileIni , cFileFin , nQuality, nDensity )
local hbmp
local cBuffer
local obmp:=GDIbmp():new() // inicializa sistema gdi+
DEFAULT nQuality := 100
DEFAULT nDensity := 300
if upper(right(cfileIni,3)) == "EMF"
GDIPLUSEMFTOJPG( cFileIni , AllTrim( cFileFin ) , nQuality, nDensity )
endif
Return nil
- Code: Select all Expand view RUN
HB_FUNC( GDIPLUSEMFTOJPG )
{
FILE * fil = fopen ( hb_parc(1) , "rb" ) ;
fseek ( fil , 0 , SEEK_END ) ;
int filesize = ftell ( fil ) ;
fseek ( fil , 0 , SEEK_SET ) ;
HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;
char * adr = (char *)GlobalLock ( hglobal ) ;
int nbytes = fread ( adr , 1 , filesize , fil ) ;
fclose ( fil ) ;
if ( nbytes != filesize )
{
MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );
} ;
LPSTREAM pstm = NULL ;
GlobalUnlock ( hglobal ) ;
CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ;
Metafile * original = new Metafile( pstm ) ;
LPWSTR filefin = AnsiToWide( ( char * ) hb_parc( 2 ) );
long quality = hb_parnl(3) ;
double nDensity = hb_parnl(4) ;
int nWidth = original->GetWidth() ;
int nHeight = original->GetHeight() ;
CLSID EncoderQuality ;
double nAlto ;
double nAncho ;
if ( nWidth > nHeight )
{
nAlto = ( 210 * nDensity ) / 25.4 ;
nAncho = ( 297 * nDensity ) / 25.4 ;
}
else
{
nAncho = ( 210 * nDensity) / 25.4 ;
nAlto = ( 297 * nDensity ) / 25.4 ;
}
nHeight = (int) nAlto ;
nWidth = (int) nAncho ;
Bitmap * newImage = new Bitmap(nWidth, nHeight );
newImage->SetResolution( nDensity, nDensity );
Graphics * g = new Graphics( newImage );
g->Clear( Color::White ) ;
g->SetSmoothingMode( SmoothingModeAntiAlias );
g->DrawImage( original,0, 0, nWidth, nHeight);
CLSIDFromString( L"{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}", &EncoderQuality ) ;
EncoderParameters encoderParameters;
encoderParameters.Count = 1;
encoderParameters.Parameter[0].Guid = EncoderQuality ;
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1;
encoderParameters.Parameter[0].Value = &quality ;
CLSID cClsid ;
CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;
newImage->Save( filefin , &cClsid, &encoderParameters );
delete newImage ;
delete g ;
delete original ;
pstm->Release();
}
hua wrote:Oh ok then. I thought FWH is using something other than Haru pdf
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: nageswaragunupudi and 35 guests