Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Julian Reschke
    @reschke
    so two related to media queries, one related to a CSS variable
    what about the third line?
    Guillaume Ayoub
    @liZe
    About the third line, I think that it’s because var() is not supported in properties with multiple values
    Julian Reschke
    @reschke
    thanks for the feedback; very helpful
    Guillaume Ayoub
    @liZe
    No problem ;)
    Zakaria Alamiddine
    @ZakariaAlamiddi_twitter

    hello,
    I am using weasyprint to generate pdf from html, on my local machine I have Ubuntu 18.04.4 LTS the pdf is generated correctly.
    While on the deployement env, I am using docker : python:3.7-alpine the layout and the font are not generated correctly.
    In my docker file I add :
    RUN apk update \
    && apk add postgresql && apk add postgresql-dev build-base jpeg-dev zlib-dev gcc python3-dev musl-dev postgresql-contrib postgresql-client \
    && apk add wkhtmltopdf xvfb && apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf-dev

    RUN apk add --no-cache \
    libstdc++ \
    libx11 \
    libxrender \
    libxext \
    libssl1.1 \
    ca-certificates \
    fontconfig \
    freetype \
    ttf-dejavu \
    ttf-droid \
    ttf-freefont \
    ttf-liberation \
    ttf-ubuntu-font-family \
    && apk add --no-cache --virtual .build-deps \
    msttcorefonts-installer \
    \

    Install microsoft fonts

    && update-ms-fonts \
    && fc-cache -f \

    Clean up when done

    && rm -rf /tmp/* \
    && apk del .build-deps

    to keep the fonts
    Guillaume Ayoub
    @liZe
    @ZakariaAlamiddi_twitter Hello!
    Could you please share your PDF?
    Zakaria Alamiddine
    @ZakariaAlamiddi_twitter

    finally I found the solution by adding this:
    RUN apk add --no-cache msttcorefonts-installer fontconfig
    RUN update-ms-fonts

    Google fonts

    RUN wget https://github.com/google/fonts/archive/main.zip -O fonts.zip
    RUN unzip fonts.zip
    RUN mkdir -p /usr/share/fonts/truetype/google-fonts
    RUN find $PWD/fonts-main/ -name ".ttf" -exec install -m644 {} /usr/share/fonts/truetype/google-fonts/ \; || return 1
    RUN rm -f fonts.zip
    RUN fc-cache -f && rm -rf /var/cache/

    Guillaume Ayoub
    @liZe
    Oh, OK
    Zakaria Alamiddine
    @ZakariaAlamiddi_twitter
    I download all the google fonts and my pdf is generated perfectly
    Guillaume Ayoub
    @liZe
    That’s strange, because you already had a lot of fonts installed
    Zakaria Alamiddine
    @ZakariaAlamiddi_twitter
    ah sorry, I remove this part :
    RUN apk add --no-cache \ libstdc++ \ libx11 \ libxrender \ libxext \ libssl1.1 \ ca-certificates \ fontconfig \ freetype \ ttf-dejavu \ ttf-droid \ ttf-freefont \ ttf-liberation \ ttf-ubuntu-font-family \ && apk add --no-cache --virtual .build-deps \ msttcorefonts-installer \
    the problem was with this fonts
    these*
    luknetcompany
    @luknetcompany

    Hi everyone, hope you are all doing well.

    I am not very new to WeasyPrint but need some help.

    I am using it in Django and wanted to know how I can send a document directly to the printer without creating a PDF file
    Guillaume Ayoub
    @liZe
    Hello!
    Do you want to send your document to a printer installed on the web server, or on the web client?
    luknetcompany
    @luknetcompany
    Web client
    html_template = get_template('invoice.html').render(context).encode(encoding="UTF-8") pdf_file = HTML(string=html_template, base_url=request.build_absolute_uri()).write_pdf() response = HttpResponse(pdf_file, content_type='application/pdf') response['Content-Disposition'] = 'inline; filename=Order #' + str(order.id) + '.pdf'
    that is my current code which generates a PDF
    Guillaume Ayoub
    @liZe
    Well, with this code the browser should display the PDF file and display an icon to print it, doesn’t it?
    luknetcompany
    @luknetcompany
    Yes, but I am using electron.js to wrap my Django web app on windows so there is no way to go back to my app without closing the whole thing and starting from the beginning again. If I run the web app from a browser, there is no issue, I get a prompt to save the pdf file
    Guillaume Ayoub
    @liZe
    Oh, OK
    I don’t know electron very well, but I suppose that it wokrs like a browser and that you can force the app to download the PDF instead of displaying it in your window
    Using attachment instead of inline
    luknetcompany
    @luknetcompany
    That is correct. but I'm new to electron and Node.js in general (used it the first time yesterday). I used something called "nativefier" to create a package. It does all its magic and just presents me with an EXE file and some other files that don't even look familiar. So editing the package would take me ages, I thought editing the output of WeasyPrint would be easier since I would be editing some python code, which I am very familiar with
    Guillaume Ayoub
    @liZe
    Oh
    But
    Changing inline into attachment would be in the Python code, isn’t that what you want?
    luknetcompany
    @luknetcompany
    oh I thought you meant adding something like that in electron.js
    let me try in python

    It seems that would work, but this electron.js also seems like it's blocking prompts.
    I just tested from a browser and I get a prompt to save the file.
    I guess this 80% of the work done. Thanks a million!

    I will just look into getting the "save file" prompt to display in electron. Have a great day!

    Guillaume Ayoub
    @liZe
    Cool! Have fun with WeasyPrint!
    luknetcompany
    @luknetcompany

    ahh actually its now sorted. The electron.js is now saving the file directly to my downloads folder without asking me where I want to save. Which is a bit ridiculous.

    Thanks again!!

    luknetcompany
    @luknetcompany
    is there a way to send the output straight to the printer page?
    Oh, didn't get a response to my original question though
    Guillaume Ayoub
    @liZe
    No, I don’t think so :/
    Andy Kluger
    @AndydeCleyre

    Hello! I'm using HTML(string=html, media_type='screen').write_png(...) and it's working great.

    Can I prevent the line wrapping, or increase the max line length?

    Also in a separate step I am removing the transparent border, with imagemagick/graphicsmagick, but can I prevent it being added in the first place?

    Guillaume Ayoub
    @liZe
    Hello @AndydeCleyre
    You can prevent line wrapping using white-space
    And the transparent border is caused by page margins
    You can remove them using @page{ margin: 0 }
    Andy Kluger
    @AndydeCleyre
    The source content is wrapped in pre, isn't that following the spec you link? Here's a sample: http://ix.io/3pTe
    . And you're saying I should manipulate the html before it gets to weasy, injecting the margin bit? Thanks for the help!
    oh I see now the pre-wrap bit
    Andy Kluger
    @AndydeCleyre
    But if I change the whitespace to pre, weasy truncates the long line and doesn't extend the bg that far either.