Petr,
I cannot find the fileformat_pdf.tBasicU file.
Bill
If you could use some PDF creation from script, please read on
I converted the original José Roca's Haru Free PDF Library 2.1.0 headers to ThinBASIC. As the library requires callback for code handling I created high level wrapper, which makes the PDF creation a bit easier. Here sample code:
You can download the converted headers + my special wrapper + sample code from the attachement of this post. I hope you will find use for it.' ' Test of PDF wrapper ' Uses "Console", "Math" #INCLUDE "fileformat_pdf.tBasicU" Function TBMain() ' -- Initialize library pdf_InitLibrary() ' -- Create document String sPDFFile = APP_SourcePath + "Test.pdf" tPdfDocument hDocument = pdf_CreateDocument() ' -- Font used String fArialName = pdf_GetFontNameFromTTF(hDocument, "C:\Windows\Fonts\arial.ttf", TRUE) tPdfFont fArial = pdf_CreateFont(hDocument, fArialName , "CP1250") ' -- Create page and retrieve the dimensions tPdfPage hPage tPdfNumber nHeight, nWidth hPage = pdf_AddPage(hDocument) pdf_GetPageSize(hPage, nWidth, nHeight) ' -- Create content - the coordinates are as in math: ' -- 0,0 is lower left corner ' -- Draw rectangle, with different contour and content pdf_SetStrokeColor(hPage, Rgb(96,96,96)) pdf_SetFillColor(hPage, Rgb(224,224,224)) pdf_DrawRectangle(hPage, 10, nHeight-10, nWidth-20, nHeight-20) ' -- Draw cross inside it, using 3px orange line pdf_SetStrokeColor(hPage, Rgb(255,128,64)) pdf_SetLineWidth(hPage, 3) pdf_DrawLine(hPage, 10, 10, nWidth-10, nHeight-10) pdf_DrawLine(hPage, 10, nHeight-10, nWidth-10, 10) ' -- Write text Long i pdf_SetFillColor(hPage, Rgb(0, 0, 0)) For i = 1 To 8 pdf_SetFont (hPage, fArial, 10+i*2) pdf_PrintText(hPage, 225, nHeight-20-i*(10+i*2), "Hello ThinBASIC!") Next ' -- Draw polygon Long radius For radius = 160 To 10 Step - 10 pdf_SetColor(hPage, Rgb(Rnd(128,255), Rnd(128,255), Rnd(128,255))) pdf_BeginPoly(hPage, nWidth/2, nHeight/2) For i = 0 To 360 Step 60 pdf_AddPoly(hPage, nWidth/2+Cos(DegToRad(i))*radius, nHeight/2+Sin(DegToRad(i))*radius) Next pdf_EndPoly(hPage, TRUE) Next ' -- Draw image pdf_DrawImage(hDocument, hPage, nWidth/2-64, nHeight/2-256, APP_SourcePath+"picture.png", 128, 128 ) ' -- Save to disk pdf_SaveDocument(hDocument, sPDFFile) PrintL PrintL "File saved as:" PrintL sPDFFile PrintL PrintL "Press any key to quit..." WaitKey ' -- Release document from memory pdf_ReleaseDocument(hDocument) ' -- Release library pdf_ReleaseLibrary() End Function
The wrapper offers these functions, each is documented in the fileFormat_PDF.tBasicU file:
- pdf_InitLibrary, pdf_ReleaseLibrary
- pdf_CreateDocument, pdf_SaveDocument, pdf_ReleaseDocument
- pdf_AddPage, pdf_GetPageSize
- pdf_GetFontNameFromTTF, pdf_CreateFont, pdf_SetFont, pdf_PrintText
- pdf_SetStrokeColor, pdf_SetFillColor, pdf_SetColor
- pdf_SetLineWidth, pdf_SetLineStyle
- pdf_DrawRectangle, pdf_DrawLine, pdf_BeginPoly, pdf_AddPoly, pdf_EndPoly, pdf_DrawImage
Of course, the original headers from José offer even more power.
Petr
Last edited by Petr Schreiber; 30-08-2020 at 14:55.
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Petr,
I cannot find the fileformat_pdf.tBasicU file.
Bill
Hi Bilbo,
please download the PDF.ZIP from the first post, it contains:
- DemonstrationOfPDFCreation.tBasic (sample script)
- fileformat_PDF.tBasicU (my wrapper)
- hpdf (header)
- hpdf_consts (header)
- hpdf_types (hpdf_types)
- libhpdf.dll
- libpng13.dll
- picture.png (used by example)
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Petr,
Thanks. I was in a hurry and scanned the files in the zip
to fast.
Bill
Wow Petr, what a great code.
Thanks a lot.
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks, but the biggest work is done by the authors of the original library. Some of my functions are just 1:1 wrappers.
But I added even some other higher level abstractions to make the usage of the library more simple - and easy to read, in BASIC tradition
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Updated the first post to make it work in 2020 Please re-download the PDF.zip.
Petr
Last edited by Petr Schreiber; 30-08-2020 at 14:58.
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks