Board Logo
« Create pdf with colors... »

Welcome Guest. Please Login or Register.
Aug 17th, 2017, 06:26am


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 364 times)
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 21
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: 417
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: 21
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: 21
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

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