5
$\begingroup$

I am using this answer to embed text in Graphics3D (MMA12.2.0.0, win64) but when exported as pdf the text disappears?

here is the first part of the code from the mentioned answer

Clear[billboard3D];
billboard3D[s_, 
   width_, {x_, y_, z_}, {nx_, ny_, nz_}, {hx_, hy_, hz_}] := 
  Module[{img = Rasterize[s, "Image", Background -> None], height}, 
   height = width ImageAspectRatio[img];
   {FaceForm[White], EdgeForm[None], Texture[ImageData[img]], 
    GeometricTransformation[
     Polygon[{{-.5 width, .5 height, 0}, {.5 width, .5 height, 
        0}, {.5 width, -.5 height, 0}, {-.5 width, -.5 height, 0}}, 
      VertexTextureCoordinates -> {{0, 1}, {1, 1}, {1, 0}, {0, 0}}], 
     Quiet@Composition[TranslationTransform[{x, y, z}], 
       RotationTransform[{{0, 1, 0}, {hx, hy, hz}}], 
       RotationTransform[{{0, 0, 1}, {nx, ny, nz}}]]]}]; 

and then I use it to insert the text as follows

Module[{op = 0.1}, 
 plot = Graphics3D[{Green, Opacity[op], EdgeForm[None], 
    Cuboid[{6, 0, 0}, {10, 6, 5}], Red, Opacity[op], EdgeForm[None], 
    Cuboid[{6, 0, 5}, {10, 6, 10}], Opacity[1], 
    billboard3D[Style["HM", 50, Bold, FontFamily -> "Courier"], 
     3.5, {10, 3, 7}, {1, 0, 0}, {0, 0, 1}], 
    billboard3D[Style["DFN", 50, Bold, FontFamily -> "Courier"], 
     5, {10, 3, 3}, {1, 0, 0}, {0, 0, 1}]}, Axes -> False, 
   ImageSize -> 230, Boxed -> False, ViewPoint -> {1, -1.5, 0.5}]]

Now, this is what I get when export as pdf using Export["....plot.pdf", plot, ImageResolution -> 800]

enter image description here

the Cuboids are very clean but the text doesn't appear!

Then I tried to export as png and this the results

enter image description here

Now I get the text but its background is not the same as the Cuboid and the Cuboid are not clean and smooth as in the pdf?!

--------------Update---------------

I tried also MMA 12.1.1.0 on Ubuntu 18 and this is what obtained when exported as pdf:

enter image description here

-------------------update 2---------

the created pdf file by Mathematic is attached

$\endgroup$
6
  • $\begingroup$ Have you tried with multiple pdf readers? For example, Adobe Acrobat? $\endgroup$
    – Carl Lange
    Commented May 21, 2021 at 19:30
  • $\begingroup$ @CarlLange, yes, I tried also Foxit and both show the same result. $\endgroup$
    – MMA13
    Commented May 21, 2021 at 20:36
  • $\begingroup$ I tried this earlier today in 12.2 and it was fine for me. So something else might be in play. $\endgroup$
    – ihojnicki
    Commented May 22, 2021 at 0:38
  • $\begingroup$ @ihojnicki, I tried that on Ubuntu 18 with MMA 12.1.1.0 and the same result, kindly see the udates. $\endgroup$
    – MMA13
    Commented May 22, 2021 at 12:25
  • 1
    $\begingroup$ @valarmorghulis can you please have a look at my updated answer and let me know if what I suggested is towards what you want? $\endgroup$
    – user49048
    Commented May 26, 2021 at 11:53

2 Answers 2

1
+50
$\begingroup$

I am not sure that this fully fixes the problem, but I observe a better image.

Firstly, I am using

$Version
12.0.0 for Linux x86 (64-bit) (April 7, 2019)

Now, what I did is the following:

  1. I run the code precisely as it is given in the post and generating an image
  2. Right click on the image, Print Graphic, I chose Print to File (PDF), and then just clicked the Print button.

I obtain the following -I just converted it to .png online to be able to post it here. The result seems to be a small improvement compared to the images in the OP I think

enter image description here

Edit: after some comments regarding the issue, I suggest the following:

The code from the OP is given below for convenience

Clear[billboard3D];
billboard3D[s_, 
   width_, {x_, y_, z_}, {nx_, ny_, nz_}, {hx_, hy_, hz_}] := 
  Module[{img = Rasterize[s, "Image", Background -> None], height}, 
   height = width ImageAspectRatio[img];
   {FaceForm[White], EdgeForm[None], Texture[ImageData[img]], 
    GeometricTransformation[
     Polygon[{{-.5 width, .5 height, 0}, {.5 width, .5 height, 
        0}, {.5 width, -.5 height, 0}, {-.5 width, -.5 height, 0}}, 
      VertexTextureCoordinates -> {{0, 1}, {1, 1}, {1, 0}, {0, 0}}], 
     Quiet@Composition[TranslationTransform[{x, y, z}], 
       RotationTransform[{{0, 1, 0}, {hx, hy, hz}}], 
       RotationTransform[{{0, 0, 1}, {nx, ny, nz}}]]]}];

Module[{op = 0.1}, 
 plot = Graphics3D[{Green, Opacity[op], EdgeForm[None], 
    Cuboid[{6, 0, 0}, {10, 6, 5}], Red, Opacity[op], EdgeForm[None], 
    Cuboid[{6, 0, 5}, {10, 6, 10}], Opacity[1], 
    billboard3D[Style["HM", 50, Bold, FontFamily -> "Courier"], 
     3.5, {10, 3, 7}, {1, 0, 0}, {0, 0, 1}], 
    billboard3D[Style["DFN", 50, Bold, FontFamily -> "Courier"], 
     5, {10, 3, 3}, {1, 0, 0}, {0, 0, 1}]}, Axes -> False, 
   ImageSize -> 230, Boxed -> False, ViewPoint -> {1, -1.5, 0.5}]]

Then we use

test = Graphics3D[
   Inset[plot, ImageScaled[{1, 1, 0}], {Center, Center}, 230], 
   AbsoluteOptions[plot], ImageSize -> 230];
Export["figure.pdf", test]

which produces the following (as before I only used an online converter to make it a .png to be able to post it here; on my laptop I have precisely the same .pdf file)

enter image description here

This approach can be found here amongst other ones as well.

Final edit:

I took a screenshot of the .pdf file itself, just to demonstrate that the image is clear -at least on my laptop- and perhaps there is another issue; version of Mathematica(?), document viewer, etc??

This is the screenshot

enter image description here

I am using the standard document viewer of Ubuntu.

$\endgroup$
9
  • 1
    $\begingroup$ thanks for the answer. But still, I think there must be an elegant solution to this where we can be Exporte $\endgroup$
    – MMA13
    Commented May 26, 2021 at 8:57
  • 1
    $\begingroup$ Thanks for the clarification. I'll give it another go bit later to see if I can come up with something better $\endgroup$
    – user49048
    Commented May 26, 2021 at 9:55
  • 1
    $\begingroup$ @valarmorghulis I am getting a very nice looking .pdf file as well, this is why I suggested this approach. I am just using the standard document viewer of Ubuntu. I have included a screenshot to demonstrate. Perhaps you are facing another issue, like mma version, document viewer, or something related? $\endgroup$
    – user49048
    Commented May 26, 2021 at 12:54
  • 1
    $\begingroup$ thanks a lot, it is also working and produces a very nice fig here on Ubuntu. I don't know why on windows it is not working! Thanks again for the efforts! $\endgroup$
    – MMA13
    Commented May 26, 2021 at 13:05
  • 1
    $\begingroup$ @valarmorghulis glad to hear that you were able to make progress. I do not have Windows available and cannot possibly make any comments. I haven't used them in a while to be honest :) $\endgroup$
    – user49048
    Commented May 26, 2021 at 13:06
1
$\begingroup$

Try this:

Module[{op = 0.1}, plot = Style[Graphics3D[{Green, Opacity[op], EdgeForm[None], 
 Cuboid[{6, 0, 0}, {10, 6, 5}], Red, Opacity[op], EdgeForm[None], 
 Cuboid[{6, 0, 5}, {10, 6, 10}], Opacity[1], 
 billboard3D[Style["HM", 50, Bold, FontFamily -> "Courier"], 
  3.5, {10, 3, 7}, {1, 0, 0}, {0, 0, 1}], 
 billboard3D[Style["DFN", 50, Bold, FontFamily -> "Courier"], 
  5, {10, 3, 3}, {1, 0, 0}, {0, 0, 1}]}, Axes -> False, 
ImageSize -> 230, Boxed -> False, ViewPoint -> {1, -1.5, 0.5}], RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}]]
$\endgroup$
10
  • $\begingroup$ thanks a lot for sharing thoughts, that solves the problem when exported as png but with pdf still the same problem. $\endgroup$
    – MMA13
    Commented May 26, 2021 at 6:18
  • $\begingroup$ maybe additionally use Export["plot.pdf", Graphics[Inset[plot, Automatic, Automatic, Scaled[1]]]]? @valarmorghulis $\endgroup$
    – Xuemei
    Commented May 26, 2021 at 13:07
  • $\begingroup$ @Xuemei, thanks for the comment, but the problem still presents $\endgroup$
    – MMA13
    Commented May 26, 2021 at 13:09
  • $\begingroup$ Can you attach or send me the generated pdf? Worth checking if it's a problem with MMA exporter or PDF reader/OS. $\endgroup$
    – Ranza
    Commented May 26, 2021 at 15:52
  • $\begingroup$ @Ranza I checked with different pdf editors but not working too. Kindly see the updates I attached the pdf. $\endgroup$
    – MMA13
    Commented May 26, 2021 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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