How to resize figures in Quarto (PDF output)? - pdf

I do not get the syntax for resizing graphics in Quarto, could you please give me a hint. The following has no effect.
---
title: "resize image"
format: pdf
---
![World](images/World.pdf){fig-width=5}
![World](images/World.pdf){fig-width=10}
![World](images/World.pdf){fig-width=50%}
![World](images/World.pdf){fig-height=50%}
https://quarto.org/docs/reference/formats/pdf.html#figures
https://quarto.org/docs/authoring/figures.html

You can use width and height, as documented here.
---
title: "resize image"
format: pdf
---
![Elephant with small width](elephant.png){width=10%}
![Elephant with larger height](elephant.png){height=50%}
You can also use px and in as the unit, or specify it between quotes:
![Elephant with height=100px](elephant.png){height=100px}
![Elephant](elephant.png){height=2in}
![Elephant](elephant.png){height="100"}
Why are fig-height and fig-width not working?
As stated in the document you cite, fig-height and fig-width are settings for the default size for figures generated by R or Matplotlib graphics.
Since your image is not generated by R or Matplotlib, you should use pandoc's attributes, as documented here.

Related

How to format images with markdown, Sphinx latexpdf

I have a markdown document that I wish to output in pdf format. I cannot find a way to format the images correctly.
If I use
<center><img src="_images/parameter_form.png" alt="Select Parameters" width="400"></center>
I works perfectly with make html, but with make latexpdf the image does not appear at all.
If I use (based on this stack overflow answer)
![Select Parameters](_images/parameter_form.png) { width=400 }
The images is not sized and the format string { width=400 } appears in the text
What am I doing wrcng?
The answer is to use MyST. This Sphinx parser allows a richer syntax in markdown and specifically the image tag
```{image} _images/parameter_form.png
:alt: Select Parameters
:width: 400px
:align: center
```
Perfect!

Matplotlib Tex Set Font

I would like to have a matplotlib plot in my Latex document that uses the same font as the rest of the document. I read in the matplotlib documentation that if you set the rc parameter 'usetex' to true it will use the 'Computer Modern' font, which is also the standard for Latex.
Trying this gave me the following result.
The title of the plot is generated by matplotlib, the caption by the Latex document. As you can see, the font doesn't match. I think both use 'Computer Modern', but not the same font family. The title (by matplotlib) might be something like 'Sans Serif Roman', while the caption (by the Latex document) is something like 'Serif Roman'. I tried to change the font family with the following:
plt.title("Lorem Ipsum", family='serif', fontsize=20)
But it has no effect as long usetex is activated. I also tried it with fontdict, but it also did not change the font in any way. Also writing the name of a font directly to family does not work.
Is there any way to get the same font as in the Latex document?
Ok, after speding yesterday half a day with searching a solution, I now stumbled over it 5 minutes after asking the question.
Solution:
plt.rcParams['font.family'] = 'serif'
For some reason when usetex=True, setting the fontfamily works only globally.

pdf.js get info about embedded fonts

I am using pdf.js. Fetching the Text I get blocks with font info
Object {
str: "blabla",
dir: "ltr",
width: 191.433141,
height: 12.546,
transform: Array[6],
fontName: "g_d0_f2"
}
Is it possible to get somehow more information about g_d0_f2.
Notice the PDF.js getTextContent will not and not suppose to match glyphs in PDFs. The PDF32000 specification has two different algorithms for text display and extraction. Even if you can lookup font data in the page.commonObjs, it might not be really helpful for extracted text content display due to glyphs encoding mismatch.
The page's getTextContent is doing text extraction and getOperatorList gets (glyph) display operators. See how src/display/svg.js renderer displays glyphs.

How to correctly position a header image with docx4j?

I am trying to convert this Word document with a header showing an image on the right
http://www.filesnack.com/files/cduiejc7
to PDF using this sample code:
https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java
Here's the result:
http://www.filesnack.com/files/ctjs659h
While the Word document has the header image on the right, the converted PDF shows it on the left.
How can I make docx4j to reproduce the original document as PDF?
Your image is positioned relative to a paragraph:
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="791936E3" wp14:editId="575B92C8">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="column">
<wp:posOffset>5317388</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>-325755</wp:posOffset>
</wp:positionV>
docx4j potential to support stuff like that in PDF output is limited by what XSL FO supports. See docx4j's TextBoxTest class for what we can do with text boxes.
Currently, although we can position some textBoxes; we don't do the same for floating images: https://github.com/plutext/docx4j/issues/127
In the meantime, a possible workaround for some cases (eg float right) is to use a table.
Or possibly, you could try putting the image inside a text box!

Adjust PDF options for PhantomJS

I use PhantomJS for PDF generation.
This is my command:
./phantomjs rasterize.js <someurl> test.pdf
It generates pdf file but:
The PDF looks nothing like the original website
I can't set the page orientation
Also is there any other options I can use for pdf generation?
The following change to rasterize.js also doesn't seem to work:
{ format: system.args[3], orientation: 'Letter', margin: '1cm' }
Rasterize.js is a very basic example of screen capture. There are some default values in this example that you can change to your needs.
page.viewportSize
Simulates the size of the window like in a traditional browser. In rasterize.js, it's { width: 600, height: 600 } ; not a common resolution and you may need to change this.
page.paperSize
Defines the size of the web page when rendered as a PDF. There are two modes : Manual (given a width and a height) or automatic (given a format). Do not hesitate to read the webpage documentation and the wiki page.
In your case, orientation: 'Letter' is invalid.
Supported formats are 'A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'.
Supported orientation are 'portrait' and 'landscape'.
Take a look at the source code and change it to your needs !