Page 1 of 2

Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 12:26 pm
by edk
Hello.
I need to make a PDF file that will have plenty of EAN and QR codes.
I can do this in a classic way by writing the generated code from HMG_Zebra to a .png file and inserting it into a HPDFDOC by loading this file.
But this causes a lot of writes, reads and deletes on the HDD.

I tried using HPDF_Page_DrawImage (), but this requires pointing out the "pointer" of allocating bitmap in memory.
I do not know if is possible to read/convert the pointer with a bitmap handler.

Code: Select all

#include "hmg.ch"

Procedure Main
Local cEan:='20763015'
Local cImgFile:=TEMPFILE(,'png')
Local hBitMap, nImgWidth, nImgHeight
Local lSuccess := .f.

SELECT HPDFDOC "test.pdf" TO lSuccess PAPERSIZE HPDF_PAPER_A4
IF lSuccess
	SET HPDFDOC COMPRESS ALL
	SET HPDFDOC PAGEMODE TO OUTLINE

	START HPDFDOC
		START HPDFPAGE

			hBitMap := HMG_CreateBarCode(cEan,"EAN8", 1, 15, .F., '', {0, 0, 0}, {255,255,255}, .F., .F. , .F.)
			IF hBitMap <> 0
				nImgWidth:=(BT_BitmapWidth(hBitmap) / 96) * 25.4
				nImgHeight:=(BT_BitmapHeight(hBitmap) / 96) * 25.4
				BT_BitmapSaveFile (hBitmap, cImgFile, BT_FILEFORMAT_PNG)
				BT_BitmapRelease ( hBitmap )
				@ 10, 10 HPDFPRINT IMAGE cImgFile WIDTH nImgWidth HEIGHT nImgHeight TYPE PNG
			ENDIF
			FErase(cImgFile)

		END HPDFPAGE
	END HPDFDOC		
ENDIF
Any ideas?
Regards, Edward.

Re: Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 12:35 pm
by Rathinagiri
I am sure Claudio can help in this regard.

Re: Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 6:53 pm
by EduardoLuis
Hi Edward:

You don't nee to complex code, please check this lines (you must adapt to your needs).-
With them i solve my needs of printing QRCode using field contents of one or multiple tables.-
Just a sample, that may solve your needs.-
With regards.
Eduardo

Please forgive me, i don't know how to insert a code on a post.-
Eduardo


#include <hmg.ch>
#include "hfcl.ch"

PROCEDURE pdf_create_recibi



local lSuccess := .f.
local jacinto := .T.
local cLB := chr( 10 )
local minus := 120

PRIVATE letra := 1
PRIVATE totalregistros
PRIVATE nohaymas := 'N'
PRIVATE pagxpag := 1

PRIVATE valor := "What you want to codify for example 26/02/2017 $ 253.125,=="




SELECT HPDFDOC 'RECIBI.pdf' TO lSuccess papersize HPDF_PAPER_A4
SET HPDFDOC COMPRESS ALL
SET HPDFINFO AUTHOR TO 'Formular'
SET HPDFINFO CREATOR TO 'Formular'
SET HPDFINFO TITLE TO 'Formular'
SET HPDFINFO SUBJECT TO 'Formular'
SET HPDFINFO KEYWORDS TO 'Formular'
SET HPDFINFO DATECREATED TO date() TIME time()

if lSuccess
START HPDFDOC

SET HPDFDOC ENCODING TO "CP1252"


START HPDFPAGE

////// PUT HERE YOUR CODE TO BE PRINTED, FOR EXAMPLE :

// Asign value to a variable
// valor := "What you want to codify for example 26/02/2017 $ 253.125,=="
// valor := "What you want for text " + ALLTRIM(str(TABLE->NUM)) + " CASH " + DTOC(date())

// generate the QRCODE with QR_CREATOR()
//

// IN CASE OF NEED PRINTING QRCODE GRAPHIC INSERT THIS LINE:

@ 99, 15 HPDFPRINT IMAGE 'CODE.PNG' width 25 height 25

END HPDFPAGE

END HPDFDOC
endif

// terminado := 'S'
// EXECUTE file 'RECIBI.pdf'


return nil


PROCEDURE QR_CREATOR

HMG_CreateBarCode( valor ,;
"QRCODE",;
3,;
120,;
.F.,;
"CODE.PNG",;
{ 7 , 71 , 41 },;
{ 255 , 255 , 255 },;
.T.,; // checksum
.F.,; // wide2_5
.F. ) // wide3

RETURN

Re: Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 7:14 pm
by edk
Dear Eduardo, thank you for your post.

I know how to create QRcode using png file.
I'm looking for solutions how to do it without creating png file ;)

Edward.

Re: Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 10:14 pm
by apais
you can use the ZEBRA library

Re: Barcodes in PDF without saving to file.

Posted: Fri Aug 04, 2017 10:21 pm
by apais
This is an extract from rqpdf utility by Mario Wanstandic...

Code: Select all

FUNCTION QPDF_Draw_Zebra( nLin, nCol, nWidth, nHeight, cCode, nZebraType, nZebraFlag )
   hb_Default( @nZebraType, HB_ZEBRA_TYPE_CODE128 )

   /////////////////////////////////////////////////////////////////////////////
   // Create the barcode handler

   IF nZebraType == HB_ZEBRA_TYPE_EAN13
      M->hZebra := hb_Zebra_Create_EAN13( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_EAN8
      M->hZebra := hb_Zebra_Create_EAN8( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_UPCA
      M->hZebra := hb_Zebra_Create_UPCA( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_UPCE
      M->hZebra := hb_Zebra_Create_UPCE( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE128
      M->hZebra := hb_Zebra_Create_CODE128( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE93
      M->hZebra := hb_Zebra_Create_CODE93( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE39
      M->hZebra := hb_Zebra_Create_CODE39( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE11
      M->hZebra := hb_Zebra_Create_CODE11( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODABAR
      M->hZebra := hb_Zebra_Create_CODABAR( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_ITF
      M->hZebra := hb_Zebra_Create_ITF( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_MSI
      M->hZebra := hb_Zebra_Create_MSI( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_PDF417
      M->hZebra := hb_Zebra_Create_PDF417( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_DATAMATRIX
      M->hZebra := hb_Zebra_Create_DATAMATRIX( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_QRCODE
      M->hZebra := hb_Zebra_Create_QRCODE( cCode, nZebraFlag )
   ENDIF

   /////////////////////////////////////////////////////////////////////////////
   // Verify the code
   IF hb_Zebra_GetError( M->hZebra ) != 0
      RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
   ENDIF

   /////////////////////////////////////////////////////////////////////////////
   // Draw barcode
   hb_Zebra_Draw( M->hZebra, {| x, y, w, h | HPDF_Page_Rectangle( M->hPage, x, y, w, h ) }, nCol, (QPDF_Get_Height()-nLin)-nHeight, nWidth, nHeight )
   HPDF_Page_Fill( M->hPage )
   hb_Zebra_Destroy( M->hZebra )

RETURN 0

Re: Barcodes in PDF without saving to file.

Posted: Sat Aug 05, 2017 2:58 am
by andyglezl
Hola Edward
Quizá esto ayude...
-----------------------------------------------
Hi, Edward
Maybe this will help ...


http://www.hmgforum.com/viewtopic.php?f=6&t=5308

Re: Barcodes in PDF without saving to file.

Posted: Sat Aug 05, 2017 6:20 am
by edk
apais wrote:
Fri Aug 04, 2017 10:21 pm
This is an extract from rqpdf utility by Mario Wanstandic...

Code: Select all

FUNCTION QPDF_Draw_Zebra( nLin, nCol, nWidth, nHeight, cCode, nZebraType, nZebraFlag )
   hb_Default( @nZebraType, HB_ZEBRA_TYPE_CODE128 )

   /////////////////////////////////////////////////////////////////////////////
   // Create the barcode handler

   IF nZebraType == HB_ZEBRA_TYPE_EAN13
      M->hZebra := hb_Zebra_Create_EAN13( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_EAN8
      M->hZebra := hb_Zebra_Create_EAN8( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_UPCA
      M->hZebra := hb_Zebra_Create_UPCA( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_UPCE
      M->hZebra := hb_Zebra_Create_UPCE( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE128
      M->hZebra := hb_Zebra_Create_CODE128( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE93
      M->hZebra := hb_Zebra_Create_CODE93( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE39
      M->hZebra := hb_Zebra_Create_CODE39( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODE11
      M->hZebra := hb_Zebra_Create_CODE11( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_CODABAR
      M->hZebra := hb_Zebra_Create_CODABAR( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_ITF
      M->hZebra := hb_Zebra_Create_ITF( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_MSI
      M->hZebra := hb_Zebra_Create_MSI( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_PDF417
      M->hZebra := hb_Zebra_Create_PDF417( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_DATAMATRIX
      M->hZebra := hb_Zebra_Create_DATAMATRIX( cCode, nZebraFlag )
   ELSEIF nZebraType ==  HB_ZEBRA_TYPE_QRCODE
      M->hZebra := hb_Zebra_Create_QRCODE( cCode, nZebraFlag )
   ENDIF

   /////////////////////////////////////////////////////////////////////////////
   // Verify the code
   IF hb_Zebra_GetError( M->hZebra ) != 0
      RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
   ENDIF

   /////////////////////////////////////////////////////////////////////////////
   // Draw barcode
   hb_Zebra_Draw( M->hZebra, {| x, y, w, h | HPDF_Page_Rectangle( M->hPage, x, y, w, h ) }, nCol, (QPDF_Get_Height()-nLin)-nHeight, nWidth, nHeight )
   HPDF_Page_Fill( M->hPage )
   hb_Zebra_Destroy( M->hZebra )

RETURN 0
Thank you Angel.
I'm very glad for the tip. :)

Re: Barcodes in PDF without saving to file.

Posted: Sat Aug 12, 2017 9:16 am
by quartz565
Hi Edward, Angel,

It is possible to write a little complete example in PDF with code128 and text "12345678" ?

regards,

Νίκος

Re: Barcodes in PDF without saving to file.

Posted: Sat Aug 12, 2017 2:01 pm
by apais
I can't post code that's not mine ...