0
$\begingroup$

Suppose I have smile.pdf; it's a vector graph. I can Import["smile.pdf"] like below:
enter image description here

How to put this vector graph into coordinates system? Then I can easy rotate and move it. this photo just for explanation

$\endgroup$
0
$\begingroup$

Import the *.pdf file:

smiley = First[Import["xx.pdf"]];

Inspecting the result, we find the following:

Shallow[InputForm[smiley], 7]
   InputForm[Graphics[{Thickness[0.001634], Style[{FilledCurve[<<2>>]},
                       FaceForm[RGBColor[<<4>>]]]}, ImageSize -> {612., 792.},
                      PlotRange -> {{0., 612.}, {0., 792.}}, AspectRatio -> Automatic]]

Particularly important here is the PlotRange setting, which lets us reckon where the FilledCurve[] representing the shape is centered. One can then do something like this:

Graphics[{Blue, First[Cases[smiley, _FilledCurve, ∞]] /. {x_, y_} :> 
         Composition[RotationTransform[60 °],
                     ScalingTransform[{1, 1}/50]][{x, y} - {306, 396}]},
         Background -> Yellow, Frame -> True, FrameStyle -> Gray]

feeling blue

$\endgroup$
  • $\begingroup$ Even I change another pdf,I got same result likeInputForm[Graphics[{Thickness[0.001634], Style[{FilledCurve[<<2>>]},I cannot understand why $\endgroup$ – kittygirl Mar 7 '18 at 11:53
  • $\begingroup$ That's why I asked for a specific PDF file; the strategy will need to be modified for a different PDF, since it is unreasonable to expect PDFs to have uniformity. $\endgroup$ – J. M. will be back soon Mar 7 '18 at 11:56
  • $\begingroup$ Actually, I design vector graph in Adobe Illustrator, and import to Mathematica. Which format is best for import?I mean we should have a general method. $\endgroup$ – kittygirl Mar 7 '18 at 12:04
  • $\begingroup$ "I mean we should have a general method." - unless you can enforce in Illustrator that your vector images be within a preset coordinate range, I don't see a general method being possible. $\endgroup$ – J. M. will be back soon Mar 7 '18 at 12:08
  • $\begingroup$ "I mean we should have a general method." - unless you can enforce in Illustrator that your vector images be within a preset coordinate range, I don't see a general method being possible. $\endgroup$ – J. M. will be back soon Mar 7 '18 at 12:09
0
$\begingroup$

For your example file, after importing the file, just grab the first element which you need and reconstruct graphics with the geometric transformation you want.

If you check InputForm[test4] like J.M. suggested, you can see why you only need to take the first element.

test4 = First[Import["test4.pdf"]];
Shallow[InputForm[test4], 7]
InputForm[ Graphics[{ Thickness[0.0016339869281045752`],  Style[{
FilledCurve[ Skeleton[2]]},  FaceForm[ RGBColor[ Skeleton[4]]]], 
Style[{ JoinedCurve[ Skeleton[3]]},  JoinForm[{ Skeleton[2]}]], 
Style[{ FilledCurve[ Skeleton[2]]}, 
Thickness[0.0016339869281045752`]]}, ImageSize -> {612., 792.},   
PlotRange -> {{0., 612.}, {0., 792.}}, AspectRatio -> Automatic]]
Graphics[Translate[Rotate[test4[[1]], 30 Degree], {-290, -411}], 
 Frame -> True]

enter image description here

$\endgroup$
  • $\begingroup$ where did you get -290,-411? $\endgroup$ – kittygirl Mar 7 '18 at 15:04
  • $\begingroup$ I just manually typed it. $\endgroup$ – halmir Mar 7 '18 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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