Subject: Re: bug#44338: 27.1; EWW can't download and view pdf

From: Eli Zaretskii <[email-masked]>
Date: Thu, 05 Nov 2020 17:49:58 +0200

> From: Nicholas Harrison <[email-masked]>
> Date: Thu, 5 Nov 2020 08:18:19 -0700
> Cc: [email-masked]
> 
> After running the code you gave and using eww to open a pdf, this is what I get:
> 
> Debugger entered--entering a function:
> * select-safe-coding-system("100" nil prefer-utf-8 nil
> "c:/Users/nicho/AppData/Local/Temp/docview1001/!eww
> pdf!-2072e1249b26ee28e656f1a01f0cb4a9/resolution.el")
>   write-region("100" nil "c:/Users/nicho/AppData/Local/Temp/docview1001/!eww
> pdf!-2072e1249b26ee28e656f1a01f0cb4a9/resolution.el" nil silently)
>   #f(compiled-function () #<bytecode 0x1ff19f1>)()
>   doc-view-sentinel(#<process pdf/ps->png> "finished\n")
> 
> Debugger entered--returning value: prefer-utf-8-dos
>   select-safe-coding-system("100" nil prefer-utf-8 nil "c:/Users/nicho/AppData/Local/Temp/docview1001/!eww
> pdf!-2072e1249b26ee28e656f1a01f0cb4a9/resolution.el")
>   write-region("100" nil "c:/Users/nicho/AppData/Local/Temp/docview1001/!eww
> pdf!-2072e1249b26ee28e656f1a01f0cb4a9/resolution.el" nil silently)
>   #f(compiled-function () #<bytecode 0x1ff19f1>)()
>   doc-view-sentinel(#<process pdf/ps->png> "finished\n")

Hmm, that's not the problem you reported originally, and it doesn't
look like Emacs asked you to select an encoding here, did it?

> The buffer it ends up with says:
> Cannot display this page!
> Maybe because of a conversion failure!

So I guess I'm confused now and don't know what is the problem, sorry.

A stub in the dark: if you replace raw-text with raw-text-unix here:

  (defun eww-display-pdf ()
    (let ((data (buffer-substring (point) (point-max))))
      (pop-to-buffer-same-window (get-buffer-create "*eww pdf*"))
      (let ((coding-system-for-write 'raw-text)  <<<<<<<<<<<<<<<<<<<
	    (inhibit-read-only t))
	(erase-buffer)
	(insert data)
	(mailcap-view-mime "application/pdf")))
    (goto-char (point-min)))

does the problem go away?