func (VS *Server) newPDFqr(c *gin.Context) {
	typeOfI, b := VS.getStringFromHTML(c, "typeofitem", "PDF")
	typeOfItem := TypeOfItem(typeOfI)
	if !b {
		return
	}
	pagesNumber, b := VS.getIntFromHTML(c, "pages", "PDF")
	if !b {
		return
	}
	// Change the color of the QR depending on the type of Item
	var color color.RGBA
	switch typeOfItem {
	case ServiceProduct:
		color = Pink
	case Tool:
		color = DarkBrown
	case PrimaryMaterial:
		color = Blue
	case Task:
		color = Green
	}
	var PDF PDF
	PDF.Date = time.Now().Unix()
	PDF.ID = bson.NewObjectId()
	PDF.Pages = pagesNumber
	PDF.TypeOfItem = typeOfItem
	PDF.TypeOfPDF = PDFQR
	VS.addElementToDatabaseWithoutRegister(c, PDF, PDF.ID, "h_reports", "newPDFqr", "PDF.TypeOfPDF = PDFQR ")
	// We create every page of the PDF
	var QRs []QR
	var QR QR
	var imagesToHTML []string
	var PDFpages []PDFPageqrHTML
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
	for page := 0; page < pagesNumber; page++ {
		pdf.AddPage()
		x, y := 20.0, 10.0
		for i, k := 0, 0; i < 77; i++ {
			// Create and add the ID in the DataBase
			QR.ID = bson.NewObjectId()
			QR.PDF = PDF.ID
			QR.PageNumber = page + 1
			QR.TypeOfItem = typeOfItem
			QRs = append(QRs, QR)
			VS.addElementToDatabaseWithoutRegister(c, QR, QR.ID, "h_reports", "newPDFqr", "QRs = append(QRs, QR)")

			// Create QR images and add to PDF
			qr, err := qrcode.New(QR.ID.Hex(), qrcode.High)
			if err != nil {
				fmt.Print(err)
			}
			qr.ForegroundColor = color
			qr.BackgroundColor = White
			img, err := qr.PNG(140)
			if err != nil {
				fmt.Print(err)
			}
			// convert []byte to image for saving to file
			image, _, _ := image.Decode(bytes.NewReader(img))
			//save the imgByte to file
			os.MkdirAll(basePath+"/local-resources/pdf/test/", os.ModePerm)

			out, err := os.Create(basePath + "/local-resources/pdf/test/" + QR.ID.Hex() + ".png")
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			err = png.Encode(out, image)
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			pdf.Image(basePath+"/local-resources/pdf/test/"+QR.ID.Hex()+".png", x, y, nil) //print image
			x += 75
			k++
			if k >= 7 {
				y += 75
				x = 20
				k = 0
			}
		}
		PDFpages = append(PDFpages, getPagePDFqr(imagesToHTML, PDF))
		QRs = nil
		imagesToHTML = nil
	}

	os.MkdirAll(basePath+"/local-resources/pdf/qr/", os.ModePerm)
	err := pdf.WritePdf(basePath + "/local-resources/pdf/qr/" + PDF.ID.Hex() + ".pdf")
	if err != nil {
		os.MkdirAll(basePath+"/local-resources/pdf/qr/", os.ModePerm)
		pdf.WritePdf(basePath + "/local-resources/pdf/qr/" + PDF.ID.Hex() + ".pdf")
	}
	fmt.Print("PDF done")
	// Delete the images of the QR that we created before
	os.RemoveAll(basePath + "/local-resources/pdf/test/")
	VS.goodFeedback(c, "reports/show-qr-codes")
}
// Creates the PDF for the QR codes
Creates the PDF for the QR codes
// Creates the PDF for the QR codes
func (VS *Server) newPDFqr(c *gin.Context) {
	typeOfI, b := VS.getStringFromHTML(c, "typeofitem", "PDF")
	typeOfItem := TypeOfItem(typeOfI)
	if !b {
		return
	}
	pagesNumber, b := VS.getIntFromHTML(c, "pages", "PDF")
	if !b {
		return
	}
	var color color.RGBA
	switch typeOfItem {
	case ServiceProduct:
		color = Pink
	case Tool:
		color = DarkBrown
	case PrimaryMaterial:
		color = Blue
	case Task:
		color = Green
	}
	var PDF PDF
	PDF.Date = time.Now().Unix()
	PDF.ID = bson.NewObjectId()
	PDF.Pages = pagesNumber
	PDF.TypeOfItem = typeOfItem
	PDF.TypeOfPDF = PDFQR
	VS.addElementToDatabaseWithoutRegister(c, PDF, PDF.ID, "h_reports", "newPDFqr", "PDF.TypeOfPDF = PDFQR ")
	var QRs []QR
	var QR QR
	var imagesToHTML []string
	var PDFpages []PDFPageqrHTML
	pdf := gopdf.GoPdf{}
	pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
	for page := 0; page < pagesNumber; page++ {
		pdf.AddPage()
		x, y := 20.0, 10.0
		for i, k := 0, 0; i < 77; i++ {
			QR.ID = bson.NewObjectId()
			QR.PDF = PDF.ID
			QR.PageNumber = page + 1
			QR.TypeOfItem = typeOfItem
			QRs = append(QRs, QR)
			VS.addElementToDatabaseWithoutRegister(c, QR, QR.ID, "h_reports", "newPDFqr", "QRs = append(QRs, QR)")
			qr, err := qrcode.New(QR.ID.Hex(), qrcode.High)
			if err != nil {
				fmt.Print(err)
			}
			qr.ForegroundColor = color
			qr.BackgroundColor = White
			img, err := qr.PNG(140)
			if err != nil {
				fmt.Print(err)
			}
			image, _, _ := image.Decode(bytes.NewReader(img))
			os.MkdirAll(basePath+"/local-resources/pdf/test/", os.ModePerm)
			out, err := os.Create(basePath + "/local-resources/pdf/test/" + QR.ID.Hex() + ".png")
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			err = png.Encode(out, image)
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			pdf.Image(basePath+"/local-resources/pdf/test/"+QR.ID.Hex()+".png", x, y, nil) 
			x += 75
			k++
			if k >= 7 {
				y += 75
				x = 20
				k = 0
			}
		}
		PDFpages = append(PDFpages, getPagePDFqr(imagesToHTML, PDF))
		QRs = nil
		imagesToHTML = nil
	}
	os.MkdirAll(basePath+"/local-resources/pdf/qr/", os.ModePerm)
	err := pdf.WritePdf(basePath + "/local-resources/pdf/qr/" + PDF.ID.Hex() + ".pdf")
	if err != nil {
		os.MkdirAll(basePath+"/local-resources/pdf/qr/", os.ModePerm)
		pdf.WritePdf(basePath + "/local-resources/pdf/qr/" + PDF.ID.Hex() + ".pdf")
	}
	fmt.Print("PDF done")
	os.RemoveAll(basePath + "/local-resources/pdf/test/")
	VS.goodFeedback(c, "reports/show-qr-codes")
}
func ( VS * Server ) newPDFqr ( c * gin . Context ) { typeOfI , b := VS . getStringFromHTML ( c , " " , " " ) typeOfItem := TypeOfItem ( typeOfI ) if ! b { return } pagesNumber , b := VS . getIntFromHTML ( c , " " , " " ) if ! b { return } var color color . RGBA switch typeOfItem { case ServiceProduct : color = Pink case Tool : color = DarkBrown case PrimaryMaterial : color = Blue case Task : color = Green } var PDF PDF PDF . Date = time . Now ( ) . Unix ( ) PDF . ID = bson . NewObjectId ( ) PDF . Pages = pagesNumber PDF . TypeOfItem = typeOfItem PDF . TypeOfPDF = PDFQR VS . addElementToDatabaseWithoutRegister ( c , PDF , PDF . ID , " " , " " , " " ) var QRs [ ] QR var QR QR var imagesToHTML [ ] string var PDFpages [ ] PDFPageqrHTML pdf := gopdf . GoPdf { } pdf . Start ( gopdf . Config { PageSize : * gopdf . PageSizeA4 } ) for page := 0 ; page < pagesNumber ; page ++ { pdf . AddPage ( ) x , y := 20.0 , 10.0 for i , k := 0 , 0 ; i < 77 ; i ++ { QR . ID = bson . NewObjectId ( ) QR . PDF = PDF . ID QR . PageNumber = page + 1 QR . TypeOfItem = typeOfItem QRs = append ( QRs , QR ) VS . addElementToDatabaseWithoutRegister ( c , QR , QR . ID , " " , " " , " " ) qr , err := qrcode . New ( QR . ID . Hex ( ) , qrcode . High ) if err != nil { fmt . Print ( err ) } qr . ForegroundColor = color qr . BackgroundColor = White img , err := qr . PNG ( 140 ) if err != nil { fmt . Print ( err ) } image , _ , _ := image . Decode ( bytes . NewReader ( img ) ) os . MkdirAll ( basePath + " " , os . ModePerm ) out , err := os . Create ( basePath + " " + QR . ID . Hex ( ) + " " ) if err != nil { fmt . Println ( err ) os . Exit ( 1 ) } err = png . Encode ( out , image ) if err != nil { fmt . Println ( err ) os . Exit ( 1 ) } pdf . Image ( basePath + " " + QR . ID . Hex ( ) + " " , x , y , nil ) x += 75 k ++ if k >= 7 { y += 75 x = 20 k = 0 } } PDFpages = append ( PDFpages , getPagePDFqr ( imagesToHTML , PDF ) ) QRs = nil imagesToHTML = nil } os . MkdirAll ( basePath + " " , os . ModePerm ) err := pdf . WritePdf ( basePath + " " + PDF . ID . Hex ( ) + " " ) if err != nil { os . MkdirAll ( basePath + " " , os . ModePerm ) pdf . WritePdf ( basePath + " " + PDF . ID . Hex ( ) + " " ) } fmt . Print ( " " ) os . RemoveAll ( basePath + " " ) VS . goodFeedback ( c , " " ) }
Creates the PDF for the QR codes
Creates the PDF for the QR codes
// Change the color of the QR depending on the type of Item // We create every page of the PDF // Create and add the ID in the DataBase // Create QR images and add to PDF // convert []byte to image for saving to file //save the imgByte to file //print image // Delete the images of the QR that we created before