Page 2 of 3

Re: Preview a PDF con imagen de fondo

Posted: Wed Jun 19, 2024 11:43 pm
by sysctrl2
tampoco funciona directo:
PRINTER oPrn FILE cFilePdf

Code: Select all | Expand

#include "FiveWin.ch"
FUNCTION Main()
   //                1  2       3     4      5   6   7     8       9
   Local aDatos := {;
      {"Juan 1","Pago 1","Juan","Pedro","1000","Algo 1"},;
      {"Juan 2","Pago 2","Juan","Pedro","2000","Algo 2"},;
      {"Juan 3","Pago 3","Juan","Pedro","3000","Algo 3"},;
      {"Juan 4","Pago 4","Juan","Pedro","4000","Algo 4"},;
      {"Juan 5","Pago 5","Juan","Pedro","5000","Algo 5"},;
      {"Juan 6","Pago 6","Juan","Pedro","6000","Algo 6"},;
      {"Juan 7","Pago 7","Juan","Pedro","7000","Algo 7"};
      }
   ImprimoRecibos(aDatos)

RETURN nil

STATIC FUNCTION ImprimoRecibos( aDatos )

   LOCAL oPrn, oFont,n := 0, nRow, i := 1, aSizes
   LOCAL cFilePdf := cTempFile( ".\", ".pdf" )
   LOCAL cMsg := "Exportando a PDF: Aguarda un momento"

   DEFINE FONT oFont NAME "Arial" SIZE 36, 70

   //PRINT oPrn DOC "recibos"  PREVIEW
   PRINTER oPrn FILE cFilePdf // NAME 'SysCtrl CFDI Report'

   //aSizes := oPrn:Units2Pix(0,0,7.2,327.0,'CM')
   //xbrowse (aSizes)

   //oPrn:SetSize( aSizes[3], aSizes[4] )
   nRow := 4
   PAGE
   @ 0,0 PRINT TO oPrn IMAGE "logo.jpg" SIZE oPrn:nHorzRes(), oPrn:nVertRes() PIXEL GRAY
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,1] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,2] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,3] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,4] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,5] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn TEXT aDatos[i,6] SIZE 7,.5 CM FONT oFont LASTROW nRow ALIGN "C"
   @ nRow ,  1 PRINT TO oPrn IMAGE "..\bitmaps\olga1.jpg" SIZE 4, 4 CM LASTROW nRow
   ENDPAGE

   ENDPRINT

   MSGRUN( cMsg, "Usuario", {|| Shellexecute( 0,"open", cFilePdf )  } )

RETURN nil


Re: Preview a PDF con imagen de fondo

Posted: Fri Jun 21, 2024 11:14 am
by cmsoft
Efectivamente tampoco funciona directo.
Alguna idea de como solucionar esto?

Re: Preview a PDF con imagen de fondo

Posted: Fri Jun 21, 2024 12:08 pm
by karinha
Lo intenté de todas las formas posibles, pero no funciona porque el comando GRIS(GRAY) pinta toda la hoja INFORME. Si entiendo. jajajaja.

Quizás el Maestro RAO tenga una solución. Vamos esperar.

Regards, saludos.

Re: Preview a PDF con imagen de fondo

Posted: Fri Jun 21, 2024 12:11 pm
by cmsoft
Muchas gracias por las pruebas Jao!
Esperemos a ver que dice Mr. Rao
Saludos

Re: Preview a PDF con imagen de fondo

Posted: Mon Jun 24, 2024 11:57 am
by cmsoft
+1

Re: Preview a PDF con imagen de fondo

Posted: Thu Jul 04, 2024 4:46 am
by nageswaragunupudi
Asi se ve el PDF generado desde el preview
Entire page is filled with gray color.

It appears that MSWord is not installed on the target PC. In that case, fwh's own pdf function is used and this function is causing this problem.

You can avoid this by setting

Code: Select all | Expand

TPrinter():lUseHaruPDF := .t.
at the top of your program.

Please try this change and let us know.

Re: Preview a PDF con imagen de fondo

Posted: Thu Jul 04, 2024 4:53 am
by nageswaragunupudi
Next important issue.

You like to display the "fondo.jpg" in the background like a watermark.
For this purpose you can use GRAY or even better ALPHALEVEL <n>.

In this case, both preview and printing on printer works as expected, but the PDF still does not show the image as watermark.

This still remains a problem. I am unable to provide an immediate solution.
Note: I am unable to write Gray or Alpha levels to PDF using harupdf now.
We also have a function FWWATERMARK( hbmp ) but this does not seem to help either.

We will keep searching to a solution. We keep this in our TODO list.

However you can generate PDF using fondo.jpg without the entire page painted with Gray color.

Re: Preview a PDF con imagen de fondo

Posted: Thu Jul 04, 2024 10:50 am
by cmsoft
Muchas gracias Mr. Rao.
Aguardaré la solucion

Re: Preview a PDF con imagen de fondo

Posted: Thu Jul 04, 2024 11:33 am
by nageswaragunupudi
Please try this change and let us know.
Please also provide your feedback on this issue.

Re: Preview a PDF con imagen de fondo

Posted: Thu Jul 04, 2024 1:52 pm
by nageswaragunupudi
test-1
Note: DO NOT use harupdf.

Code: Select all | Expand

function test()

   local oPrn, oFont, nRow
   local hBmp, n

   hBmp := GrayFondo()

   PRINT oPrn PREVIEW
   oPrn:SetPage( 9 ) // A4 size

   DEFINE FONT oFont NAME "ARIAL" SIZE 0,-22  OF oPrn

   PAGE
   @ 1,0 PRINT TO oPrn IMAGE hBmp SIZE 7,nil INCHES

   nRow := 4
   for n := 1 to 12
      @ nRow, 2 PRINT TO oPrn TEXT NTOCMONTH( n ) INCHES FONT oFont LASTROW nRow
   next
   @ 4, 5.2 PRINT TO oPrn IMAGE "..\bitmaps\olga1.jpg" SIZE 2.5,3 INCHES ALIGN "" LASTROW nRow

   ENDPAGE

   ENDPRINT
   RELEASE FONT oFont
   DeleteObject( hBmp )

return nil

function GrayFondo()

   local hBmp, hGray

   hBmp  := FW_ReadImage( , "..\bitmaps\fondo.jpg" )[1]
   hGray := bmp2gray( hbmp )
   DeleteObject( hBmp )

return hGray
Image

We need to still lighten the water mark.
We will keep improving.
Please provide your feedback

Re: Preview a PDF con imagen de fondo

Posted: Fri Jul 05, 2024 3:16 pm
by cmsoft
Hice las pruebas. El resultado de la marca de agua es muy similar al enviado por Ud.
Lo que noto que el proceso de la previsualización tarda aproximadamente 25 segundos.
El PDF obtenido tiene la marca de agua ya sin el fondo gris.

Re: Preview a PDF con imagen de fondo

Posted: Fri Jul 05, 2024 5:04 pm
by nageswaragunupudi
cmsoft wrote:Hice las pruebas. El resultado de la marca de agua es muy similar al enviado por Ud.
Lo que noto que el proceso de la previsualización tarda aproximadamente 25 segundos.
El PDF obtenido tiene la marca de agua ya sin el fondo gris.
1) Does this serve your purpose for the time being?

2) We will keep working on it. Objectives: (a) Make the water-mark even lighter and (b) test with alpha too and (c) make it work with harupdf also.

Re: Preview a PDF con imagen de fondo

Posted: Sat Jul 06, 2024 8:04 am
by nageswaragunupudi
Image

Is this pdf okay now?

Re: Preview a PDF con imagen de fondo

Posted: Sat Jul 06, 2024 12:40 pm
by cmsoft
Este ultimo, se ver perfecto!
Como lo lograste?

Re: Preview a PDF con imagen de fondo

Posted: Sat Jul 06, 2024 2:48 pm
by nageswaragunupudi
You can easily do it for print-preview as well as printing on paper using the clause ALPHALEVEL <nAlpha> with the command PRINT IMAGE.
But till now, we have problems in saving this image as PDF.
FWH uses FWPDF class for saving to PDF using PdfHaru library.
FWH uses its FWPDF class to save PDF using HaruPDF. We did not handle alphalevel in the method printimage() of this class. Now we enhanced this class to handle alphalevel.
With this enhancement:

Code: Select all | Expand

function PdfAlpha()

   local oPrn, oFont, nRow
   local hBmp, n

   TPrinter():lUseHaruPdf := .t.

   PRINT oPrn PREVIEW

   oPrn:SetPage( 9 ) // A4 size
   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-22  OF oPrn

   PAGE
      @ 0,1 PRINT TO oPrn IMAGE "..\bitmaps\fondo.jpg" SIZE 7,10 INCHES ALIGN "" ALPHALEVEL 80
      nRow := 4
      for n := 1 to 12
         @ nRow, 2 PRINT TO oPrn TEXT NTOCMONTH( n ) SIZE 7,0.37 INCHES FONT oFont LASTROW nRow
      next
      @ 4.7, 5 PRINT TO oPrn IMAGE "..\bitmaps\pngs\2.png" SIZE 2.5,5 INCHES ALIGN "" ALPHALEVEL 150
   ENDPAGE

   ENDPRINT

   RELEASE FONT oFont

return nil
Image

Notes:
Works with enhanced FWPDF class only using lUseHaruPDF := .t.
Does not work with default pdf generator or even with the commercial image2pdf.

We will let you know the changes you need to make to FWPDF class in the next post