Best way to print recipes

Everything else that doesn't fall into one of the other PB categories.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Best way to print recipes

Post by Fangbeast »

I've just about got 90% of my recipe program going thanks to InfraTec's writing of the import code, he was absolutely terrific.

And Kenmo's rating gadget make a great addition too.

But now I am turning my thoughts to printing and i realise that my normal method of 'filling in' a web template isn't good enough to get page and size controls to cater to the printer.

Ideally, I'd like to be able to print a recipe as I see them in magazines, mostly the photos in the top left, ingredients to the right and the instructions underneath it all.

What would be the best way of doing this?

Continue to use my web template with absolutely no control over the printing, pages etc, xml dialog for page control layout of the vector lib?

Does anyone have any ideas and some sample code to teach me what I should be doing?

I can beg if it helps and also lend you srod's abused goat collection!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: Best way to print recipes

Post by mhs »

The Vector Drawing lib is your friend :)

I just unfortunately no sample code at hand, but to make it works well.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Best way to print recipes

Post by Fangbeast »

mhs wrote:The Vector Drawing lib is your friend :)

I just unfortunately no sample code at hand, but to make it works well.
I understand your point but understand mine too, I am not good with graphics or maths so I need some concrete examples to follow or I just don't get it.

The web template way I do things is not good for this sort of thing, absolutely no control unless you know html off the top of your head.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Best way to print recipes

Post by IdeasVacuum »

Well essentially there are only the two most popular paper sizes to support, ANSI A (aka Letter) and ISO A4. ANSI A is 215.9 x 279.4 mm and ISO A4 is 210 x 297mm, so you can define a 'hybrid' margin (border) size to support both in 1 layout that will print on either size sheet.

So, I would consider using a Container to represent the paper, arrange an image gadget and two Editor gadgets in the layout you described for on-screen viewing and then translate this to printable output. You could indeed output a PDF, which is both shareable and printable - the print quality delivered by PDF + Adobe Reader is pretty good.
Last edited by IdeasVacuum on Sat Feb 27, 2016 12:46 am, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Best way to print recipes

Post by Fangbeast »

IdeasVacuum wrote: So, I would consider using a Container to represent the paper, arrange an image gadget and two Editor gadgets in the layout you described for on-screen viewing and then translate this to printable output. You could indeed output a PDF, which is both shareable and printable - the print quality delibered by PDF + Adobe Reader is pretty good.
i looked at the pdf stuff once, too complicated for my brain. But as I said above "so I need some concrete examples to follow or I just don't get it."

:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
TI-994A
Addict
Addict
Posts: 2771
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best way to print recipes

Post by TI-994A »

Fangbeast wrote:...I need some concrete examples to follow or I just don't get it.
Here's something I put together just for you!

Code: Select all

Procedure PrintRecipe(recipeName.s, image.i, ingredients.s, method.s)
  
  recipeTitleFont = LoadFont(#PB_Any, "Arial", 24, #PB_Font_Bold)
  recipeBodyFonts = LoadFont(#PB_Any, "Times New Roman", 14)
  recipeHeaderFonts = LoadFont(#PB_Any, "Times New Roman", 22, 
                               #PB_Font_Bold | #PB_Font_Italic)
  If PrintRequester()
    If StartPrinting("Fangbeast's Recipe Printer")  
      If StartVectorDrawing(PrinterVectorOutput(#PB_Unit_Millimeter))
        
        frameWidth = 1
        singleSpace = 5
        doubleSpace = 10
        pageMargin = 10
        pageWidth = VectorOutputWidth()
        pageHeight = VectorOutputHeight()
        
        imgAspect.d = ImageWidth(image) / ImageHeight(image)
        imgWidth.d = (pageWidth - (pageMargin * 2)) / 2
        imgHeight.d = imgWidth * imgAspect
        
        MovePathCursor(pageMargin, pageMargin)
        AddPathLine(pageWidth - (pageMargin * 2), 0, #PB_Path_Relative)
        AddPathLine(0, pageHeight - (pageMargin * 2), #PB_Path_Relative)
        AddPathLine(-(pageWidth - (pageMargin * 2)), 0, #PB_Path_Relative)
        AddPathLine(0, -(pageHeight - (pageMargin * 2)), #PB_Path_Relative)
        StrokePath(frameWidth, #PB_Path_SquareEnd)
        
        VectorFont(FontID(recipeTitleFont))
        VectorSourceColor(RGBA(0, 0, 155, 255))
        titleXMargin = (pageWidth - VectorTextWidth(recipeName)) / 2
        titleYMargin = pageMargin + singleSpace
        MovePathCursor(titleXMargin, titleYMargin)
        DrawVectorText(recipeName)
        
        startX = pageMargin + singleSpace
        startY = PathCursorY() + (singleSpace * 3)
        MovePathCursor(startX, startY)
        DrawVectorImage(ImageID(image), 255, imgWidth, imgHeight)
        imageBase = PathCursorY()
        
        startX = PathCursorX() + singleSpace
        VectorFont(FontID(recipeHeaderFonts))
        VectorSourceColor(RGBA(0, 0, 0, 255))
        MovePathCursor(startX, startY)
        DrawVectorText("Ingredients")
        
        startY = PathCursorY() + doubleSpace
        VectorFont(FontID(recipeBodyFonts))
        MovePathCursor(startX, startY)
        paragraphWidth = pageWidth - (startX + pageMargin + singleSpace)
        DrawVectorParagraph(ingredients, paragraphWidth, 150)
        
        startX = pageMargin + singleSpace
        startY = imageBase + doubleSpace
        VectorFont(FontID(recipeHeaderFonts))
        VectorSourceColor(RGBA(0, 0, 0, 255))
        MovePathCursor(startX, startY)
        DrawVectorText("Method")
        
        startY = PathCursorY() + doubleSpace
        VectorFont(FontID(recipeBodyFonts))
        MovePathCursor(startX, startY)
        paragraphWidth = pageWidth - ((pageMargin * 2) + doubleSpace)
        paragraphHeight = pageHeight - (startY + pageMargin)
        DrawVectorParagraph(method, paragraphWidth, paragraphHeight)
        
        StopVectorDrawing()
      EndIf
    EndIf
    StopPrinting()
  EndIf
  
EndProcedure


;demo for downloading sample recipe files from DropBox (requires PureBasic v5.4+)

UseJPEGImageDecoder()
InitNetwork()

Define.s ingredients, method, recipeName = "Mini Strawberry Cheesecakes"

ReceiveHTTPFile("https://www.dropbox.com/s/sd0xaeqybtehb1x/cheeseCake.jpg?dl=1",
                GetTemporaryDirectory() + "cheeseCake.jpg")
image = LoadImage(#PB_Any, GetTemporaryDirectory() + "cheeseCake.jpg")

ReceiveHTTPFile("https://www.dropbox.com/s/m2hnogqhab2b588/ingredients.txt?dl=1",
                GetTemporaryDirectory() + "ingredients.txt")
ReadFile(0, GetTemporaryDirectory() + "ingredients.txt")
While Not Eof(0)
  ingredients + ReadString(0) + #CRLF$
Wend
CloseFile(0)

ReceiveHTTPFile("https://www.dropbox.com/s/lh517igi6bddtgh/method.txt?dl=1",
                GetTemporaryDirectory() + "method.txt")
ReadFile(0, GetTemporaryDirectory() + "method.txt")
While Not Eof(0)
  method + ReadString(0) + #CRLF$
Wend
CloseFile(0)

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 300, "Recipe Printer", wFlags)
TextGadget(#PB_Any, 10, 10, 180, 20, "Raw ingredients text:", #PB_Text_Center)
TextGadget(#PB_Any, 200, 10, 180, 20, "Raw method text:", #PB_Text_Center)
TextGadget(#PB_Any, 400, 10, 180, 20, "Recipe image:", #PB_Text_Center)
SetGadgetText(EditorGadget(#PB_Any, 10, 30, 180, 180, #PB_Editor_WordWrap), ingredients)
SetGadgetText(EditorGadget(#PB_Any, 200, 30, 180, 180, #PB_Editor_WordWrap), method)
CopyImage(image, image2)
ResizeImage(image2, 180, 180)
ImageGadget(#PB_Any, 400, 30, 180, 180, ImageID(image2))
printButton = ButtonGadget(#PB_Any, 10, 250, 580, 40, "PRINT SAMPLE RECIPE")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case printButton
          PrintRecipe(recipeName, image, ingredients, method)           
      EndSelect
  EndSelect
Until appQuit = 1
And here's a sample printout:

Image

All you need is the PrintRecipe() procedure, passing it the recipe name, ingredients and method texts, and an image. The rest of it is simply for the demonstration, downloading the sample files, display the raw data, etc.

Not perfect, but hope you'd find it useful. :D
EDITS wrote:18th February 2019: updated download links
Last edited by TI-994A on Mon Aug 15, 2022 2:55 am, edited 2 times in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
juror
Enthusiast
Enthusiast
Posts: 249
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Best way to print recipes

Post by juror »

Impressive :shock:
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Best way to print recipes

Post by IdeasVacuum »

very 8)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Best way to print recipes

Post by Fangbeast »

That's beautiful. If my tiny pig brain caused by years of abusing srod's deformed sheep can understand it, I will be in pig heaven!!

That example is very sminky.

I can't wait to finish the million other things I have to do to this program to release it, it will look like magic.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Best way to print recipes

Post by davido »

@TI-994A,
Beautiful.
An impressive demonstration of printing with vector drawing library. 8)
Thank you for sharing.
DE AA EB
User avatar
TI-994A
Addict
Addict
Posts: 2771
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best way to print recipes

Post by TI-994A »

Thank you for all the kind words. I'm truly flattered, and I'm truly grateful. :D

Most of all, I'm so glad that you've found it good enough to include in your project, Fangbeast. Thank you.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4795
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Best way to print recipes

Post by Fangbeast »

TI-994A wrote:Thank you for all the kind words. I'm truly flattered, and I'm truly grateful. :D

Most of all, I'm so glad that you've found it good enough to include in your project, Fangbeast. Thank you.
Are you kidding me?? My tired brain couldn't code its way out of a diseased sheep's testicles to think of things like that so I put it in because it looks great and it works!! (I blame that srod for the diseased sheep).

Everything I do that I can't handle (and there is a lot!!) I yell loudly for to get help and nearly everything I do is a collaborative effort.

There are so many nice bits in this recipe manager now, hope that I can make it even better and give back to everyone for all the years of help.

My claim to fame is being a good assembler of bits and bobs, a trained monkey:):):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Best way to print recipes

Post by srod »

That is very nice TI-994A. When did the HTTP lib start supporting HTTPS? :shock:

Fangles, those goats and sheep were in pristine condition when you took delivery of them. They still had the wrapping on them for Pete's sake! Poor old Flossie was so traumatised on her return that she threw herself into the Lion's den at London zoo... but the Lion's threw her back as there is so little meat left on her!

I'd ask what you did to them, but then I'd likely be so traumatised that I would have to throw myself into the Lion's den as well!

Stick to abusing post boxes will you and leave the poor animals alone!
I may look like a mule, but I'm not a complete ass.
User avatar
TI-994A
Addict
Addict
Posts: 2771
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Best way to print recipes

Post by TI-994A »

srod wrote:That is very nice TI-994A. When did the HTTP lib start supporting HTTPS? :shock:
Thanks srod. Not sure on that one; all I know is that PureBasic's ReceiveHTTPFile() function stopped working with DropBox files one or two versions prior to 5.4, following some DropBox protocol change (please see this thread). However, even then, it appears to have worked on the HTTPS protocol.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply