Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Mixed page orientation #1564

Open
fjoho opened this issue Feb 25, 2014 · 53 comments

Comments

@fjoho
Copy link

commented Feb 25, 2014

Some ideas how to implement mixed page orientation:

  • command line argument specifying orientation for each html page in the argument list
  • a code in HTML that tells to change page orientation from here.
@ashkulz

This comment has been minimized.

Copy link
Member

commented Feb 25, 2014

Unless you provide a patch or a technical suggestion on how to accomplish this (in terms of changes required in QT), this is unlikely to get implemented.

@fjoho

This comment has been minimized.

Copy link
Author

commented Feb 25, 2014

So you think changes in QT are needed? Why?

@ashkulz

This comment has been minimized.

Copy link
Member

commented Feb 25, 2014

See QPrinter::setOrientation -- it is up to the printer driver to pick up changes or not, and I don't think that the PDF print driver in QT handles it correctly.

@0xBF

This comment has been minimized.

Copy link

commented May 5, 2014

QPrinter::PdfFormat support page orientation set. At least in Qt 4.8.5 from Debian jessie.

next code generate pdf with 3 pages (portrait, landscape, again portrait):

#include <QApplication>
#include <QPainter>
#include <QPrinter>

int main( int argc, char *argv[]) {
  QApplication app( argc,argv);

  QPrinter printer(QPrinter::HighResolution); //create your QPrinter (don't need to be high resolution, anyway)

  printer.setPageSize(QPrinter::A4);
  printer.setOrientation(QPrinter::Portrait);
  printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
  printer.setFullPage(false);
  printer.setOutputFileName("output.pdf");
  printer.setOutputFormat(QPrinter::PdfFormat); //you can use native format of system usin QPrinter::NativeFormat

  QPainter painter(&printer); // create a painter which will paint 'on printer'.
  painter.setFont(QFont("Tahoma",8));

  painter.drawText(200,200,"Page #1");

  printer.setOrientation(QPrinter::Landscape);
  printer.newPage();
  painter.drawText(200,200,"Page #2");

  printer.setOrientation(QPrinter::Portrait);
  printer.newPage();
  painter.drawText(200,200,"Page #3");

  painter.end();
}
@fjoho

This comment has been minimized.

Copy link
Author

commented May 6, 2014

Pleas re-open issue.

@ashkulz

This comment has been minimized.

Copy link
Member

commented May 6, 2014

@fjoho: I think that point 1 can be achieved by moving orientation from being a PdfGlobal property to a PdfObject property, however this would break backward compatibility for users of the API. I'd welcome a PR from you implementing it which also addresses the backward compatibility concerns :-)

For point 2, it will require changes at the WebKit level so that part remains unchanged.

@fjoho

This comment has been minimized.

Copy link
Author

commented May 6, 2014

Why move orientation from being a PdfGlobal property? Just add --page-orientation as a PdfObject property. If --page-orientation is set, then override PdfGlobal property for that page.

@ashkulz

This comment has been minimized.

Copy link
Member

commented May 7, 2014

Are you willing to contribute a patch? I'm not interested in it as such, but will review/integrate a patch which implements this.

@fjoho

This comment has been minimized.

Copy link
Author

commented May 7, 2014

I do not have enough experience with C++ to help with this. If you re-open the issue then maybe someone else will help? Many will probably have use for this sooner or later.

@ashkulz

This comment has been minimized.

Copy link
Member

commented May 7, 2014

I haven't seen any major C++ contributions to this project other than from @pruiz in the last two years. I don't think that I will be able to focus on feature requests or minor bugs until wkhtmltopdf is ported to Qt5, as that is a massive effort in itself. I have a very simple criterion: if the bug is simple to solve i.e. taking less than 2-3 hours effort, I will solve it immediately otherwise it won't be addressed. If I do get time in future, I can easily track such issues by the label -- I mark such issues as PatchNeeded or UpstreamChangeNeeded.

@wladiston

This comment has been minimized.

Copy link

commented Feb 2, 2015

Was that implemented?

@fjoho

This comment has been minimized.

Copy link
Author

commented Feb 3, 2015

Don't think so, but i will love to see it implemented.

@ashkulz ashkulz reopened this Feb 3, 2015

@tomw1808

This comment has been minimized.

Copy link

commented Apr 24, 2015

here we go: +1.
Imagine all the terrible css-rotate-hacks would be gone. Seems like the nice-to-have-feature is actually quite important across different sectors.

Now, a year passed since it was filed, how is your take on that currently?

@ashkulz

This comment has been minimized.

Copy link
Member

commented Apr 24, 2015

@tomw1808: I don't really have time to take it up. I'm quite busy in my day job and my 1-year old kid takes up almost all of the free time, so any effort that I put here is mostly in the 0.13 upgrade and not in specific issues. This project badly needs code contributions, but those do not seem to be happening.

@ashkulz ashkulz added this to the future milestone Apr 24, 2015

@ashkulz ashkulz added FeatureRequest and removed PatchNeeded labels Apr 24, 2015

@tomw1808

This comment has been minimized.

Copy link

commented Apr 24, 2015

@ashkulz I totally understand that. I am having private side projects myself and a family aside (or vice versa), its almost impossible to keep work-life balance while still developing for my own projects. Unfortunately I am no qt developer, or I would take on that. I hope someone will hear my prayers and hop on to contribute to that really awesome project. Wish you all the best for you and your family! Thanks for writing back and a good day from Austria.

@ashkulz

This comment has been minimized.

Copy link
Member

commented Apr 24, 2015

@tomw1808: Thanks for the appreciation 👍

@shamitv

This comment has been minimized.

Copy link

commented Sep 13, 2015

@ashkulz , I am thinking about an approach that

  1. Exposes couple of C++ functions to JavaScript, these function can be used to manage state of PdfGlobal.orientation ( basically setter and getter)
  2. JS can call this function anytime to set orientation
  3. Add required plumbing to update orientation in PDF Printer as well

Does that make sense ?

Will update once I have an implementation available. It might take some time since my C++ is rusty.

@fjoho

This comment has been minimized.

Copy link
Author

commented Sep 13, 2015

Looking forward to this :)

@shamitv

This comment has been minimized.

Copy link

commented Sep 14, 2015

I think the approach might not work as I though.

By the time code gets down to printing pages, all JS has already been executed. Flow of the code seems to be

  1. Html is fetched and rendered by QT.
    a. JS is executed in this step
  2. Code finds out number of pages by querying QT
  3. Each page is rendered on PDF

So, info provided by JS would be lost by the time PDF is rendered.

This might still work if there is some kind of callback each time QT starts rendering a new page.

Will investigate further over next weekend.

shamitv added a commit to shamitv/wkhtmltopdf that referenced this issue Nov 15, 2015
Feature request: Mixed page orientation wkhtmltopdf#1564
Add a command line option "--custom-orientations" to specify custom
page
orientation for each URL.

Example is

"wkhtmltopdf.exe
--custom-orientations PLP page1.html   page2.html
page3.html
test_unit_03.pdf"

In this example, three URLs are supplied and "PLP"
indicates page
orientation for each URL (Portrait for 1st, Landscape for
2nd and
Portrait for third)
@shamitv

This comment has been minimized.

Copy link

commented Nov 15, 2015

Need help with testing this implementation.

Change : shamitv@0330bd0

Windows Binary : https://github.com/shamitv/wkhtmltopdf/releases/tag/v0.12.2.5

HOWTO : (Optional) parameter --custom-orientations. Value of the parameter should be a string with one character for each input URL. Character can be P or L for Portrait / Landscape.

Example :
"wkhtmltopdf.exe --custom-orientations PLP page1.html page2.html page3.html test_unit_03.pdf"

@AmeliRiddle

This comment has been minimized.

Copy link

commented Nov 16, 2015

@shamitv I can't test ( I get error and i can't correct it(

/usr/bin/xvfb-run: line 166: 28785 Segmentation fault (core dumped) DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1

@shamitv

This comment has been minimized.

Copy link

commented Nov 16, 2015

Which platform are you testing it on? I can try recreating on the same platform (Linux/Windows distribution, version and 64 v/s 32 bit)

@AmeliRiddle

This comment has been minimized.

Copy link

commented Nov 17, 2015

@shamitv
Linux version 4.1.10-200.fc22.x86_64 (mockbuild@bkernel01.phx2.fedoraproject.org) (gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC) )

@ghost

This comment has been minimized.

Copy link

commented Jan 8, 2016

@shamitv As AmeliRiddle, I can't test it. I get an error (crash) while generating a pdf with more than 1 html file.
I am running Windows 10 64bits. HTML files and exe are in the same folder.

This is the command line I use to test it :
wkhtmltopdf
--page-size A4
--custom-orientations PAPAPAP
--print-media-type
--margin-left 10
--margin-top 40
--margin-right 10
--margin-bottom 10
--header-spacing 5
--header-html "HAB_Planning.tdcml_header.html"
--footer-html "HAB_Planning.tdcml_footer.html"
--javascript-delay 3000 "HAB_Planning.html"
--javascript-delay 3000 "HAB_Planning_chapitre_2.html"
--javascript-delay 3000 "HAB_Planning_chapitre_3.html"
--javascript-delay 3000 "HAB_Planning_chapitre_4.html"
--javascript-delay 3000 "HAB_Planning_chapitre_5.html"
--javascript-delay 3000 "HAB_Planning_chapitre_6.html"
--javascript-delay 3000 "HAB_Planning_chapitre_7.html"
test.pdf

Are you still working on this feature ?
I will try to look at this during next week. Hope I can help.

@shamitv

This comment has been minimized.

Copy link

commented Jan 17, 2016

@eadelon , thanks for the feedback. Would it be possible for you to reproduce this issue with this Binary : https://github.com/shamitv/wkhtmltopdf/releases/tag/v0.12.2.5 ?

@PerlTester

This comment has been minimized.

Copy link

commented Feb 1, 2016

Just downloaded and tested this on windows 2008R2 64bit and does work with multi format pages PLP with a title page and a toc built. However there is an issue with 100% widths not filling landscape pages 100%. A 100% table width does fill a portrait page fully but only 75% of a landscape page, so there is an issue with this - landscape pages having 25% whitespace on the right hand side. Any ideas?

If this could be sorted I'll start using it.

Many Thanks.

@shamitv

This comment has been minimized.

Copy link

commented Feb 1, 2016

Hi, would it be possible to provide sample html files / urls to test this issue with width of table ?

@PerlTester

This comment has been minimized.

Copy link

commented Feb 1, 2016

Here you go,

3 html files with tables set 100% width.

Resulting PDF shows ok title page and table of contents but the widths are
messed up.

Called from perl using

my $output_part_file1 =
$c->config->{home}.qq{/root/htmldoc/temp/}.qq{part_1}.qq{.html};
my $output_part_file2 =
$c->config->{home}.qq{/root/htmldoc/temp/}.qq{part_2}.qq{.html};
my $output_part_file3 =
$c->config->{home}.qq{/root/htmldoc/temp/}.qq{part_3}.qq{.html};

system qq{"$filepath" --custom-orientations PLP $title_file $template_toc
"$output_part_file1" "$output_part_file2" "$output_part_file3"
--load-error-handling ignore "$output_file"};

where

$filepath" is path to executable

$title_file is qq{cover "titlepath and filename"

$template_toc is qq{toc}

etc.

Cheers

Pat.

On Mon, Feb 1, 2016 at 4:45 PM, Shamit Verma notifications@github.com
wrote:

Hi, would it be possible to provide sample html files / urls to test this
issue with width of table ?


Reply to this email directly or view it on GitHub
#1564 (comment)
.

@PerlTester

This comment has been minimized.

Copy link

commented Feb 2, 2016

Tested with some more HTML and the result is always the same. Where you have 3 html files and you want Portrait followed by Landscape followed by Portrait.

The first file is rendered correctly Portrait with the correct width and styling, colours etc..
The second file is rendered Landscape (great) but with the width of the preceding portrait page.
The third file is rendered Portrait (great) with but it applies the width of the Landscape which oversizes table and div widths to greater than the portrait width pushing it off the page.

Just to note also that header-right and footer-right on the Landscape page is correctly positioned to the far right of the page.

Looks like page size settings may need to be applied along with the landscape global override I'm afraid.

Pat.

@PerlTester

This comment has been minimized.

Copy link

commented Feb 18, 2016

OK here is my offering...

Implemented a new PDF Object parameter --page-orientation with a value of P for portrait and L for landscape.

Given 3 HTML files where you want First Landscape, Second Portrait and Third Landscape invoke as follows:

wkhtmltopdf.exe part_1.htm --page-orientation L part_2.htm --page-orientation P part_3.htm --page-orientation L Output.pdf

Follow the instructions for building on debian jessie 64bit as per the install.md file then overwrite the src and include directories with the attached and then build your binaries.

src_and_include_dir.zip

Tested on Windows 2008R2, Unbuntu 14LTS and Debian Jessie.

Thanks to @shamitv for showing the way, the issue with his code was that you needed to change the orientation in 2 places - once while printing as his does but also on web page build.

Pat.

@ashkulz

This comment has been minimized.

Copy link
Member

commented May 12, 2016

@PerlTester: can you make a PR with your changes?

@PerlTester

This comment has been minimized.

Copy link

commented May 12, 2016

Yes happy to do but need to figure out howto :-) I am a Github newbie

@ashkulz

This comment has been minimized.

Copy link
Member

commented May 12, 2016

Maybe this article can be a starting point?

@PerlTester

This comment has been minimized.

Copy link

commented May 12, 2016

Thanks. I'll give it go over the next day or so.

Pat.

On Thu, May 12, 2016 at 2:06 PM, Ashish Kulkarni notifications@github.com
wrote:

Maybe this article
https://guides.github.com/activities/contributing-to-open-source/ can
be a starting point?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1564 (comment)

@twf-nikhila

This comment has been minimized.

Copy link

commented Jun 29, 2017

It will be great to have this feature included.

@damodaran

This comment has been minimized.

Copy link

commented Jul 12, 2017

@PerlTester Is this merged with the main repo?

@PerlTester

This comment has been minimized.

Copy link

commented Jul 12, 2017

Hi damodaran,

I created a pull request last year but the maintainer said it crashed for him though it works for me on multiple platforms, Linux and windows, ... maybe you can message him to see where its at @askulz

Thanks

@wthinkit

This comment has been minimized.

Copy link

commented Apr 3, 2018

Hi, All
As this feature is hardly added, I think there is always way to find solution, my solution is generate both the specific pages and common pages with '--read-args-from-stdin', then use some libs such as pdfsharp(on .NET platform) to concatenate all pages.
That work as a charm.
Hope can help.

@sguedon

This comment has been minimized.

Copy link

commented Oct 12, 2018

It will be great to have this feature included.

@enotuniq

This comment has been minimized.

Copy link

commented Jan 15, 2019

any news?

@serjebulavsky

This comment has been minimized.

Copy link

commented Apr 2, 2019

Would be great to have this feature

@bahmany

This comment has been minimized.

Copy link

commented Aug 5, 2019

Hi, any good news ?

@PerlTester

This comment has been minimized.

Copy link

commented Aug 11, 2019

New pull request

/pull/4439

@PerlTester

This comment has been minimized.

Copy link

commented Aug 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.