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

Page clipRect is ignored if output is PDF #10465

Closed
leplatrem opened this issue Mar 28, 2012 · 45 comments
Closed

Page clipRect is ignored if output is PDF #10465

leplatrem opened this issue Mar 28, 2012 · 45 comments
Labels

Comments

@leplatrem
Copy link

leplat...@gmail.com commented:

Which version of PhantomJS are you using? Tip: run 'phantomjs --version'.
1.5.0 (development)

Reproductible with the following snippet :

var page = new WebPage(),
    address, output, size;

if (phantom.args.length < 2 || phantom.args.length > 3) {
    console.log('Usage: rasterize.js URL filename');
    phantom.exit();
} else {
    address = phantom.args[0];
    output = phantom.args[1];
    page.viewportSize = { width: 1600, height: 1200 };
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
        } else {
            window.setTimeout(function () {
                page.clipRect = {top: 100, left: 100, 
                                 width: 200, height: 200};
                page.render(output);
                phantom.exit();
            }, 200);
        }
    });
}

Which operating system are you using?

Ubuntu 11.10

Did you use binary PhantomJS or did you compile it from source?

Using antono ppa : https://launchpad.net/~antono/+archive/phantomjs

Please provide any additional information below.

Similar issue was marked as invalid : http://code.google.com/p/phantomjs/issues/detail?id=134

Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #465.
🌟   6 people had starred this issue at the time of migration.

@aconrad
Copy link

aconrad commented Jul 11, 2012

alexandr...@gmail.com commented:

Same problem here with PhantomJS 1.6.0. PNG works just fine though.

@trainiac
Copy link

adkison....@gmail.com commented:

Any plans to fix this in the near future? Better yet, is there anywhere to read what is on the roadmap?

@rouge8
Copy link

rouge8 commented Dec 14, 2012

a...@andyfreeland.net commented:

Problem persists in PhantomJS 1.7.0.

@eranimo
Copy link

eranimo commented Mar 25, 2013

Any update? This still occurs.

@sudiptochoudhury
Copy link

I am using 1.9 and the problem persists. It ignores the clipRect and captures the whole page.

@dan-mesa
Copy link

1.9.1 and the problem persists. Have any of you been using a workaround? I'm thinking about phantomjs -> png -> pdf, but that's unfortunate.

@ova2
Copy link

ova2 commented Sep 24, 2013

This issue is important indeed! Can we hope that clipRect is accepted by PDF rendering in the next PhantomJS version? Thanks in advance.

@JustinAiken
Copy link

👍

@skion
Copy link

skion commented Jan 15, 2014

Had a quick look, and even though in PhantomJS the path to "print" a PDF is entirely different from the path to "render" a pixel image (probably to retain vector-ish properties), in the end this seems to be primarily a limitation in the underlying Qt library.

However, it does look possible to add a clipRect feature to QWebFrame::print(), potentially by overloading that function with a clipRect, similar to QWebFrame::render(), and in that case passing onto printContext::spoolRect() instead of printContext::spoolPage() at the lowest level.

Again, from what I can see we'd need a patch in QtWebkit in order to fix this; I don't see yet how it can be worked around just in PhantomJS without going via a pixel image.

@mateuszjarzewski
Copy link

You can very easly do pdf rect-clip render using combination of iframes and body overflow hidden style and height.
I just bump to it after many hours of playing about.
Have fun!

@mailtorakeshp
Copy link

@mateuszjarzewski Can you please share some piece of code on how you achieved it?

@adonishong
Copy link

This issue still there in 1.9.7... Looking forward the day this issue be fixed...

@mateuszjarzewski Would you please share in work around in achieving your method, thank you very much.

@mandb
Copy link

mandb commented Oct 17, 2014

... :|

@vbauer
Copy link
Contributor

vbauer commented Nov 21, 2014

Version 1.9.8. Problem is still there.

@mahnunchik
Copy link

+1

1 similar comment
@xvik
Copy link

xvik commented Nov 22, 2014

+1

@vbauer
Copy link
Contributor

vbauer commented Nov 22, 2014

I've just found, that parameters top:0 & left:0 (with any values for width & height) render full page instead of specific area.

@Friedel-Castor
Copy link

I have the same problem. I want to select a DOM-Element and render only those to a pdf.
This solution helped me to find a workaround:
http://stackoverflow.com/questions/1535331/how-to-hide-all-elements-except-one-using-jquery

It hides all elements except the element that i want to render.
The only thing i changed was the order of the commands.
Here is my Code:

page.includeJs(jquery, function(){
       page.evaluate(function (element){
        $(element).appendTo('body');
        $('body > :not(' + element + ')').hide(); 
       }, element);       
      });
window.setTimeout(function(){
        page.render("page.pdf");
      },1000);

Maybe it helps someone

@eranimo
Copy link

eranimo commented Mar 18, 2015

This issue is now three years old and many people are having this problem. Maybe it should be a higher priority?

@cabralmartin
Copy link

+1

6 similar comments
@mrmarktyy
Copy link

+1

@ugoertz
Copy link

ugoertz commented Jun 11, 2015

+1

@GoldHornKing
Copy link

+1

@juazemar
Copy link

+1

@sergey-datskevich-vrp
Copy link

+1

@angelim
Copy link

angelim commented Jul 12, 2015

+1

@szakharchenko
Copy link

+1

@deekookee
Copy link

+1

3 similar comments
@alex7egli
Copy link

+1

@ggevgg
Copy link

ggevgg commented Aug 20, 2016

+1

@ZhichaoY
Copy link

+1

@bulinutza
Copy link

It would be a life saver if page.clipRect behaved the same in .pdf as in the image formats. Please please add this :-)

@leplatrem
Copy link
Author

If it is a matter of life maybe it would be worth considering providing some help to the maintainers of this project #justsaying

@bulinutza
Copy link

@leplatrem I really would if I have the knowledge required or the time. My company is heavily relying on phantomjs and we would be willing to pay for a phanomjs license is funding was something that would help the development efforts.

@sreejithz
Copy link

+1 👍
me too waiting for this.

@Jeff-14159
Copy link

+100 need this fixed too. on 2.1.1

@leplatrem
Copy link
Author

leplatrem commented Feb 14, 2017

Adding +1* here won't have much impact. AFAIK it is clearly stated that the program is distributed as-is and without any warrantee.

Maybe relying on a funding platform (like http://www.fixthatbug.com or whatever) could help. If several companies need that bug fixed, they could gather funds to attract developers with the right skillset.

(my 2 cents)

@szakharchenko
Copy link

@leplatrem , I suppose those who really needed the functionality just wrote a simple ghostscript-based workaround like me:).

@leplatrem
Copy link
Author

@szakharchenko now you can start a company that sells the script to those who seem to really need it ;)

@rlsz
Copy link

rlsz commented Aug 7, 2017

+1

2 similar comments
@rubystar
Copy link

+1

@vvvvoid
Copy link

vvvvoid commented Oct 12, 2017

+1

@Hamza-324
Copy link

@szakharchenko mind sharing ? I really need it !

@rlsz
Copy link

rlsz commented Nov 17, 2017

@Hamza-324
I inject jquery, hide all other tags, then print the area.
A temporary solution:

var width=$('.print').width();
var offset=20;
$('.print').parents().each(function(index,item){
	$(item).siblings().hide();
	$(item).css("margin", "0").css("border", "0px").css("padding", "0px").css("overflow","hidden");
});
$('.print').css("margin", offset+"px").css("border", "0px").css("padding", "0px").width(width);

@ghost ghost removed old.Priority-Medium labels Dec 19, 2017
@stale stale bot added the stale label Dec 25, 2019
@stale
Copy link

stale bot commented Dec 28, 2019

Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 28, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

No branches or pull requests