Board Logo
« Create pdf with colors... »

Welcome Guest. Please Login or Register.
Nov 20th, 2017, 10:33pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Create pdf with colors...  (Read 527 times)
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 22
xx Create pdf with colors...
« Thread started on: Mar 23rd, 2017, 3:54pm »


Below the file test.pdf is created with some drawings...
Take a look at the code...to get an idea , how it works...at least I hope...
Goodluck ! ;D

Code:
nomainwin

    button #scr, "Make  pdf... ", [b1], UL, 15, 40

    open "Draw..." for graphics_nsb as #scr

    print #scr, "fill red"
    print #scr, "flush"
    wait
    [b1]

    open "test.pdf" for output as #tf

 print #tf, "%PDF-1.2"
 print #tf, "1 0 obj<</Type /Page/Parent 5 0 R"
 print #tf, "/Resources 3 0 R"
 print #tf, "/Contents 2 0 R>>endobj"
 print #tf, "2 0 obj<< /Length 51 >>"
 print #tf, "stream"

 print #tf, "BT"
 print #tf, " /F1 12 Tf 1 0 0 1 "
 print #tf, " 60 590" ''left top
 print #tf, "Tm (Justbasic...Drawing is fun...)Tj"
 print #tf, "  ET"


 print #tf, " 250 0 0 rg"''color
 print #tf, " 120 580 m"''move to
 print #tf, " 100 140  l"
 print #tf, " 80 160 l"
 print #tf, " f"

 print #tf, " 0 250 0 rg"
 print #tf, " 200 560 m"
 print #tf, " 210 140  l"
 print #tf, " 280 160 l"
 print #tf, " f"

 print #tf, " 0 0 250 rg"
 print #tf, "BT"
 print #tf, " /F1 20 Tf 1 0 0 1 "
 print #tf, " 10 560" ''left top
 print #tf, "Tm (Justbasic...Drawing is fun...)Tj"
 print #tf, "  ET"


 print #tf, "endstream"
 print #tf, "endobj"
 print #tf, "3 0 obj<< /ProcSet[/PDF/Text] /Font <</F1 4 0 R >>>>endobj"
 print #tf, "4 0 obj<< /Type /Font/Subtype /Type1/Name /F1/BaseFont/Arial >>endobj"

 print #tf, "5 0 obj<< /Type /Pages/Kids [ 1 0 R ]/Count 1"
 print #tf, "/MediaBox[ 0 0 300 600 ] >>endobj"
 print #tf, "6 0 obj<< /Type /Catalog/Pages 5 0 R >>endobj"
 print #tf, "trailer<< /Root 6 0 R >>"

close #tf


b$ = "test.pdf"
RUN "rundll32.exe url.dll,FileProtocolHandler ";b$
wait


 
User IP Logged

tenochtitlanuk ( John F)
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 422
xx Re: Create pdf with colors...
« Reply #1 on: Mar 23rd, 2017, 6:46pm »

I too like finding how file types like bmp, wav or pdf are structured and assembling them like this, ie programmatically.

A method for pdf's I've found useful is to set my printer driver default to 'pdf' and simply print LB graphics to a pdf file as below.. It also means that I have to actively set to print to a different printer- if a program goes wrong and prints wasted sheets of real paper it is worse than simply having a file to delete!

Code draws a coloured figure in a box then prints it to fill a page.
Code:
    nomainwin

    WindowWidth =420
    WindowHeight =460

    menu #scr, "Options", "Export PDF", [export]

    open "Draw->-->PDF" for graphics_nsb as #scr


    #scr "down ; box 1 1 400 400"

    for i =255 to 1 step -5
        #scr "backcolor "; i; " 120 "; 255 -i
        #scr "    color "; 255 -i; " 120 "; i
        #scr "home ; circlefilled "; int( 200 /256 *i)
    next i

    wait

  [export]
    #scr "flush ; print 400"
    wait
 

Note you can now load and print the pdf if you wish to...
Also note that a bigger bounding box and corresponding increase in the 'print' line allows high resolutions.
User IP Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html
I use XP and Ubuntu Linux on old machines!
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 22
xx Re: Create pdf with colors...
« Reply #2 on: Mar 23rd, 2017, 7:29pm »

Ok, thx for the code. I copied and paste it...but no printer attached...
My computer gave me the print message... So this code can be later usefull.. Thx for sharing ! cheesy

Regards,

Frederik Pot
User IP Logged

code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 22
xx Re: Create pdf with colors...
« Reply #3 on: May 10th, 2017, 03:50am »

Hi,

To set colors in the pdf file ... its more from 0 to 1 :

0.4 0 0 rg

Thats all i wanna say for now..
Regards,
Frederik Pot
User IP Logged

code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 22
xx Re: Create pdf with colors...
« Reply #4 on: Nov 8th, 2017, 02:19am »

Hi,
Here a code wich makes a .pdf file with image... the image test.jpg should be in the same directory...

Goodluck

Code:

nomainwin

    button #scr, "Make  pdf... ", [b1], UL, 15, 40

    open "Draw..." for graphics_nsb as #scr

    print #scr, "fill red"
    print #scr, "flush"
    wait
    [b1]


    open "test.pdf" for output as #tf







print #tf, "%PDF-1.5"
print #tf, "%?? "





print #tf, "8 0 obj"
print #tf, "<<"
print #tf, "/Type /Page/Parent 2 0 R"
print #tf, "/Rotate 0"
print #tf, "/MediaBox [0 0 595 842]/CropBox [0 0 595 842]"
print #tf, "/Resources<</ProcSet[/PDF/Text]"
print #tf, "/Font<</T1 3 0 R/T2 4 0 R/T3 5 0 R/T4 6 0 R>>"
print #tf, "/XObject <</I1 10 0 R >>>>"
print #tf, "/Contents 9 0 R"
print #tf, ">>"
print #tf, "endobj"


print #tf, "9 0 obj<</Length 411"
print #tf, ">>stream"
print #tf, "q"
print #tf, "144 0 0 100 300 700 cm"
print #tf, "1 0 0 1 0 0 cm"
print #tf, "/I1 Do"
print #tf, "Q"
print #tf, "BT/T3 12 Tf"
print #tf, "105 699 Td"
print #tf, "(Hi !!!) Tj"
print #tf, "ET"

print #tf, "BT"
 print #tf, " /T3 12 Tf 1 0 0 1 "
 print #tf, " 60 590" ''left top
 print #tf, "Tm (Justbasic...Drawing is fun...)Tj"
 print #tf, "  ET"


 print #tf, " 0.6 0 0 rg"''color
 print #tf, " 120 580 m"''move to
 print #tf, " 100 140  l"
 print #tf, " 80 160 l"
 print #tf, " f"

 print #tf, " 0 0.4 0 rg"
 print #tf, " 200 560 m"
 print #tf, " 210 140  l"
 print #tf, " 280 160 l"
 print #tf, " f"

 print #tf, " 0 0 0.9 rg"
 print #tf, "BT"
 print #tf, " /T3 20 Tf 1 0 0 1 "
 print #tf, " 10 560" ''left top
 print #tf, "Tm (Justbasic...Drawing is fun...)Tj"
 print #tf, "  ET"


print #tf, "endstream"
print #tf, "endobj"

print #tf, "1 0 obj<</Type /Catalog/Lang(EN-US)/Pages 2 0 R>>"
print #tf, "endobj "

print #tf, "2 0 obj<</Count 1/Kids [ 8 0 R ]>>"
print #tf, "endobj "

print #tf, "3 0 obj<</Type/Font/Name /T1/BaseFont/Arial"
print #tf, "/Subtype/Type1/Encoding /WinAnsiEncoding>>"
print #tf, "endobj"
print #tf, "4 0 obj<</Type/Font/Name /T2/BaseFont/Arial"
print #tf, "/Subtype/Type1/Encoding /WinAnsiEncoding>>"
print #tf, "endobj"
print #tf, "5 0 obj<</Type/Font/Name /T3/BaseFont/Arial"
print #tf, "/Subtype/Type1/Encoding /WinAnsiEncoding>>"
print #tf, "endobj"
print #tf, "6 0 obj<</Type/Font/Name /T4/BaseFont/Arial"
print #tf, "/Subtype/Type1/Encoding /WinAnsiEncoding>>"
print #tf, "endobj "

print #tf, "10 0 obj"
print #tf, "<</Name /I1"
print #tf, "/Type /XObject"
print #tf, "/Subtype /Image"
print #tf, "/Width 8"
print #tf, "/Height 8"
print #tf, "/Length 29779"
print #tf, "/Filter /DCTDecode"
print #tf, "/ColorSpace /DeviceRGB"
print #tf, "/BitsPerComponent 8"
print #tf, ">> stream"

open "test.jpg" for binary as #df
data$ = input$( #df, lof( #df))
print #tf, data$
close #df



print #tf, "endstream"
print #tf, "endobj "



print #tf, "7 0 obj<</ModDate(D:20070501024237+10'00')"
print #tf, "/CreationDate(D:20070501024237+10'00')"
print #tf, "/Title(Title)/Creator(Your App Name)"
print #tf, "/Author(System Generated"
print #tf, "/Producer(www.My New App.com.au)/Company(My Company Name)>>"
print #tf, "endobj"


print #tf, "xref"
print #tf, "0 11"
print #tf, "0000000000 65535 f"
print #tf, "0000001275 00000 n"
print #tf, "0000001332 00000 n"
print #tf, "0000001374 00000 n"
print #tf, "0000001473 00000 n"
print #tf, "0000001573 00000 n"
print #tf, "0000001671 00000 n"
print #tf, "0000031745 00000 n"
print #tf, "0000000014 00000 n"
print #tf, "0000000234 00000 n"
print #tf, "0000001766 00000 n"



print #tf, "trailer"
print #tf, "<</Size 11"
print #tf, "/Root 1 0 R"
print #tf, "/Info 7 0 R"
print #tf, "/ID[<5181383ede94727bcb32ac27ded71c68>"
print #tf, "<5181383ede94727bcb32ac27ded71c68>]"
print #tf, ">>"



print #tf, "startxref"
print #tf, "31959"
print #tf, "%%EOF"

close #tf


b$ = "test.pdf"
RUN "rundll32.exe url.dll,FileProtocolHandler ";b$
wait





 


Link tip:https://www.codeproject.com/Articles/18623/Add-Images-and-Textboxes-to-PDF
User IP Logged

Facundo
Board Moderator


member is offline

Avatar




PM

Gender: Male
Posts: 1301
xx Re: Create pdf with colors...
« Reply #5 on: Nov 8th, 2017, 11:39am »

Amazing, I need to try this, could be useful to create simple help files. Tanks for sharing !!
User IP Logged

cundo aka MSlayer
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls