PDF quandary - A cry for clarity.

Post

Posted
Rating:
#1 (In Topic #668)
Regular
Doctor Watson is in the usergroup ‘Regular’
Those who follow my “Printing to a PDF, SVG or Postscript file” topic will know that trying to do so seems to be a real problem.
It doesn’t make sense reading through pages of instructions and code examples, trying to learn how to make project work, only to find out that when it finally does it will only run on a machine with the same or at least compatible hard and software features as the one you’re using. When you can’t make sure that people will be able to obtain a proper result by using the executable you want to distribute, what’s the point?
Nowhere is this seemingly more apparent than in the complex  procedures related to printing.
Mind you, this is not a typical Gambas issue. I’ve encountered it in other programming languages as well.
That’s why I want to put the output-to-be-printed in a PDF file. That one (or SVG, or Postscript) can be used on any system using the appropriate software. Users running Linux may want to send their file to Windows, Mac, …
So I would like to find out once and for all if it is at all possible, using the Gambas Print, Paint or Whatever Class to produce a PDF file that people can use without further problems. If not, I might as well throw in the towel.
That’s why I would like to ask you to run the following code – and eventually modify it - and see if you can obtain a ‘working’ PDF file. If you don’t want to save the file, just opt for ‘Print Preview’.
I’m curious. If that already  turns out to be a problem …  :cry:
 The original project can be found here (oh dear) :
Programming Gambas from Zip/Printing - Wikibooks, open books for an open world

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public pr1 As New Printer As "pr1"
  4. Public Button1 As New Button(Me) As "Button1"
  5. Public SimpleText As String
  6.  
  7. Public Sub Form_Open()
  8.  
  9. SimpleText = "Countries of the World<br><br>Papua New Guinea<br><br>Papua New Guinea is a country that is north of Australia. It has much green rainforest. It has beautiful blue seas. Its capital, located along its southeastern coast, is Port Moresby.<br><br>This is plain text in Linux Libertine 12 point.<br><br>John Smith, editor"
  10.  
  11. Me.width = 140
  12. Me.Height = 100
  13. With Button1
  14.   .width = 100
  15.   .height = 30
  16.   .left = 20
  17.   .top = 20
  18.   .text = "Click"
  19.  
  20. Public Sub pr1_Draw()
  21.   Paint.Font = Font["Linux Libertine,12"]  'Turn this line Off or you won't see anything
  22.   Paint.DrawRichText(SimpleText, 10, 10)   'Original was (SimpleText,960, 960, Paint.Width - 2 * 960) what ????
  23.  
  24. Public Sub Button1_Click()
  25.   pr1.OutputFile = Application.path & "/Output.pdf" 'To make sure Configure is set 'Print To File'
  26.   If pr1.Configure() Then Return
  27.   pr1.Print
  28.  

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Are you not using poppler?

I know not what exactly poppler does but it is the gambas pdf component, i'd should think it worth using if you want to do pdf related things.
It might just be for reading pdf docs not writing

/comp/gb.poppler - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
All your code does is print text to a file.

Just because you name it *.pdf does not make it a pdf file.  :roll:

I should think you will have to use an external program to convert the print text into pdf format

Or learn how to manually write pdf format.

It's not going to happen all by itself ;)

Welcome to the wonderfull world of linux ;) :lol:
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
Hello Doctor Watson,
I have tried your code and it seems to me that the pdf file is created regularly.
In fact, opening it with a hexadecimal editor, I can see its "Magic Number ": <COLOR color="#800000">%PDF-1.4.%…..1 </COLOR> et cetera…

However, another way to create a PDF file is to use gb.cairo Component.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
Doctor Watson is in the usergroup ‘Regular’
The generated files seem to be real PDF files indeed.
Just checked them with an app ‘PDF Mix Tool’ and the Document Information says (Vuott will be pleased) : “Producer cairo 1.16.0”.
So printer.configure uses cairo to produce PDF files.
How this will turn out when I try to reach my final goal – putting a GridView on a PDF page  :?:  :roll:
But for now that leaves the eminent problem of using fonts.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

Doctor Watson said

…my final goal – putting a GridView on a PDF page
In the pdf file do you want to put only the text contained in the cells of GridView, or do you also want to make the grid appear?

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
on my system Debian , Gnome

first press of the print button produces a blank output to either the file or preview.

all successive pressed of the print button produce proper output to both file or preview

I have not been able to find out why.

so during testing of you only test once and stop to try to find out why …. you think it is not working ! But it may work on the second press of print …. hopefully someone else can find the problem and the fix.

This is duplicate from my post in the other thread of yours
the person that wrote the original code from the from zip book was using qt graphics and you and I are using gtk.

when you start a new project you are given the choice which to use … it can be changed later but it is kinda confusing as to just what changes go together … if you create a new project and chose qt for graphics I think the code from the book will work just fine.
If you ask someone to run a test of your code from a copy and paste you should tell them what graphic system you are using.

When you compile the project I think the graphic system is compiled with the code  ….I have not published anything yet so I am  not sure …..others can answer that.
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’
Well… if you want to "put" your GridView and its text in a PDF file, you could try this example-code.
You have to activate "gb.desktop.x11" and "gb.cairo" Components.

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim r, c As Byte
  4.  
  5.   With GridView1
  6.     .Rows.Count = 5
  7.     .Columns.Count = 5
  8.  
  9.   For r = 0 To 4
  10.     For c = 0 To 4
  11.       GridView1[r, c].Text = "abcde"
  12.     Next
  13.   Next
  14.  
  15.  
  16. Public Sub Button1_Click()
  17.  
  18.   Dim dw As DesktopWindow
  19.   Dim pdf As CairoPdfSurface
  20.   Dim im As Image
  21.  
  22. ' Find the "window" of the GridView by its identifier
  23.   With dw = New DesktopWindow(GridView1.Handle)
  24. ' Capture the GridView image:
  25.     im = .GetScreenshot(True).Image
  26.  
  27. ' Sets the drawing surface of the future PDF file.
  28. ' The first argument sets the path where the future PDF file will be saved.
  29. ' The second and third arguments set the size in "millimeters" of the future PDF file.
  30.   pdf = New CairoPdfSurface("/tmp/file.pdf", 210.0, 297.0)
  31.  
  32.   With Cairo
  33.     .Begin(pdf)
  34.     .Source = Cairo.ImagePattern(im, 100, 100)
  35.     .Paint
  36.     .End
  37.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
I stand corrected  :roll:

thanks guys
I should probably not comment with assumptions when i know very little about something, like printing ;)
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
Doctor Watson is in the usergroup ‘Regular’
Grayghost4, you are so right. To all who want to try it:
- Feel free to change "Linux Libertine,12" to some font you like. "Z003,20" is a nice one. It should be pre-installed.
- Run my code and  click on the button.
- Printer.Configure appears.
- Choose ‘Print Preview’ (you will get a blanc page)
- Close the Preview screen, not the programme.
- Click on the button again.
- Printer.configure appears again.
- Choose ‘Print Preview’ again.
- This time the preview screen displays the text in the choosen font.
Just as Grayghost4 I haven’t the foggiest why this happens but is looks like a clue to the problem. Real Guru stuff this one.
Vuott : thanks for the code. I will have a go at it soon.
Bruce : No hard feelings mate !  :D

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#11
Regular
Doctor Watson is in the usergroup ‘Regular’
Vuott : Just tried to run your code. Unfortunately something goes wrong.
It starts with an error: “Unknown identifier: DesktopWindow”
Both gb.cairo and gb.desktop.x11 have been activated.
 :?:

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 Dr.  

You need to add a gridview to  FMain.form

then it will work just fine
Online now: No Back to the top

Post

Posted
Rating:
#13
Regular
Doctor Watson is in the usergroup ‘Regular’
 Did you try that yourself Grayghost4?
Of course I did put GridView1 on the form.
And a Button1 by the way.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#14
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’

Doctor Watson said

Did you try that yourself Grayghost4?

Yes I copied and paisted the program from the thread and when I ran it … it error out

added a gridview1 to the FMain.form

Did you start with a graphic program from NEW ?

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#15
Regular
Doctor Watson is in the usergroup ‘Regular’
 Hi Grayghost4.
Yes I started with a new project but that wouldn’t be necessary. A new form would be sufficient. I think you don’t see what’s going on.
When Vuott sends this programme, he quite rightly supposes that you or any other visitor will spot that it contains code to handle a GridView1 and a Button1. And that you will know that you have to put them on the form that will be used first.
I see by the way that you don’t have added the Button1.
But even if you did everything right, it still gives the error I signalled to Vuott.
At least it does so on my machine with my software configuration.
Let’s wait and see what Vuott has to say about the error message.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#16
Regular
vuott is in the usergroup ‘Regular’

Doctor Watson said

Vuott : Just tried to run your code. Unfortunately something goes wrong.
It starts with an error: “Unknown identifier: DesktopWindow”
Both gb.cairo and gb.desktop.x11 have been activated.

Well, you have to activate also " <COLOR color="#800000">gb.desktop</COLOR> ".

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#17
Regular
Doctor Watson is in the usergroup ‘Regular’
 Well, I couldn’t have known that, could I ?
But ‘Bingo’ It works !
Let’s see now if I can get it to do what I exactly want.
Trial& Error time
Thanks Vuott

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#18
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

vuott said

You have to activate "gb.desktop.x11" and "gb.cairo" Components.

Doctor Watson said

Well, I couldn’t have known that, could I ?

Hmmmm …
Online now: No Back to the top

Post

Posted
Rating:
#19
Regular
vuott is in the usergroup ‘Regular’

PJBlack said

Hmmmm …
Well, for me my code works even without activating the "gb.desktop" Component, but maybe he has an older version of Gambas than mine.
My version of Gambas is: b01f603 (master)
I remember that previously it was necessary to activate both "gbdesktop" and "gb.desktop.x11".

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#20
Regular
Doctor Watson is in the usergroup ‘Regular’
 Gentlemen, this is starting to deviate away from the real reason for this topic.
PJBlack, you seem to be sceptical? Well, Vuott did not write “ You have to activate "gb.desktop.x11" and "gb.cairo" Components.” He wrote about activating gb.desktop.x11 first and activating gb.desktop afterwards.  And that fully justifies my remark. May I kindly ask to keep to what was really written.
But Vuott’s answer points out an ‘error’ we easily make when we share code we have written. We assume that it will run on every other machine or with every other Gambas version or configuration.
Vuott, I don’t know about ‘b01f603 (master)’. My version is 3.14.3. So I just checked the Gambas site and I see that there’s a new version 3.16.0. Is that the one you mean?
Perhaps I should upgrade to that one first and check if problems like the original one of this topic – executing Paint.Font - still persist. If not, I could write some report about it.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#21
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
I am using 3.16.0, and I did not have to activate gb.desktop to make the program run.
Online now: No Back to the top

Post

Posted
Rating:
#22
Regular
vuott is in the usergroup ‘Regular’

Doctor Watson said

Vuott, I don’t know about ‘b01f603 (master)’. My version is 3.14.3. So I just checked the Gambas site and I see that there’s a new version 3.16.0. Is that the one you mean?
Yes, I do.


grayghost4 said

I am using 3.16.0, and I did not have to activate gb.desktop to make the program run.
In fact, me too.


Doctor Watson said

We assume that it will run on every other machine or with every other Gambas version or configuration.
In my opinion the programmer can not consider the multiplicity of cases due to the versions of Gambas owned by the users or by the installed libraries or by the hardware.  :shock:
…a few days ago a user of the Italian Gambas forum, asking a question, claimed to still use  :? Gambas-2 !!!  :o
Should programmers also think about those who use Gambas with a version abandoned about 10 years ago? Really, that would be crazy!

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#23
Regular
Doctor Watson is in the usergroup ‘Regular’
Vuott, I also said that I would (like to perhaps) write a report about this issue. I just wanted to wait and check a few points after having upgraded to the latest Gambas version. And that went wrong as you probably read here : Upgrading to 3.16.0 - Gambas ONE (still not solved).
I fully agree with you when you say
In my opinion the programmer can not consider ……
and I would like to suggest something small and simple to draw our members’ attention to what to expect when executing code they copy here :
Image

(Click to enlarge)

Small effort that could avoid some unnecessary questions.
By the way I’m getting the hang of using Cairo, but it would still be a benefit for users if Printer.Configure could work properly – like choosing between svg, postscript for one thing (all formats handled by Cairo as well).

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#24
Guru
BruceSteers is in the usergroup ‘Guru’

Doctor Watson said

Vuott, I also said that I would (like to perhaps) write a report about this issue. I just wanted to wait and check a few points after having upgraded to the latest Gambas version. And that went wrong as you probably read here : Upgrading to 3.16.0 - Gambas ONE (still not solved).
I fully agree with you when you say
In my opinion the programmer can not consider ……
and I would like to suggest something small and simple to draw our members’ attention to what to expect when executing code they copy here :
Screenshot from 2021-05-20 07-09-32.png
Small effort that could avoid some unnecessary questions.
By the way I’m getting the hang of using Cairo, but it would still be a benefit for users if Printer.Configure could work properly – like choosing between svg, postscript for one thing (all formats handled by Cairo as well).

Well i'm not doing that, most of us here are using the latest version.

Don't feel so embarrassed and defensive dude.
It's all cool , we live and learn , nothing wrong with being a bit of a newb, we've all been there.
You clearly have a lot to learn about lots of things by the way you cannot even upgrade via the ppa method.

You ask for posts to be deleted because you think you've made yourself look silly , it's just the learning curve. It's not silly , it's just the way it is.
Your obviously bruised ego makes you look silly, not the initial questions.

If you want to get to the stage of thinking you've found bugs in gambas and wanting to report them to Benoit or making suggestions to improve gambas then you need to be on the latest development branch , gambas 3.14 is old news, It's not being developed any more.

Maybe you could do the autotools install instead?
I made a utility to upgrade to latest gambas…
Bruce Steers / gambassimpleupgrade · GitLab (for newbs who do not know git)
Bruce Steers / GambasLatestUpdate · GitLab (a bit more advanced)


Sorry to sound like an ass but that's what I am so it just keeps coming out like that ;) :p
Online now: No Back to the top
1 guest and 0 members have just viewed this.