Barcodes in PDF without saving to file.

HMG Unicode versions 3.1.x related

Moderator: Rathinagiri

edk
Posts: 164
Joined: Thu Oct 16, 2014 11:35 am
DBs Used: DBF
Location: Poland
Has thanked: 43 times
Been thanked: 96 times

Barcodes in PDF without saving to file.

Post by edk » Fri Aug 04, 2017 12:26 pm

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.
Last edited by edk on Fri Aug 04, 2017 12:50 pm, edited 1 time in total.

User avatar
Rathinagiri
Posts: 5161
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 127 times
Been thanked: 129 times
Contact:

Post by Rathinagiri » Fri Aug 04, 2017 12:35 pm

I am sure Claudio can help in this regard.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

EduardoLuis
Posts: 517
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina
Been thanked: 28 times

Post by EduardoLuis » Fri Aug 04, 2017 6:53 pm

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

edk
Posts: 164
Joined: Thu Oct 16, 2014 11:35 am
DBs Used: DBF
Location: Poland
Has thanked: 43 times
Been thanked: 96 times

Post by edk » Fri Aug 04, 2017 7:14 pm

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.

User avatar
apais
Posts: 257
Joined: Fri Aug 01, 2008 6:03 pm
Location: uruguay
Has thanked: 23 times
Been thanked: 15 times
Contact:

Post by apais » Fri Aug 04, 2017 10:14 pm

you can use the ZEBRA library

User avatar
apais
Posts: 257
Joined: Fri Aug 01, 2008 6:03 pm
Location: uruguay
Has thanked: 23 times
Been thanked: 15 times
Contact:

Post by apais » 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

User avatar
andyglezl
Posts: 838
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 21 times
Contact:

Post by andyglezl » Sat Aug 05, 2017 2:58 am

Hola Edward
Quizá esto ayude...
-----------------------------------------------
Hi, Edward
Maybe this will help ...


http://www.hmgforum.com/viewtopic.php?f=6&t=5308
Andrés González López
Desde Guadalajara, Jalisco. México.

edk
Posts: 164
Joined: Thu Oct 16, 2014 11:35 am
DBs Used: DBF
Location: Poland
Has thanked: 43 times
Been thanked: 96 times

Post by edk » Sat Aug 05, 2017 6:20 am

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. :)

User avatar
quartz565
Posts: 443
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 103 times
Been thanked: 11 times
Contact:

Post by quartz565 » Sat Aug 12, 2017 9:16 am

Hi Edward, Angel,

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

regards,

Νίκος
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

User avatar
apais
Posts: 257
Joined: Fri Aug 01, 2008 6:03 pm
Location: uruguay
Has thanked: 23 times
Been thanked: 15 times
Contact:

Post by apais » Sat Aug 12, 2017 2:01 pm

I can't post code that's not mine ...

Post Reply