Tasp
Full Member
Posts: 215
|
Post by Tasp on Sept 2, 2023 9:18:21 GMT -5
Hi All, I'm trying to create something that will create a PDF as per the image below. The only way I can think of at the minute is to create this in a graphics window and send it to the printer, and the default printer is set to M$ Create PDF's - this isn't ideal as obviously anyone else trying to print anything, just sends it to the PDF. Can't find anything by searching where anyone has created a PDF in LB, which is surprising. It would also be helpful if anyone has a simple way of creating the chart contained in the example as well?
|
|
|
Post by xxgeek on Sept 2, 2023 10:19:12 GMT -5
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Sept 2, 2023 11:00:06 GMT -5
Thanks xxgeek I'd just found similar on the LB forum. So you cannot add a BMP to a PDF, it has to be JPG (as I've read so far) I'm sure I had or found on Aylces Restaurant or similar an LB DLL API to convert BMP to JPG, I really would prefer not to use PS to do it, as it seems buggy at best. But I cannot find it anywhere?? This is what I have so far and it does create a blank document. NOMAINWIN 'Define company name and address CompanyAdd1$ = "Company Name" CompanyAdd2$ = "Address 1" CompanyAdd3$ = "Address 2" CompanyAdd4$ = "Address 3" CompanyAdd5$ = "Address 4" text$ = "!£$%^&*()_+-={}[]:@~;'#?><,./"
'Center Window UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
OPEN "Page" FOR Graphics AS #p #p, "autoresize" #p, "trapclose [QUIT]"
'Setup Address on page #p, "font Arial 19 bold ; color 0 112 192" #p, "place 20 30" #p, "\" + CompanyAdd1$ #p, "Font Arial 11 ; Color BLack" #p, "\" + CompanyAdd2$ #p, "\" + CompanyAdd3$ #p, "\" + CompanyAdd4$ #p, "\" + CompanyAdd5$
#p "flush" #p, "getbmp drawing 1 1 500 500" bmpsave "drawing", "bmpsave.bmp"
CALL GeneratePDF
WAIT
[QUIT] CLOSE #p STOP
SUB GeneratePDF
open "test.pdf" for output as #tf
print #tf,"%PDF-1.1" print #tf,"%????" print #tf,"1 0 obj" print #tf,"<<" print #tf,"/Kids [2 0 R]" print #tf,"/Type /Pages" print #tf,"/Count 1" print #tf,">>" print #tf,"endobj" print #tf,"2 0 obj" print #tf,"<<" print #tf,"/Rotate 0" print #tf,"/Parent 1 0 R" print #tf,"/MediaBox [0 0 792 ";(cl*20)+40;"]" print #tf,"/Resources 3 0 R" print #tf,"/Type /Page" print #tf,"/XObject/I1 32 0 R " print #tf,"/Contents [4 0 R]" print #tf,">>" print #tf,"endobj" print #tf,"32 0 obj " print #tf,"<</Name /I1" print #tf,"/Type /XObject" print #tf,"/Subtype" print #tf,"/Image" print #tf,"/Width 300" print #tf,"/Height 150" print #tf,"/Length 80000" print #tf,"/Filter" print #tf,"/DCTDecode" print #tf,"/ColorSpace" print #tf,"/DeviceRGB" print #tf,"/BitsPerComponent 8>>" print #tf,"stream"
open "bmpsave.bmp" for input as #fIn content$ =input$( #fIn, lof( #fIn)) close #fIn
print #tf,content$ print #tf,"endstream" print #tf,"endobj" print #tf,"3 0 obj " print #tf,"<<" print #tf,"/Font" print #tf,"<<" print #tf,"/F0" print #tf,"<<" print #tf,"/BaseFont /Arial" print #tf,"/Subtype /Type1" print #tf,"/Type /Font" print #tf,">>" print #tf,">>" print #tf,">>" print #tf,"endobj " print #tf,"4 0 obj " print #tf,"<<" print #tf,"/Length 121" print #tf,"/Filter/DCTDecode" print #tf,"/Type/XObject/" print #tf,"Length 33555/" print #tf,"Height 413/" print #tf,"BitsPerComponent 8/" print #tf,"Subtype/Image/'" print #tf,"Width 640" print #tf,"stream" print #tf,"endstream" print #tf,">>" print #tf,"stream" print #tf,"0.5 g" print #tf,"0 0 0 rg" print #tf,"BT" print #tf,"/F0 20 Tf" print #tf,"1 0 0 1 60 ";(cl*20)+40;" Tm" print #tf,"20 TL" print #tf,"() Tj T*"
'for i = 0 to cl step 1 'print #scr.te, "!line ";i;" linete$" ; 'print #tf,"2 Tr" 'print #tf,"(";linete$;") Tj T*" ' next i print #tf,"ET"
for dl = 1 to fl step 1 print #tf,"0 0 1 rg" print #tf," ";x1(dl)+xp;" ";(cl*20)-y1(dl)+yp;" m" print #tf," ";x2(dl)+xp;" ";(cl*20)-y2(dl)+yp;" l" print #tf," f" next dl
print #tf,"endstream" print #tf,"endobj" print #tf,"5 0 obj" print #tf,"<<" print #tf,"/Pages 1 0 R" print #tf,"/Type /Catalog" print #tf,">>" print #tf,"endobj xref" print #tf,"0 6"
''rint #tf,"0000000000 65535 f"
''print #tf,"0000000015 00000 n"
''print #tf,"0000000074 00000 n"
''print #tf,"0000000192 00000 n"
''print #tf,"0000000291 00000 n"
''print #tf,"0000000466 00000 n"
print #tf,"trailer" print #tf,"" print #tf,"<<" print #tf,"/Root 5 0 R" print #tf,"/Size 6" print #tf,">>" print #tf,"startxref" print #tf,"516" print #tf,"%%EOF" close #tf END SUB
Edit: PDF code nicked from here
|
|
|
Post by xxgeek on Sept 2, 2023 11:53:16 GMT -5
|
|
|
Post by xxgeek on Sept 2, 2023 12:45:37 GMT -5
Does this line actually convert to jpg, or is this just a windows trick?
run "cmd.exe /c ren bmpsave.bmp bmpsave.jpg", hide
I know it renames it to jpg, and it shows up in an image viewer ok, but is it truly in jpg format?
Just trying to help. I see you're going from bmp to jpg, and not the other way. My last post to the dll probably won't help, as it states it converts jpg to bmp.
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Sept 2, 2023 13:30:11 GMT -5
Yeah image323 just converts one way, jpg to bmp. I've used that plenty in the past.
The cmd REN just renames the image, I would assume your image program is just showing it irrelevant from the extension. no conversion takes place.
I've been trawling through some PDF docs to see if there's a way just to insert the BMP, as I assume it doesn't care on the format originally, however it quite hard to find, as most searches just show software or online tools. I need this to happen natively within LB.
|
|
|
Post by xxgeek on Sept 2, 2023 13:44:24 GMT -5
Yeah, That was a youtube find, and the comments were all praising the guy for the conversion lol I've been looking too, not much out there except 3rd party apps.
Powershell has a function for converting, but you say you don't want that either.
Doesn't look good, but maybe someone else can help with an api.
|
|
|
Post by Walt Decker on Sept 2, 2023 16:10:39 GMT -5
I have code that will change just about any image format to any other format. However, I would have to put it in a dll because it uses Windows(tm) gdi+ and gdi+ requires wide string characters (unicode).
|
|
|
Post by tsh73 on Sept 2, 2023 16:55:43 GMT -5
It looks BMP could be inserted, kind of. (but to get exact thing you want it might need some prior treatment) I started with code from linked thread that inserts webcam-image.jpg (created by Paint) Then I changed JPG image to BMP I used size 64x64 print #ti,"/Width 64" print #ti,"/Height 64" I think width divisible by 4 is safe (somehow 50x50 did not worked for me, it looked like each line has some extra pixels) Used (Paint default )24 bit BMP I commented out line print #ti,"/Filter /DCTDecode" which marked image as JPEG file and put not whole content$ but only image data print #ti,mid$(content$ ,54) 'offset to data Here's what I got I see * picture is upside down (well, it is known that BMP actually stores image upside down) * R and B colors are reversed (I have no idea how to fix that. Read bitmap back and change R and B bytes in each RGB triplet?) But I was able to flip image to normal orientation by adding "-" in this line 'print #ti,"1 0 0 1 0 0 cm" print #ti,"1 0 0 -1 0 0 cm"
Though it is obvious that image is moved down It could be helped too, ("q" command has first line - position, second - scale. I changed only scale) but it requires some reading on PDF So it is doable. Does it worth the troubles? Besides, point with putting JPG was - compression Uncompressed bitmaps are HUGE, so will be PDF (though it might ZIP nicely, not as small as JPG anyway)
|
|
|
Post by metro on Sept 2, 2023 18:54:55 GMT -5
html could be an option, you could display it within your program using Alyces browser3.dll (if it needs to be seen) libertybasiccom.proboards.com/post/4004and have a <create PDF> button to send the html to a commandline converter wkhtmltopdf.org/I have not had the need to use the converter, preferring to just stick with html. I insert charts with Googles help
DIM H1$(20) DIM F1$(20) DIM D$(20)
D$(0)="CODE_NUMBER" D$(1)="4-1100_10" D$(2)="4-1101_57" D$(3)="4-1102_11" D$(4)="4-1103_8" D$(5)="4-1104_2" D$(6)="4-1105_28" D$(7)="4-1106_2" D$(8)="4-1108_2" D$(9)="4-1110_2" D$(10)="4-1205_3"
H1$(1)="<html>"
H1$(2)= "<script type=";chr$(34);"text/javascript";chr$(34); "src=";chr$(34);"https://www.gstatic.com/charts/loader.js";chr$(34);"></script>"
H1$(3)="<body>" H1$(4)="<div id=";chr$(34);"myChart";chr$(34);"style=";chr$(34);"width:100%; max-width:350px; height:250px;";chr$(34);"></div>" H1$(5)=" " H1$(6)="<script>" H1$(7)="google.charts.load('current', {'packages':['corechart']});" H1$(8)="google.charts.setOnLoadCallback(drawChart);" H1$(9)=" " H1$(10)="function drawChart() {" H1$(11)="var data = google.visualization.arrayToDataTable(["
F1$(1)="]);" F1$(2)=" " F1$(3)="var options = {" F1$(4)=" title:'Sales by Product Code'" F1$(5)="};" F1$(6)=" " F1$(7)="var chart = new google.visualization.BarChart(document.getElementById('myChart'));" F1$(8)=" chart.draw(data, options);" F1$(9)= "}" F1$(10)="</script>" F1$(11)="</body>" F1$(12)="</html>"
for h = 1 to 11 print H1$(h) next print "['";WORD$(D$(0),1,"_");"','";WORD$(D$(0),2,"_");"'],"
for d= 1 to 10 DL$(d)="['";WORD$(D$(d),1,"_");"',";WORD$(D$(d),2,"_");"]," print DL$(d) NEXT
for f = 1 to 12 print F1$(f) next
alycesrestaurant.com/lbpe/SaveJPG.html
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Sept 3, 2023 5:24:25 GMT -5
Ok so I was working using the wrong snippet of code!!! I was using the #tf which brings the info from the textbox rather than the image (time wasted there) The correct code is in the #ti segment; SUB GeneratePDF OPEN "test.pdf" FOR OUTPUT AS #ti
print #ti,"%PDF-1.5" print #ti,"%??" print #ti,""
print #ti,"8 0 obj" print #ti,"<<" print #ti,"/Type /Page/Parent 2 0 R" print #ti,"/Rotate 0" print #ti,"/MediaBox [0 0 1600 1900]/CropBox [0 0 595 842]" print #ti,"/Resources<</ProcSet[/PDF/Text]" print #ti,"/Font<</T1 3 0 R/T2 4 0 R/T3 5 0 R/T4 6 0 R>>" print #ti,"/XObject <</I1 10 0 R >>>>" print #ti,"/Contents 9 0 R" print #ti,">>" print #ti,"endobj" print #ti,""
print #ti,"9 0 obj<</Length 989" print #ti,">>stream" print #ti,"q" print #ti,"144 0 0 100 10 700 cm" print #ti,"1 0 0 1 0 0 cm" print #ti,"/I1 Do" print #ti,"Q" print #ti,"BT/T3 12 Tf" print #ti,"100 650 Td" print #ti,"(Greetings from code) Tj" print #ti,"ET" print #ti,"endstream" print #ti,"endobj" print #ti,""
print #ti,"1 0 obj<</Type /Catalog/Lang(EN-US)/Pages 2 0 R>>" print #ti,"endobj" print #ti,""
print #ti,"2 0 obj<</Count 1/Kids [ 8 0 R ]>>" print #ti,"endobj" print #ti,""
print #ti,"3 0 obj<</Type/Font/Name /T1/BaseFont/Arial" print #ti,"/Subtype/Type1/Encoding /WinAnsiEncoding>>" print #ti,"endobj" print #ti,"4 0 obj<</Type/Font/Name /T2/BaseFont/Arial" print #ti,"/Subtype/Type1/Encoding /WinAnsiEncoding>>" print #ti,"endobj" print #ti,"5 0 obj<</Type/Font/Name /T3/BaseFont/Arial" print #ti,"/Subtype/Type1/Encoding /WinAnsiEncoding>>" print #ti,"endobj" print #ti,"6 0 obj<</Type/Font/Name /T4/BaseFont/Arial" print #ti,"/Subtype/Type1/Encoding /WinAnsiEncoding>>" print #ti,"endobj"
print #ti,"10 0 obj" print #ti,"<</Name /I1" print #ti,"/Type /XObject" print #ti,"/Subtype /Image" print #ti,"/Width 600" print #ti,"/Height 600" print #ti,"/Length 29779" print #ti,"/Filter /DCTDecode" print #ti,"/ColorSpace /DeviceRGB" print #ti,"/BitsPerComponent 8" print #ti,">> stream" print #ti,""
open "bmpsave.jpg" for input as #fIn content$ =input$( #fIn, lof( #fIn)) close #fIn
print #ti,content$
print #ti,""
print #ti,"endstream" print #ti,"endobj"
print #ti,"xref" print #ti,"0 11"
print #ti,"trailer" print #ti,"<</Size 11" print #ti,"/Root 1 0 R" print #ti,"/Info 7 0 R" print #ti,"/ID[<5181383ede94727bcb32ac27ded71c68>" print #ti,"<5181383ede94727bcb32ac27ded71c68>]" print #ti,">>"
print #ti,"startxref" print #ti,"31959" print #ti,"%%EOF"
print #ti," "
close #ti
I'm actually using a 3rd party app to convert to jpg (ImageMagick) which could be run from the command line, because I couldn't do it natively. I have noticed a rotate value in the PDF make up, so that's an option, however Anatoly I agree BMP filesize is going to be an issue. But I think spinning my own PDF is likely to create problems in the future for people not being able to open the PDF on various machines? possibly. I think metro might be onto a winner and create it in HTML and use htmltopdf to convert. One issue I can see though is this needs to be available to be used offline, so grabbing charts online maybe an issue. Time to start over! only 12 hours wasted!
|
|
|
Post by meerkat on Sept 3, 2023 6:15:07 GMT -5
Agree with you metro For me anyway. It's soo much easier to do stuff in HTML. I haven't found anything in PDF that can't be done in HTML. Maybe some day LB will have a html interface..
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Sept 3, 2023 8:13:56 GMT -5
Can someone suggest a decent WYSIWYG HTML editor?
Tried Brakets, Seamonkey etc. I used to use Dreamweaver, thats going back some years!
|
|
|
Post by Rod on Sept 3, 2023 13:39:54 GMT -5
There have been two html programs. One very early and a second that tried t to leverage the initial program. So long ago they may be hard to find but they did produce html files.
David Drake provided the first example, perhaps the newsletters.
|
|
|
Post by xxgeek on Sept 3, 2023 15:55:58 GMT -5
Can someone suggest a decent WYSIWYG HTML editor? Haven't used one in many years, sorry don't know what's out there. You sure you need one? You're fairly close with your bmp, just a bit more and you'll be done. I played with the code posted initially and came up with something I believe will work for you. You'll need to edit your default printer back to a non pdf printer, and finish drawing your bmp. May need a little more editing depending on what you have in mind. This draws the 'current unfinished' bmp, and displays it in your default browser, then attempts to print it. NOMAINWIN 'Define company name and address CompanyAdd1$ = "Company Name" CompanyAdd2$ = "Address 1" CompanyAdd3$ = "Address 2" CompanyAdd4$ = "Address 3" CompanyAdd5$ = "Address 4"
'Center Window UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
OPEN "Page" FOR Graphics AS #p #p, "trapclose [QUIT]"
'Setup Address on page #p, "font Arial 19 bold ; color 1 112 192" #p, "place 20 30" #p, "\" + CompanyAdd1$ #p, "Font Arial 11 ; Color BLack" #p, "\" + CompanyAdd2$ #p, "\" + CompanyAdd3$ #p, "\" + CompanyAdd4$ #p, "\" + CompanyAdd5$ #p "flush" #p, "getbmp drawing 1 1 280 300" bmpsave "drawing", "bmpsave.bmp" close #p 'make the web page, and display it CALL GenerateHTML lprint html$ dump
'quit the program [QUIT] end
SUB GenerateHTML nomainwin q$=chr$(34)'a single double quote' text$ ="<P><IMG SRC=";q$;"bmpsave.bmp";q$;" ALT=";q$;q$;" BORDER=1 width=";q$;"166";q$;" height=";q$;"160";q$;"></P>" html$ = "htmlPage.html" open html$ for output as #1 #1 text$ close #1 run "explorer ";html$ end sub
|
|