title: Android: Create identical Views for drawing on Canvas of PdfDocument for printing
body: <p>I'm using Views inflated from XML to draw on the Canvas of a PdfDocument.Page. 
  The problem is, that the generated PDF looks different on different devices (text size, height and width ), depending on screen size etc.. </p>
  
  <p>Is there a way to create identical Views no matter what the screen size is, so that I get identical PDFs. Dp, sp, px, pt all respect somehow the physical device.
  Maybe overwriting some values of screen-size etc. in Context?</p>
  
  <p>Here is my code for generating a PDF Document:</p>
  
  <pre><code>LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.pdf_person_container, null);
  
  PdfDocument document = new PdfDocument();
  PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(595,842,1).create();
  PdfDocument.Page page = document.startPage(pageInfo);
  
  int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
  int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);
  view.measure(measureWidth, measuredHeight);
  view.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());
  
  view.draw(page.getCanvas());
  
  document.finishPage(page);
  document.writeTo(new FileOutputStream(filePath + "Detail.pdf"));
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/iPhPi.jpg" rel="nofollow noreferrer">PDF on phone 1</a></p>
  
  <p><a href="https://i.stack.imgur.com/EqQi5.jpg" rel="nofollow noreferrer">PDF on phone 2</a></p>