Maybe someone can come up with a robust way of identifying rasterized pink boxes? –
Lukas Lang
In the cases I checked (with Mathematica 13.1.0), PDF export with immediate re-import returned the same construct for the pink box in the all cases:
Style[{JoinedCurve[{{{0, 2, 0}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}}}, _, CurveClosed -> {1}]},
JoinForm[{"Miter", 10.}], Thickness[_], RGBColor[1., 0.32941176470588235, 0.32941176470588235, 1.]]
Hence we can implement the check as follows:
vectorExportImportPDF[expr_] :=
First@ImportString[ExportString[expr, "PDF", "AllowRasterization" -> False],
If[$VersionNumber >= 12.2, {"PDF", "PageGraphics"}, {"PDF", "Pages"}],
"TextOutlines" -> False];
containsPinkBoxQ[g_Graphics] :=
Catch[g /. Style[{JoinedCurve[{{{0, 2, 0}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}}}, _,
CurveClosed -> {1}]}, JoinForm[{"Miter", 10.}], Thickness[_],
RGBColor[1., 0.32941176470588235, 0.32941176470588235, 1.]] :> Throw[True]; False]
Here is how it can be used:
containsPinkBoxQ[vectorExportImportPDF[Framed[x, FrameMargins -> fish]]]
True
containsPinkBoxQ[vectorExportImportPDF[Framed[x, FrameMargins -> 1]]]
False
vectorExportImportPDF[
Cell[BoxData[SuperscriptBox["1", "2", "3"]], "Output"]] // containsPinkBoxQ
True
containsPinkBoxQ[vectorExportImportPDF[Image[RandomImage[10], ImageSize -> x]]]
containsPinkBoxQ[vectorExportImportPDF[Image[RandomImage[10], ImageSize -> 10]]]
True
False
Note however, that the exact form of the construct may be version-dependent. Also, despite "AllowRasterization" -> False
in some cases Mathematica rasterizes the contents on Export
, and in such situations this method may not work.
FrontEnd`ExportPacket[BoxData@ToBoxes[...]],"InputForm"]
would work (as used here), but the front-end just returns a default image size. If you doFrontEnd`ExportPacket[BoxData@ToBoxes[Graphics[Inset[...]]]],"InputForm"]
instead, you do kind of get the pink boxes back, but the whole thing is rasterized. Maybe someone can come up with a robust way of identifying rasterized pink boxes? $\endgroup$ErrorBox
. The Docs are silent about this, so I added the tag "undocumented". $\endgroup$Image[]
does not do any validation on theImageSize
option value. This implies that the error is only revealed when the FE tries to display the image. $\endgroup$