title: Generating a PDF with custom size in android with PdfDocument
body: <p><a href="https://developer.android.com/reference/android/graphics/pdf/PdfDocument" rel="nofollow noreferrer">PdfDocument</a> is a class that makes it possible to generate a PDF from an Android View. You simply add a View to <code>PdfDocument</code> and then save the PDF to memory.</p>
  
  <p>However, I wouldn't like to add a View that is already rendered in the screen, because such View is only good for smartphone screens, and I want to generate a PDF document for printers. </p>
  
  <p>Therefore, I want to pass a View without rendering. While it's certainly possible for me to do that, how would the dimensions and proportions be decided? How can I control this in my PDF?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Following the answer below from clotodex, I did:</p>
  
  <pre><code>    LayoutInflater inflater = getLayoutInflater();
      View linearview;
      linearview = inflater.inflate(R.layout.printed_order,
                                    findViewById(android.R.id.content),
                                    false);
  
      PdfDocument document = new PdfDocument();
      PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2480, 3508, 0).create();
      PdfDocument.Page page = document.startPage(pageInfo);
  
      linearview.draw(page.getCanvas());
      document.finishPage(page);
  
      OutputStream outStream;
      File file = new File(getExternalFilesDir(null), "pedido.PDF");
  
      try {
          outStream = new FileOutputStream(file);
          document.writeTo(outStream);
          document.close();
          outStream.flush();
          outStream.close();
  </code></pre>
  
  <p>but I get an empty PDF. If I do </p>
  
  <pre><code>View view = findViewById(android.R.id.content);
  view.draw(page.getCanvas());
  </code></pre>
  
  <p>in place of</p>
  
  <pre><code>linearview.draw(page.getCanvas()); 
  </code></pre>
  
  <p>I get the activity I'm in, which confirms everything is rigth, except for the view that I'm trying to print.</p>