Skip to content

Commit

Permalink
Initial commit of rust version
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hk committed Jun 24, 2020
0 parents commit 4fbafb4
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rcedit-x64.exe
pdf.ico


#Added by cargo

/target
66 changes: 66 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "chrome-pdf-viewer"
version = "2.0.0"
authors = ["maxloh <[email protected]>"]
edition = "2018"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
url = "2.1.1"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Loh Ka Hong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# chrome-pdf-viewer

This simple rust program served as a shortcut to open pdf in a popup Chrome window without tab bar and address bar

For the old Golang implementation, please check [v1.0](https://github.com/maxloh/chrome-pdf-viewer/tree/v1.0) tag

![Screenshot](https://raw.githubusercontent.com/maxloh/chrome-pdf-viewer/readme/screenshot.png)

## Usage

You need to have Google Chrome installed in order to use this program

- Open File Explorer

- Right click on a PDF file

- Select **Open with** > **Choose another app**

- Check the **Always use this app to open .pdf files** checkbox

- Select **More apps**

- Scroll to the bottom and select **Look for another app on this PC**

- Select the downloaded .exe file from [Releases](https://github.com/maxloh/chrome-pdf-viewer/releases) page, and select **Open**

## Build

### Prerequisites

- [Rust](https://www.rust-lang.org/tools/install) installed

- [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/#vstool-2019-family) installed

- [ImageMagick](https://imagemagick.org/script/download.php#windows) installed (for converting icon to .ico file)

- [Rcedit (x64 version)](https://github.com/electron/rcedit/releases) downloaded and put into your path

### Run the build

- Run **build.bat**

## Credits

- Program icon from [chromium/chromium](https://chromium.googlesource.com/chromium/src/+/28ee90fc0392760f358c16cbb57c0323500d7bb0/chrome/browser/resources/settings/icons.html#123), licensed under [a BSD-style license](https://chromium.googlesource.com/chromium/src/+/refs/heads/master/LICENSE)

- Sample PDF file in screenshot from [mozilla/pdf.js](https://github.com/mozilla/pdf.js/blob/f652cf8e5ea127393ee83e6cb30c51ecd6ce91c3/web/compressed.tracemonkey-pldi-09.pdf), licensed under [Apache License 2.0](https://github.com/mozilla/pdf.js/blob/master/LICENSE)
4 changes: 4 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cargo build --release
magick -background none -density 10000 pdf.svg -trim -scale 256x256 pdf.ico
rcedit-x64.exe .\target\release\chrome-pdf-viewer.exe --set-icon pdf.ico
pause
35 changes: 35 additions & 0 deletions pdf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![windows_subsystem = "windows"]

use std::env;
use std::process::Command;
use url::form_urlencoded;

fn main() {
let args: Vec<String> = env::args().collect();
let path: String = form_urlencoded::Serializer::new(String::new())
.append_pair("", &args[1])
.finish()[1..]
.replace("%3A", ":")
.replace("%5C", "\\")
.replace("+", "%20");
Command::new("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
.arg("--app=".to_owned() + &path)
.spawn()
.expect("PDF viewer failed to start");
}

0 comments on commit 4fbafb4

Please sign in to comment.