When does webgadget NOT work to view PDFs?

Just starting out? Need help? Post your questions and find answers here.
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

When does webgadget NOT work to view PDFs?

Post by RobertSF »

Wow, a PDF Viewer in just five lines of code.

Code: Select all

If OpenWindow(0, 0, 0, 800, 600, "View PDF", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  fname.s = "C:\pdf_file_you_wish_to_view.pdf"
  WebGadget(0, 10, 10, 780, 580, "file://" + fname)
EndIf
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
There are warnings in these forums that the above approach doesn't always work. On some people's computers, PDFs open in Acrobat or their browser instead of the web gadget. My problem is the opposite. On the computers I can access, it works fine, but I'll be rolling out the application that uses this viewer at work, so I need to find out under what circumstances the above approach fails.

On my computers, I have IE and FireFox and IE and Chrome. I have changed settings variously to save, view, always ask, or open with Acrobat, but no matter what settings I set, the above code continues to work, displaying PDFs in the web gadget just fine.

I know... my problem is that it works! :shock: :lol:
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: When does webgadget NOT work to view PDFs?

Post by Dude »

RobertSF wrote:my problem is that it works!
Doesn't work here. I wouldn't rely on it at all. What if I were your customer?

Image
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: When does webgadget NOT work to view PDFs?

Post by Marc56us »

Reading PDFs is not a native function of browsers, it is a plugin (sometimes installed automatically by some readers)
Edge has its plugin installed by default too.
So for a client application it is better not to rely on it.

A RunProgram("pdf_file.pdf") without any other parameters will work most of the time, because almost all machines have a reader already installed.

Alternatively, it is also possible to deliver with the program a portable PDF reader (single EXE) such as SumatraPDF (open-source)
It can't fill a PDF form, but do the rest.
Don't be afraid of the 'cheap' aspect of the website, this program is excellent.

:wink:
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: When does webgadget NOT work to view PDFs?

Post by Dude »

Marc56us wrote:Don't be afraid of the 'cheap' aspect of the website
Apparently, to be a software success you need a professional website. I had to bite my lip. :? But, SumatraPDF is fantastic.
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: When does webgadget NOT work to view PDFs?

Post by RobertSF »

Dude wrote:
RobertSF wrote:my problem is that it works!
Doesn't work here. I wouldn't rely on it at all. What if I were your customer?
Fortunately, it's at work, where it's a controlled or at least controllable environment, so I can change whatever makes it fail -- but only if I can find out what that is.
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: When does webgadget NOT work to view PDFs?

Post by RobertSF »

Marc56us wrote:A RunProgram("pdf_file.pdf") without any other parameters will work most of the time, because almost all machines have a reader already installed. Alternatively, it is also possible to deliver with the program a portable PDF reader (single EXE) such as SumatraPDF
Here's what I'm trying to do. At work we have to scan enormous amounts of documents. The scanner saves every document named as some string (e.g. "Scan035.3-") followed by a consecutive number. We then have to open every document, see what the title really is, and rename the file. For example, we might rename "Scan035.3-00345665" to "AA Vol x; Pages y thru z." The underlined parts are the only thing that change, and this information is right on the first page of each document. It's tedious when you have to do this for many documents.

My little application would consist of a window with a web gadget and string gadgets to input the underlined information. There would be a button to launch a path requester. The user would select the folder containing the PDFs to rename. The application would then loop through any PDFs in that folder, displaying each in turn in the web gadget and allowing the user to fill out the string fields. When the user pressed the Next button, the application would rename the file and display the next PDF in the folder.

If I use RunProgram, however, I have no control over Sumatra or whatever, and you need to close the file before renaming it. Coincidentally, I use Sumatra and like it.
Hadrian
User
User
Posts: 11
Joined: Fri Nov 09, 2012 12:50 pm

Re: When does webgadget NOT work to view PDFs?

Post by Hadrian »

Check out Pdfium here on this forum and write your own pdf-reader !
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: When does webgadget NOT work to view PDFs?

Post by RobertSF »

Hadrian wrote:Check out Pdfium here on this forum and write your own pdf-reader !
I checked it out, and I would use PDFium loyally if I needed to create and edit PDFs, but I need something simpler to just view them.

I've decided to stick with WebGadget for now. I also use VB.Net, and I've discovered that a basic Acrobat Reader installation, which everyone in a large organization has, includes a PDFLib component you can use to display and navigate through PDF files. Now I just need to figure out how to use it in PureBasic.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: When does webgadget NOT work to view PDFs?

Post by Marc56us »

Normally a scanner produces an image (often uncompressed TIFF) and this is then converted into a more current format (often JPG) which is then often encapsulated in a PDF. (A PDF is text in Postcript and images compressed or not). All then compressed or not in .PDF file.

The ideal would therefore be to visualize the scanner image before transformation.

If this is not possible and the final format is a PDF, then there are several possibilities:
- In Windows 10, the file explorer displays PDFs in the pane. So rename is easy and fast (F2) but not fun: no PB need.
- If the PDF contains only one image (so it did not go through OCR) then it is possible to extract this image with for example one of the XPDF tools. pdftopng will extract the image in png (even if it is in jpg)
:idea: You can even with GrabImage() display only the part of the image necessary for the user to identify it (example the top of page)

pdftopng https://www.xpdfreader.com/pdftopng-man.html (Win, Linux, Mac) :)

:wink:
RobertSF
User
User
Posts: 61
Joined: Thu May 03, 2018 4:24 pm

Re: When does webgadget NOT work to view PDFs?

Post by RobertSF »

Thanks for the info on pdftopng. If I start doing more with the PDF format, it will come in handy.

For now, though, since Web Gadget displays PDFs fine for everyone here at work, I've decided to use that despite the problems other people have had. It was a weekend project, and I basically finished it in less than day.

Here's what it looks like. It's been very well received by my coworkers! Oh, and since the Web Gadget displays HTML, I put the instructions in as an HTML file. Very convenient. And maybe I'll include some CSS to make it prettier. :)
Image
Post Reply