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

Factor of 2.54 in sozi2pdf #195

Closed
rainwoodman opened this Issue Aug 20, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@rainwoodman

rainwoodman commented Aug 20, 2013

The testing svg file can be found on http://web.phys.cmu.edu/~yfeng1/test-sozi2pdf.svg

With phantomjs 1.9.1 (the prebuild linux binary downloaded from phantomjs.org site),
pages produced by sozi2pdf are wrongly clipped: each slide spans two pages in vertical, and clipped horizontally.

http://web.phys.cmu.edu/~yfeng1/test-sozi2pdf-no-254.pdf

If I set the page zoom factor to 1/ 2.54 in soze2pdf.js, the page is no longer cropped:
... onCallback() = ...
page.zoomFactor = 1 / 2.54
...
http://web.phys.cmu.edu/~yfeng1/test-sozi2pdf-w-254.pdf

This seems to be a unit conversion problem (possible in phantomjs?)

@senshu

This comment has been minimized.

Show comment
Hide comment
@senshu

senshu Aug 20, 2013

Owner

Thanks for reporting this issue. I will have a look at this.

Owner

senshu commented Aug 20, 2013

Thanks for reporting this issue. I will have a look at this.

@neuralyzer

This comment has been minimized.

Show comment
Hide comment
@neuralyzer

neuralyzer Aug 22, 2013

I experienced the same problem. And did the following workaround. I only have the problem with the PDF export function of phantomjs. You can also export your presentation as png with phantomjs. Just change the following function in sozi2pdf.js:

page.onCallback = function (fileName) {
    page.render(tmpDir + fileName + ".png");
};

for convenience I also added an option screen to sozi2pdf.py:

PAGE_FORMATS = {
    "a4":     { "width_mm": 297, "height_mm": 210 },
    "letter": { "width_mm": 279, "height_mm": 216 },
    "screen": { "width_mm": 1024, "height_mm": 768 }
}

DEFAULT_RESOLUTION = 2

the default resolution of 2 produced acceptable results.

Note that pdfjoin still handles png. Nothing else to change! Clearly having a PDF consisting of png images is not as nice as a "real" PDF containing vector data. However, as backup solution for presentations it still does the job.

I think this supports your thought on the bug being located in phantomjs.

neuralyzer commented Aug 22, 2013

I experienced the same problem. And did the following workaround. I only have the problem with the PDF export function of phantomjs. You can also export your presentation as png with phantomjs. Just change the following function in sozi2pdf.js:

page.onCallback = function (fileName) {
    page.render(tmpDir + fileName + ".png");
};

for convenience I also added an option screen to sozi2pdf.py:

PAGE_FORMATS = {
    "a4":     { "width_mm": 297, "height_mm": 210 },
    "letter": { "width_mm": 279, "height_mm": 216 },
    "screen": { "width_mm": 1024, "height_mm": 768 }
}

DEFAULT_RESOLUTION = 2

the default resolution of 2 produced acceptable results.

Note that pdfjoin still handles png. Nothing else to change! Clearly having a PDF consisting of png images is not as nice as a "real" PDF containing vector data. However, as backup solution for presentations it still does the job.

I think this supports your thought on the bug being located in phantomjs.

@senshu

This comment has been minimized.

Show comment
Hide comment
@senshu

senshu Oct 21, 2013

Owner

@rainwoodman In my latest attempt with PhantomJS 1.9.0, I had to set the zoom factor to 0.5.

@neuralyzer I can add an option to choose the export method: PDF or PNG.

Owner

senshu commented Oct 21, 2013

@rainwoodman In my latest attempt with PhantomJS 1.9.0, I had to set the zoom factor to 0.5.

@neuralyzer I can add an option to choose the export method: PDF or PNG.

@rainwoodman

This comment has been minimized.

Show comment
Hide comment
@rainwoodman

rainwoodman Oct 21, 2013

It is worth it to a pre-scaling factor (multiplied on the user set zoom
factor) to correct the problem in phantomJS?

The phantom bus is here:

ariya/phantomjs#10659

  • Yu

On Mon, Oct 21, 2013 at 9:01 AM, Guillaume Savaton <notifications@github.com

wrote:

@rainwoodman https://github.com/rainwoodman In my latest attempt with
PhantomJS 1.9.0, I had to set the zoom factor to 0.5.

@neuralyzer https://github.com/neuralyzer I can add an option to choose
the export method: PDF or PNG.


Reply to this email directly or view it on GitHubhttps://github.com/senshu/Sozi/issues/195#issuecomment-26714665
.

rainwoodman commented Oct 21, 2013

It is worth it to a pre-scaling factor (multiplied on the user set zoom
factor) to correct the problem in phantomJS?

The phantom bus is here:

ariya/phantomjs#10659

  • Yu

On Mon, Oct 21, 2013 at 9:01 AM, Guillaume Savaton <notifications@github.com

wrote:

@rainwoodman https://github.com/rainwoodman In my latest attempt with
PhantomJS 1.9.0, I had to set the zoom factor to 0.5.

@neuralyzer https://github.com/neuralyzer I can add an option to choose
the export method: PDF or PNG.


Reply to this email directly or view it on GitHubhttps://github.com/senshu/Sozi/issues/195#issuecomment-26714665
.

@senshu

This comment has been minimized.

Show comment
Hide comment
@senshu

senshu Nov 11, 2013

Owner

I still do not understand how PhantomJS handles paper size and viewport size.

The resolution used in PhantomJS is supposed to be 72dpi.
However, to get the desired paper size, I have to set a resolution of 72 dots per centimeter.

Then a zoom factor of 0.5 is needed before rendering to avoid clipping.

Owner

senshu commented Nov 11, 2013

I still do not understand how PhantomJS handles paper size and viewport size.

The resolution used in PhantomJS is supposed to be 72dpi.
However, to get the desired paper size, I have to set a resolution of 72 dots per centimeter.

Then a zoom factor of 0.5 is needed before rendering to avoid clipping.

@senshu senshu closed this Apr 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment