Save as - does not correctly display the filetype to save as.
SumatraPDF version
- Version 3.5.2; and Prerelease 3.6.17065 (Windows 11 x64)
Describe the bug When saving files which are open-able but which have no file-name extension, almost all file-types EXCEPT Mobi and CBZ/CBR default to PDF, and do not save with a filename extension. Mobi, however, does save with a .mobi extension.
To Reproduce Steps to reproduce the behavior:
- open an openable document (without extension) in this case, generally an .fb2, .epub, or .azw
- ctrl-s
- in save-as box, the file will be detected as PDF but when saving, the file wil save with no file name extension.
Expected behavior I would expect SumatraPDF to determine correctly the filetype of the file and automatically indicate which file type to save as, and add the filename extension.
Additional context The context of this problem is that I am managing a large collection of files from a hard disk. The files were originally on a *nix system, where file-extensions were unnecessary or unused. SumatraPDF is one of the few programs available which can open a stack of files (20+ files at a time) to determine the content. Unfortunately while it OPENS the file accurately (generally) it does not list the file-type for saving purposes. This means it leaves the saving of the file type up to the user who needs to guess which file type the file is.
PLEASE NOTE, I am uncertain if this is a bug, or a feature request. I apologise in advance if this is posted in the wrong thread.
hmmm Windows relies heavily on the extension for setting file associations so it would be odd to use files without them in SumatraPDF and in some cases would not expect to open them if not associated by their extension.
you could perhaps use a "shim" batch file to detect format and rename the same as say IrfanView may but that is not a part of current SumatraPDF file "sniffing". If it can open them by header format it usually will pass to correct file engine but does not auto change names as that's user prerogative.
a more complex way is a rename utility that understands the target filetypes like this
dir /b *.
2fish
ddequery15s
Large_World_Map_bright
Untitled
>rename
The syntax of the command is incorrect.
>rename.exe
Renamed: \2fish -> \2fish.pdf
Renamed: \ddequery15s -> \ddequery15s.zip
Renamed: \Large_World_Map_bright -> \Large_World_Map_bright.jpg
Renamed: \Untitled -> \Untitled.png
however, that requires windows native c# code for speed so the CS file you would edit to suit is
using System;
using System.IO;
using System.Collections.Generic;
class FileTypeRenamer
{
static Dictionary<byte[], string> magicHeaders = new Dictionary<byte[], string>(new ByteArrayComparer())
{
{ new byte[] { 0x25, 0x50, 0x44, 0x46 }, ".pdf" },
{ new byte[] { 0xFF, 0xD8, 0xFF }, ".jpg" },
{ new byte[] { 0x89, 0x50, 0x4E, 0x47 }, ".png" },
{ new byte[] { 0x50, 0x4B, 0x03, 0x04 }, ".zip" },
// Add more as needed
};
static void Main()
{
string folder = Directory.GetCurrentDirectory();
foreach (string file in Directory.GetFiles(folder))
{
string ext = Path.GetExtension(file);
if (string.IsNullOrEmpty(ext))
{
byte[] header = new byte[8];
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
fs.Read(header, 0, header.Length);
}
foreach (var kvp in magicHeaders)
{
if (StartsWith(header, kvp.Key))
{
string newName = file + kvp.Value;
File.Move(file, newName);
Console.WriteLine(string.Format("Renamed: {0} -> {1}", file, newName));
break;
}
}
}
}
}
static bool StartsWith(byte[] fileHeader, byte[] magic)
{
for (int i = 0; i < magic.Length; i++)
{
if (fileHeader[i] != magic[i]) return false;
}
return true;
}
class ByteArrayComparer : IEqualityComparer<byte[]>
{
public bool Equals(byte[] a, byte[] b)
{
if (a.Length != b.Length) return false;
for (int i = 0; i < a.Length; i++)
if (a[i] != b[i]) return false;
return true;
}
public int GetHashCode(byte[] obj)
{
int hash = 17;
foreach (byte b in obj)
hash = hash * 31 + b;
return hash;
}
}
}
the command to compile the above rename.cs will be
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc /platform:x86 /reference:System.IO.Compression.dll /reference:System.IO.Compression.FileSystem.dll rename.cs
How can I change Cntr S to Cntr Shift S and vice versa as this is creates lot of problem, because when you read file you normally save annotation in the same file and you don't create another file everytime you save, and pressing three keys instead of two is also little akward.