PDF quandary - A cry for clarity.
Posted
#1
(In Topic #668)
Regular

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)
- ' Gambas class file
- 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"
- With Button1
- .width = 100
- .height = 30
- .top = 20
- .text = "Click"
- Paint.DrawRichText(SimpleText, 10, 10) 'Original was (SimpleText,960, 960, Paint.Width - 2 * 960) what ????
- pr1.Print
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

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
Posted
Guru

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
Posted
Regular

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>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
Regular

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?Doctor Watson said
…my final goal – putting a GridView on a PDF page
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Enthusiast

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.
Posted
Regular

You have to activate "gb.desktop.x11" and "gb.cairo" Components.
Code (gambas)
- With GridView1
- .Rows.Count = 5
- .Columns.Count = 5
- GridView1[r, c].Text = "abcde"
- ' Find the "window" of the GridView by its identifier
- ' Capture the GridView image:
- ' Sets the drawing surface of the future PDF file.
- ' The first argument sets the path where the future PDF file will be saved.
- ' The second and third arguments set the size in "millimeters" of the future PDF file.
- With Cairo
- .Begin(pdf)
- .Source = Cairo.ImagePattern(im, 100, 100)
- .Paint
- .End
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Guru

thanks guys
I should probably not comment with assumptions when i know very little about something, like printing
Posted
Regular

- 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 !
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
Enthusiast

You need to add a gridview to FMain.form
then it will work just fine
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
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 ?
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
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>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
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 …
Posted
Regular

Well, for me my code works even without activating the "gb.desktop" Component, but maybe he has an older version of Gambas than mine.PJBlack said
Hmmmm …
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>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

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.
You eat an elephant one small bite at a time.
Posted
Enthusiast

Posted
Regular

Yes, I do.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?
In fact, me too.grayghost4 said
I am using 3.16.0, and I did not have to activate gb.desktop to make the program run.
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:Doctor Watson said
We assume that it will run on every other machine or with every other Gambas version or configuration.
…a few days ago a user of the Italian Gambas forum, asking a question, claimed to still use :? Gambas-2 !!!
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>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

I fully agree with you when you say
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 :In my opinion the programmer can not consider ……
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.
You eat an elephant one small bite at a time.
Posted
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 sayand I would like to suggest something small and simple to draw our members’ attention to what to expect when executing code they copy here :In my opinion the programmer can not consider ……
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
1 guest and 0 members have just viewed this.




