android-pdfview icon indicating copy to clipboard operation
android-pdfview copied to clipboard

page shows rotated if rotate is other than 0

Open omidaminiva opened this issue 9 years ago • 4 comments

if in metadata rotate is other than 0 then page show rotated

I have a pdf that it shows 90 degree rotated. When I open the file in metadatas for each page there is Rotate 90

<</Type/Page/MediaBox [0 0 612 792]
/Rotate 90/Parent 3 0 R
/Resources<</ProcSet[/PDF /ImageC]
/ExtGState 40 0 R
/XObject 41 0 R
>>

omidaminiva avatar Sep 10 '15 17:09 omidaminiva

@omidaminiva, thank you for your observation. I don't know, when author will fix this moment. But now I can use InputStream and check rotation(may be not better decision, but it works).


  public static byte[] BYTES = new byte[1024];

  public static boolean isRotate(InputStream inputStream) {
    StringBuilder x = new StringBuilder();

    int numRead = 0;
    try {
      while ((numRead = inputStream.read(BYTES)) >= 0) {
        x.append(new String(BYTES, 0, numRead));
        if (String.valueOf(x).contains("Rotate")) {
          if (String.valueOf(x).contains("Rotate 90")) {
            return true; 
          } else {
            return false;
          }
        }
        x.delete(0, numRead-20);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return false;
  }

then in init method:

    try {
      if (Utils.isRotate(new FileInputStream(pdf.path))) {
        pdfView.setRotation(90);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

dimanych avatar Jan 10 '16 15:01 dimanych

Thanks I will give it a try

omidaminiva avatar Jan 11 '16 15:01 omidaminiva

My decision is bad practice, for list of big pdf files (>20mb and if source has'nt word "Rotation") it has big strain. Also it turns out pdf has not only "Rotate 90". I noticed there is rotated pdf-files, where page source look like this:

2008 0 obj
<</Filter/FlateDecode/First 15/Length 150/N 2/Type/ObjStm>>stream
hÞ2403P0P0440S05S°±ÑwÎ/Í+Q04ÖwË,*2,́
‚ô}A<s0/¤² Uß¿´$'3/µØΨÏdD)Ä]#˜æf(F@Tù¥V”€ô˜€y‰E© {!îò‹RË@²ë2KrR5þýgžÈ¼€y>ólæ¥ÌK˜g2Ïbž¨ig`
endstream
endobj

where there rotation information? =(

dimanych avatar Jan 11 '16 17:01 dimanych

barteksc/AndroidPdfViewer shows correct rotation.

layerlre avatar Jun 08 '16 09:06 layerlre