Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Page Orientation V.2019 #4439

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

PerlTester
Copy link

This updated commit adds the necessary code to allow Portrait and Landscape page
changes within a PDF document.

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

@SankethJain
Copy link

Hi @PerlTester, I would like to understand if your change can handle when an html spans multiple pages?

Example:
If the content is dynamic, there is a possibility that the content in an html overflows to the next page in the pdf, and if I have specified 2 htmls (1 portrait, 1 landscape), it is expected to churn out 3 pages.

Or, if an html uses the following css code

@media screen, print{
	section {
		page-break-before: always;
	}
}

This works in the existing release. Just wondering if it would work in yours as well.

@PerlTester
Copy link
Author

PerlTester commented Aug 27, 2019 via email

@SankethJain
Copy link

Sounds great.
In issue #1564, user shamitv had released an alpha version (in 2016) for this idea, but I encountered an issue in the PLP scenario. The portrait after the landscape pages were taking the width of the landscape. This is not an issue with your pull, right?

Also, is it possible for you to generate a binary with your changes and share it as an alpha, until the final merge happens? I am working on a requirement that could really use this feature.

Thanks for the reply.

@PerlTester
Copy link
Author

PerlTester commented Aug 27, 2019 via email

@SankethJain
Copy link

Would you be able to produce an alpha version, so that I don't have to wait for the merge to complete? Would that be ok?

@PerlTester
Copy link
Author

PerlTester commented Aug 28, 2019

Alpha with absolutely NO warrantee, Ubuntu 18.04 Bionic deb file zipped under windows!!!

wkhtmltox_0.12.6-0.20180619.5.dev.4f1b79d.bionic_amd64.zip

Windows 64 - multi-part winzip files below, remove .zip from filename of .z01 and .z02

wkhtmltox-0.12.6-0.20190712.20.dev.e3fa5a9.msvc2015-win64_multipart.z02.zip
wkhtmltox-0.12.6-0.20190712.20.dev.e3fa5a9.msvc2015-win64_multipart.zip
wkhtmltox-0.12.6-0.20190712.20.dev.e3fa5a9.msvc2015-win64_multipart.z01.zip

@SankethJain
Copy link

Is there a windows executable version of this?

@SankethJain
Copy link

SankethJain commented Aug 30, 2019

Hi @PerlTester. This works just as intended.

In fact, I just discovered a hidden gem, that I can have different headers/footers for each of the pages. It even skipped the 1st page of the document as I had expected.
Code: (Ignore the repetition)
wkhtmltopdf.exe abc.html --page-orientation P --header-html header.html --footer-html header.html abc.html --page-orientation L --header-html header.html --footer-html header.html abc.html --page-orientation P --header-html header.html --footer-html header.html abc_combined.pdf
Which produces:
abc_combined.pdf

Alternatively, to have a common header/footer for the entire document, you can write as below:
Code:
wkhtmltopdf.exe --header-html header.html --footer-html header.html abc.html --page-orientation P abc.html --page-orientation L abc.html --page-orientation P abc_combined_3.pdf
Which produces:
abc_combined_3.pdf

I hope this makes it into the final merge.

Be warned

Given the above feature, writing a code like below will only produce header/footer for the last page(s) only.
Code
wkhtmltopdf.exe abc.html --page-orientation P abc.html --page-orientation L abc.html --page-orientation P --header-html header.html --footer-html header.html abc_combined_2.pdf
abc_combined_2.pdf

Additional documents for replication
abc.html.txt
header.html.txt
FinPctGraphs.js.txt
Site.css.txt

P.S. Note to @ashkulz Kindly look into this and merge. This feature has been requested since Feb 2014.
Thanks in advance.

@PerlTester
Copy link
Author

Happy to be of help.

P.

@duoi
Copy link

duoi commented Sep 11, 2019

@ashkulz any update on when this will be reviewed/merged to the trunk?

@azinchenko
Copy link

We plan to use version wkhtmltopdf with different page orientation. But we have had some problems with packaging. May I ask you to built wkhtmltopdf with this functionality for CentOS 7 64?

@PerlTester
Copy link
Author

PerlTester commented Nov 2, 2019 via email

@jeslabbert
Copy link

Happy to be of help.

P.

Hi PerlTester would you be willing to help advise us on a project where we need what you have done inside of a PHP environment?

@PerlTester
Copy link
Author

PerlTester commented Nov 15, 2019 via email

@jerbob92
Copy link

Can someone please look into this? We're still on a really old version because we need this for our application.

@vasildb
Copy link

vasildb commented Jan 8, 2020

Internal links between pages doesn't seem to work regardless of --disable-external-links and --enable-external-links options.

@mrdj07
Copy link

mrdj07 commented Mar 12, 2020

@PerlTester I'm having random errors when trying to print a large table that can span over 1 or more pages. I've noticed I get a lot more failures when the table spans over two pages.

Here's the output I get:
Loading pages (1/6) [> ] 0% [> ] 0% [> ] 1% [=> ] 2% [=> ] 3% [==> ] 4% [===> ] 5% [===> ] 6% [====> ] 7% [====> ] 8% [=====> ] 9% [======> ] 10% [=======> ] 13% [==========> ] 17% [============> ] 21% [===============> ] 25% [==================> ] 30% [===================> ] 33% [======================> ] 38% [========================> ] 41% [===========================> ] 46% [==============================> ] 50% [================================> ] 54% [==================================> ] 58% [=====================================> ] 62% [=======================================> ] 66% [==========================================> ] 70% [============================================> ] 74% [===============================================> ] 79% [=================================================> ] 82% [====================================================> ] 87% [======================================================> ] 90% [=========================================================> ] 95% [============================================================] 100% Counting pages (2/6) [====> ] Object 1 of 12 Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load. Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load. Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load. [===============> ] Object 3 of 12 [===================> ] Object 4 of 12 [========================> ] Object 5 of 12 [==============================> ] Object 6 of 12 [==================================> ] Object 7 of 12 [=======================================> ] Object 8 of 12 [=============================================> ] Object 9 of 12 [=================================================> ] Object 10 of 12 [======================================================> ] Object 11 of 12 [============================================================] Object 12 of 12 Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown Loading TOC (3/6) [======> ] 10% [==============================> ] 50% [=====================================> ] 63% [===========================================> ] 73% [================================================> ] 80% [============================================================] 100% [======> ] 10% [==============================> ] 50% [============================================================] 100% Resolving links (4/6) [====> ] Object 1 of 12 [=========> ] Object 2 of 12 [===============> ] Object 3 of 12 [===================> ] Object 4 of 12 [========================> ] Object 5 of 12 [==============================> ] Object 6 of 12 [==================================> ] Object 7 of 12 [=======================================> ] Object 8 of 12 [=============================================> ] Object 9 of 12 [=================================================> ] Object 10 of 12 [======================================================> ] Object 11 of 12 [============================================================] Object 12 of 12 Loading headers and footers (5/6) [> ] 0% [> ] 1% [=> ] 2% [=> ] 3% [==> ] 4% [===> ] 5% [===> ] 5% [===> ] 6% [====> ] 7% [====> ] 8% [=====> ] 9% [======> ] 10% [======> ] 10% [=======> ] 13% [==========> ] 17% [============> ] 21% [===============> ] 25% [================> ] 28% [===================> ] 32% [=====================> ] 36% [========================> ] 40% [=========================> ] 43% [============================> ] 47% [==============================> ] 51% [=================================> ] 55% [==================================> ] 58% [=====================================> ] 62% [=======================================> ] 66% [==========================================> ] 70% [===========================================> ] 73% [==============================================> ] 77% [================================================> ] 81% [===================================================> ] 85% [====================================================> ] 88% [=======================================================> ] 92% [=======================================================> ] 93% [============================================================] 100% Printing pages (6/6) [> ] Preparing [====> ] Page 1 of 14 [========> ] Page 2 of 14 [============> ] Page 3 of 14 [================> ] Page 4 of 14 [=====================> ] Page 5 of 14 [=========================> ] Page 6 of 14 [==============================> ] Page 7 of 14 [==================================> ] Page 8 of 14 [======================================> ] Page 9 of 14

When it works, it works perfectly. Please let me know if you need more test code. Thanks !

@knash94
Copy link

knash94 commented Apr 23, 2020

@PerlTester Great work, this works great but I've found a bug that I think is related to the issue @mrdj07 was having.

I believe if the document orientation is set to Portrait, but the last page is a landscape and contains multiple pages it will then produce an error

@ashkulz ashkulz added this to the 0.12.7 milestone Jun 9, 2020
src/lib/pdfconverter.cc Outdated Show resolved Hide resolved
@jerbob92
Copy link

What do you think @PerlTester, time for a v.2020? :D

@PerlTester
Copy link
Author

@jerbob92 seems like @ashkulz has put it in the pipeline for 0.12.7 release so here's hoping we see it soon🥇

@ashkulz
Copy link
Member

ashkulz commented Nov 24, 2020

Sorry, wasn't able to spend time on this project lately. @PerlTester, not sure about this comment you made earlier -- do you plan to incorporate the change in the PR?

@ashkulz
Copy link
Member

ashkulz commented Nov 24, 2020

Great work, this works great but I've found a bug that I think is related to the issue @mrdj07 was having.

I believe if the document orientation is set to Portrait, but the last page is a landscape and contains multiple pages it will then produce an error

@knash94, can you link/add a minimal test case so that we can verify this?

@PerlTester
Copy link
Author

PerlTester commented Nov 24, 2020 via email

Modified lines 952 & 953 as per update in message thread
@PerlTester
Copy link
Author

Hi @ashkulz I have updated the PR with the change I have suggested, can you check if all is well. I have also done a bit of extensive testing on the reported failure of multiple landscape pages but cannot get it to fail or replicate an error as suggested by @knash94

Thanks for progressing.

P.

@ahmed-bhs
Copy link

@ashkulz any updates !

@jerbob92
Copy link

Since we missed Amit's birthday this year for a new release, I suspect the next release will be Jun 10, 2022.
Can we get this into that release @ashkulz ?

@leond08
Copy link

leond08 commented Feb 10, 2022

any updates

@PerlTester
Copy link
Author

PerlTester commented Feb 10, 2022 via email

@jerbob92
Copy link

I have kinda lost hope on this too and we have scheduled to migrate our wkhtmltopdf logic to something else, like https://github.com/puppeteer/puppeteer

@PerlTester
Copy link
Author

PerlTester commented Feb 10, 2022 via email

@erakadjiev
Copy link

Hi @ashkulz, any hope that 0.12.7 (and mainly this patch) will ever be released? Or should wkhtmltopdf be considered practically abandoned?

@PerlTester Thank you very much for creating this patch!
Do you have any recent suggestion for a good alternative to wkhtmltopdf? @jerbob92 did you already migrate to something else?

@jerbob92
Copy link

@erakadjiev not yet. Will probably be Puppeteer or Gotenberg

@PerlTester
Copy link
Author

PerlTester commented Sep 27, 2022 via email

@erakadjiev
Copy link

@jerbob92 @PerlTester Thank you for the replies! Would be good if Chromium would address that issue soon. I'll check out Gotenberg - I haven't heard about it before. Thanks!

@jerbob92
Copy link

@erakadjiev I imagine Gotenberg would have the same issue as Puppeteer since it also uses Chromium, but it's seems to fit this use-case a bit better than Puppeteer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet