title: Generate PDF files from view with Images from network URL in Android
body: <p>I am generating a PDF file using the native PDF Libraries (android.graphics.pdf.PdfDocument) </p>
  
  <p>the document should contain a header that is a static imageView, a few textviews, and a RecyclerView with a bunch of images,</p>
  
  <p>everything except the recyclerview is displayed correctly, </p>
  
  <p>the recyclerview is using the Glide library to load the images but they are not loaded nor displayed,  I tried pre-fetching them using the library but it also does nothing, </p>
  
  <p>here is the code for creating the pdf</p>
  
  <pre><code>    public File createPDF(PostDB postDB) {
      int addition = 0;
      String postDBContent = postDB.getContent();
      if (postDBContent != null) {
          int estimatedLineCount = postDBContent.length() / 43;
          String[] lines = postDBContent.split("\r\n|\r|\n");
          estimatedLineCount += lines.length;
          addition = (estimatedLineCount - 43) * 60;
      }
  
  
      List&lt;String&gt; imagesUrls = postDB.getImagesUrls();
      for (String url : imagesUrls) {
          Glide.with(context).load(url).preload();
      }
  
  
      try {
          FileOutputStream fOut = context.openFileOutput(LOCAL_PATH, Context.MODE_PRIVATE);
          PdfDocument document = new PdfDocument();
          PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(1800, 3900 + addition + 1000, 1).create();
          PdfDocument.Page page = document.startPage(pageInfo);
          Canvas canvas = page.getCanvas();
          LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View content;
          if (inflater != null) {
              final int[] count = {0};
              content = inflater.inflate(R.layout.pdf_layout, null);
              ButterKnife.bind(this, content);
              publisherTextView.setText(postDB.getAuthor());
              Date date = new Date(postDB.getDate());
              DateFormat dateFormat = DateFormat.getInstance();
              String format = dateFormat.format(date);
              dateTextView.setText(format);
              titleTextView.setText(postDB.getTitle());
              contentPreviewTextView.setText(postDBContent);
              recyclerViewImages.setLayoutManager(new GridLayoutManager(context, 2));
              recyclerViewImages.setAdapter(new PDFImageAdapter(postDB.getImagesUrls()));
              String text = postDB.getCity() + ", " + postDB.getCountry();
              location.setText(text);
              int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
              int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);
              content.measure(measureWidth, measuredHeight);
              content.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());
              content.draw(canvas);
  
          }
          document.finishPage(page);
          document.writeTo(fOut);
          document.close();
          fOut.close();
          return new File(context.getFilesDir().getPath() + "/" + LOCAL_PATH);
      } catch (IOException e) {
          Log.i("error", e.getLocalizedMessage());
          return null;
      }
  }
  </code></pre>
  
  <p>here is my code for binding the ViewHolders </p>
  
  <pre><code> public void setData(String url) {
      Glide.with(imageView.getContext()).load(url)
              .listener(new RequestListener&lt;Drawable&gt;() {
                  @Override
                  public boolean onLoadFailed(@Nullable GlideException e, Object model, Target&lt;Drawable&gt; target, boolean isFirstResource) {
                      Timber.d("onLoadFailed");
                      return true;
                  }
  
                  @Override
                  public boolean onResourceReady(Drawable resource, Object model, Target&lt;Drawable&gt; target, DataSource dataSource, boolean isFirstResource) {
                      Timber.d("onResourceReady");
                      return true;
                  }
              })
              .into(imageView);
  }
  </code></pre>
  
  <p>the data onBind method is called, and calls the setData method. but neither callback from Glide is ever called.</p>