1
$\begingroup$

I have created the following PDF: Basically an image, with a description underneath and a space to take some personal notes:

m = Import[
   "https://images.pexels.com/photos/36455/rose-red-flower-victor-\
hugo.jpg?cs=srgb&dl=flora-floral-flower-36455.jpg&fm=jpg"];

exportIm = 
 Panel[Style[
   Grid[{{im, 
      SpanFromLeft}, {TextCell[
       Row[{"balabalaablabalb balabalbalbalba"}], 
       TextJustification -> 1, Hyphenation -> False], 
      SpanFromLeft}, {}, {"Notes: "}}, 
    Frame -> {{False, False}, {True, True, True, False}, {False}}, 
    BaseStyle -> ImageSizeMultipliers -> 1], 7, 
   FontFamily -> "Helvetica", Background -> White], 
  Background -> White, ImageSize -> {210, 227}*2]

Export["test.pdf", exportIm]

enter image description here

Now I would like to add a QR code to the bottom right of the PDF (which will eventually link to the image on the web).

I now that I can create a QR code...

BarcodeImage["123456789", "QR"]

... but I don't know how to include it into the PDF. Do you know how ?

$\endgroup$
1
$\begingroup$

You could use a few options here, but your best bet is to just use the grid system you already have with Item, to specify the alignment for the barcode manually. Specifically, we'll do Item[BarcodeImage["1"], Alignment->Right] to align to the right edge, coupled with a SpanFromLeft to actually place other content in the column (otherwise it doesn't work correctly - I'm not actually certain why that is).

exportIm = Panel[Style[Grid[{
 {m, SpanFromLeft},
 {TextCell[Row[{"balabalaablabalb balabalbalbalba"}], 
   TextJustification -> 1, Hyphenation -> False], SpanFromLeft},
 {},
 {"Notes: "},
 {SpanFromLeft, 
  Item[BarcodeImage["123456789", "QR"], Alignment -> Right]}
 }, Frame -> {{False, False}, {True, True, True, False}, {False}},
 BaseStyle -> ImageSizeMultipliers -> 1], 7, 
FontFamily -> "Helvetica", Background -> White], 
Background -> White, ImageSize -> {210, 227}*2]

You can modify the third argument to BarcodeImage to choose the size of the QR code.

Other options include Overlay and ImageCompose. These have various issues though - Overlay is a little hard to specify location, and ImageCompose requires Rasterizeing of both inputs before working.

$\endgroup$
  • $\begingroup$ Thank you very much for this great answer ! However, the barcode is not placed at the very bottom of the page. When you export it as pdf you can see that the barcode is below the "Notes" text on the left, but not on the bottom of the page. Do you see an option of how to achieve this ? $\endgroup$ – james Sep 6 '18 at 6:42
  • $\begingroup$ Have you seen my previous comment ? $\endgroup$ – james Sep 6 '18 at 19:58
  • $\begingroup$ mathematica.stackexchange.com/questions/181370/… $\endgroup$ – james Sep 6 '18 at 21:53
  • $\begingroup$ Ah, sorry, I missed this, good idea adding a separate question. $\endgroup$ – Carl Lange Sep 6 '18 at 22:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.