LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-06-2018, 11:40 AM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,772
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
page orientation vs. various apps vs. printer(s)


I've read the thread Set Default Page Orientation. It is quite dated (2015) but I have some similar troubles in 2018.

Printing from a browser gives me the most grief the most often. Many web-pages seem to print well as portrait. Some, however, require landscape. Sadly, some web-pages are too wide part way through their content and it does not wrap. The content is then truncated and "lost."

I want all of my print requests, regardless of the source application, to sort out the per-document and per-page orietation -- portrait vs. landscape -- and have the printer do the right things. Okular and Evince seem to behave well for many PDF files. However, apps such as browsers (Firefox, Chromium) and email (Thunderbird) appear to want a single page orientation for every page of every print request.

Do I understand that modern linux workstations make everything into a "PDF data" before asking CUPS to send bytes to a printer? Does the app tag the "PDF data" so CUPS knows where it came from or does it simply grab a file from the spool queue?

Folks, I really, REALLY want to understand this but I'd like a two-phase solution. First, tell me something that works. Second, point me at sources for deeper understanding.

Thanks in advance,
~~~ 0;-Dan
 
Old 02-06-2018, 12:54 PM   #2
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
I'd try setting defaults via localhost:631 from a web browser.

But if you really want to figure things out this is what you want https://www.cups.org/documentation.html
 
Old 02-06-2018, 01:27 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,140
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
Quote:
Folks, I really, REALLY want to understand this but I'd like a two-phase solution.
Quote:
Okular and Evince seem to behave well for many PDF files.
You mean to make a pdf from a web page, then print it.

Make the .pdf from web page the way you want it. Make something that allows you to select page size, font size etc.
For example Qt version:
Code:
#! /usr/bin/env python

#Run web2pdf.py then answer input prompts

import sys, signal
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl, QSizeF
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings 
from PyQt5.QtPrintSupport import QPrinter

#Change user agent here
uagent = ('Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0')

class WebToPdf(QWebView):
    def __init__(self, url, out_file, font_size, options):
        QWebView.__init__(self)
        
        #Set user agent for web page request
        def agent(self):
            return (uagent)
        userAgent = QWebPage(self)
        userAgent.userAgentForUrl = agent
        
        web = QWebView()
        web.setPage(userAgent)
        
        #Set from options dialog
        if 'N' in options:
            web.settings().setAttribute(
                    QWebSettings.JavascriptEnabled, False)
            web.settings().setAttribute(
                    QWebSettings.AutoLoadImages, False)
        if 'I' in options:
            web.settings().setAttribute(
                    QWebSettings.JavascriptEnabled, False)
        if 'S' in options:
            web.settings().setAttribute(
                    QWebSettings.AutoLoadImages, False)
        if 'C' or '' in options:
            pass

        #Set from font_size input    
        web.settings().globalSettings().setFontSize(
                    QWebSettings.MinimumFontSize, int(font_size))
                    
        web.load(QUrl(url))
        
        #pdf printer
        printer = QPrinter()
        
        #Set pdf page size
        #Letter 216 × 279|Legal 216 × 356|Tabloid 279 × 432|Ledger 432 × 279
        printer.setPaperSize(QSizeF(216, 279), QPrinter.Millimeter) #Letter
        #printer.setPaperSize(QSizeF(216, 356), QPrinter.Millimeter) #Legal
        #printer.setPaperSize(QSizeF(279, 432), QPrinter.Millimeter) #Tabloid
        #printer.setPaperSize(QSizeF(432, 279), QPrinter.Millimeter) #Ledger
        
        printer.setOutputFormat(QPrinter.PdfFormat)
        #Set pdf margins
        printer.setPageMargins(10,10,10,10,QPrinter.Millimeter)
        printer.setOutputFileName(out_file)

        def print_it():
            web.print_(printer)
            QApplication.exit()
    
        web.loadFinished.connect(print_it)
        
        #Keep a log file
        with open('web2pdf_log', 'a') as f:
            f.write('\nurl: %s\nFile name: %s\nFont size: %s'
                    '\nOption used: %s\nUser agent: %s\n' 
                    % (url, out_file, font_size, options, uagent))

def main():
    app = QApplication(sys.argv)
    
    #Get inputs
    #Get url or quit
    url = input('\n' 'Source url can be web page or file://myfile.html'
                '\n' 'Enter/Paste source url: ')
    if url == '':
        print ('Error: Need to enter a url')
        sys.exit(0)
        
    #Get out file name or set default name
    out_file = input('\n' 'Enter output file name (default: out.pdf): ')
    if out_file == '':
        out_file = 'out.pdf'
        
    #Get font size or set default size
    font_size = input('\n' 'Enter font size for web page (default: 16): ')
    if font_size == '':
        font_size = '16'
    if font_size.isdigit():
        pass
    else:
        print ('Error: Font size has to be an integer')
        sys.exit(0)

    #Choose options dialog, select type or set default type
    options = input('\n''Select pdf type: \n\n'
                        'No images or scripts N \n'
                        'Images - No scritps  I \n'
                        'Scripts - No images  S \n'
                        'Complete page        C \n'
                        'default: C \n\n'
                        'Enter one of N I S C: ')
    #Change all chars entered to upper case
    options_fix_case = options.upper()
    if options_fix_case not in ['N', 'I', 'S', 'C', '']:
        print ('Error: Invalid option entered')
        sys.exit(0)

    print_pdf = WebToPdf(url, out_file, font_size, options_fix_case)
    print_pdf
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
Or an Example gtk version
Code:
#! /usr/bin/env bash

#webpage to pdf with wkhtmltopdf

clear
#Get inputs
read -p "Enter/Paste page url: " url
read -p "Enter output filename, default (out.pdf): " pdffile
read -p "Enter minimum font size, default (20): " fontsize

#If no font size entered or non integer set default
if ! [ "${fontsize//[0-9]}" ]; then
    fontsize=20 #Default font size
fi

#If no out filename entered set default
if [ -z "$pdffile" ]; then 
    pdffile="out.pdf"
fi

#Select pdf type
read -p "
Lower quality/save space L 
No script/no images N
With images/no script I
With scripts/no images S
Full images/scripts/background F
 
Enter L N I S F : " lnif

#Keep a log file
echo "
"$(date)"
URL: "$url"
Outfile name: "$pdffile"
Fontsize: "$fontsize"
Quality: "$lnif"
" 2>&1 | tee -a webtopdf_log

#Get it
case $lnif in
	[Ll]* ) wkhtmltopdf -l -T 6 -B 6 -R 3 -L 3 --no-background \
    --no-images --disable-javascript --disable-plugins \
    --minimum-font-size "$fontsize" "$url" "$pdffile"
	;;
	
	[Nn]* ) wkhtmltopdf -T 6 -B 6 -R 3 -L 3 --no-background \
    --no-images --disable-javascript --disable-plugins \
    --minimum-font-size "$fontsize" "$url" "$pdffile"
	;;
    
    [Ii]* ) wkhtmltopdf -T 6 -B 6 -R 3 -L 3 --no-background \
    --disable-javascript --disable-plugins \
    --minimum-font-size "$fontsize" "$url" "$pdffile"
    ;; 
    
    [Ss]* ) wkhtmltopdf -T 6 -B 6 -R 3 -L 3 --no-background \
    --no-images --disable-plugins --minimum-font-size "$fontsize" \
    "$url" "$pdffile"
    ;;
	
	[Ff]* ) wkhtmltopdf -T 6 -B 6 -R 3 -L 3 --javascript-delay 10000 \
    --no-stop-slow-scripts --minimum-font-size "$fontsize" \
    "$url" "$pdffile"
	;;
	
	*) echo "Invalid option"
	;;
esac
Then print the .pdf
Edit: I'm sorry wkhtmltopdf is qt5 now also.
Code:
pacman -Si wkhtmltopdf
Repository      : community
Name            : wkhtmltopdf
Version         : 0.12.4-1
Description     : Command line tools to render HTML into PDF and various image
                  formats
Architecture    : x86_64
URL             : https://wkhtmltopdf.org/
Licenses        : LGPL3
Groups          : None
Provides        : None
Depends On      : qt5-webkit  qt5-svg
Optional Deps   : xorg-server: wkhtmltopdf needs X or Xvfb to operate
Conflicts With  : None
Replaces        : None
Download Size   : 162.42 KiB
Installed Size  : 685.00 KiB

Last edited by teckk; 02-06-2018 at 01:52 PM.
 
1 members found this post helpful.
Old 02-12-2018, 07:40 AM   #4
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,772

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by teckk View Post
You mean to make a pdf from a web page, then print it.
WOW! Thanks for all of that.
I have and will learn a lot from your code on several fronts.

I'm not sure that it "solves" my original problem. Given that I have a browser open to some page that I want to print, the browser has some menu item or keystroke (eg, CTRL-P) that enables PRINT_THIS_PAGE. It is at this point that I'm seeking to intervene and assert control over what gets printed.

I know that I can select PRINT_TO_FILE and make a PDF document from the web page. I can then use your scripts and others to tinker both the output and the printer settings that get used. It sounds like I want my own variant, PRINT_TO_FILE_MyWAY. Alternately, I need to automatically notice that I've created a new PDF document in some folder and launch a chain of scripts to tinker then print that file.

Thanks in advance,
~~~ 0;-Dan
 
Old 02-12-2018, 08:25 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Actually, the CUPS user manual is probably more thorough than their "help."

For instance, here ...

Last edited by sundialsvcs; 02-12-2018 at 08:26 AM.
 
Old 02-12-2018, 10:30 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,724

Rep: Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918
I have the same problem that some websites automatically print as landscape which are really portrait and some print as portrait but then some content is truncated.

Your correct that the default format was changed from Postscript to PDF. You can create your own cups filters to automatically check the PDF but if the content is already truncated before cups and then just printing as landscape will not help much.
 
Old 02-12-2018, 01:11 PM   #7
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I have my browser set to 'preview' before it prints. From there I can check the format and switch between orientations. I also usually don't want every individual printed page of a web page, so I specify only the pages I want printed.
 
Old 02-12-2018, 03:40 PM   #8
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,140
Blog Entries: 6

Rep: Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828Reputation: 1828
@SaintDanBert
Quote:
I know that I can select PRINT_TO_FILE and make a PDF document from the web page. I can then use your scripts and others to tinker both the output and the printer settings that get used.
No,
Copy the url from the browser and paste it into your pdf making script. The above scripts make a pdf from a url, no cups, no BS. Then after you have a .pdf made from the page, do what you want with it, print it, keep it, delete it...etc.

Unremark the paper size that you want. Or have the script ask you for it.
Code:
#Set pdf page size
#Letter 216 × 279|Legal 216 × 356|Tabloid 279 × 432|Ledger 432 × 279
printer.setPaperSize(QSizeF(216, 279), QPrinter.Millimeter) #Letter
#printer.setPaperSize(QSizeF(216, 356), QPrinter.Millimeter) #Legal
#printer.setPaperSize(QSizeF(279, 432), QPrinter.Millimeter) #Tabloid
#printer.setPaperSize(QSizeF(432, 279), QPrinter.Millimeter) #Ledger
From man wkhtmltopdf
Code:
   -B, --margin-bottom <unitreal>
              Set the page bottom margin
       -L, --margin-left <unitreal>
              Set the page left margin
       -R, --margin-right <unitreal>
              Set the page right margin
       -T, --margin-top <unitreal>
              Set the page top margin
       -O, --orientation <orientation>
              Set orientation to Landscape or Portrait
           --page-height <unitreal>
              Page height
       -s, --page-size <Size>
              Set paper size to: A4, Letter, etc.
           --page-width <unitreal>
It gives you the ability to inspect the pdf before you print it. Or make the pdf 3 or 4 times until you get it right. You can also dload the page to file once, then use the script or wkhtmltopdf on the file. You have to download it anyway to make a pdf from it, regardless how you get it. Make a script like above and you can get a page real quick with/without images, with/without scripts. My 2 cents.
 
1 members found this post helpful.
Old 02-14-2018, 03:56 PM   #9
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,772

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Thanks, heaps...

I'll give it a try and report back.

Regards,
~~~ 0;-Dan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set default page orientation in Okular for printing jjscott Linux - Desktop 9 08-16-2016 06:48 AM
Recommend scanner with b/w printer - printer use < 1 page per month porphyry5 Linux - Hardware 3 09-20-2011 09:59 PM
Standalone Authentication Page for Web Apps LinuxGeek Linux - Software 4 12-20-2007 02:15 AM
Scribus and page orientation blotch Linux - Software 4 10-13-2005 02:47 AM
A must have apps page Goatdemon LQ Suggestions & Feedback 26 07-20-2002 01:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration