PDF Files created on Terminal - linux

I created a pdf file on the Ubuntu's terminal and add plain text. When I use cat it shows the wrote text, no problem. But if I try to open the file with a pdf viewer it says that is corrupted and I can't see.
Why this happen?
There is a way of see the file out of the terminal?
I'm new at Linux.
Remember, the file contains only plain text, and I can normally see the content at the terminal.

Related

Using Octave to "Edit" notepad file instead of "Open" in Windows

I use Windows 10 and an .exe program (in-house code written by a colleague) that imports data from .txt files. Since 99% of my use of .txt files are for this program, I've changed the default Windows program so that this .exe file is run automatically when opening a .txt file. If I need to access the .txt file directly, or use it for another purpose, I right-click and choose "edit."
I'm now writing a program of my own (using Octave 4.4.1), which also uses .txt files that sometimes need to be opened/edited, but if I use "open(filename)" in my Octave script, of course it just opens the .exe file. I can open the .txt file from there, but I'd like to skip this middle step, since the aforementioned .exe program is not intended to be used in this process, and there are other users of my code that don't have the .exe program installed.
Is there a way to duplicate the right-click/edit feature in Windows within Octave code? "edit(filename)" opens the file in the native Octave editor, which is technically viable, but not exactly a desirable scenario. I've also tried changing the default Octave editor to Notepad, and I've tried Notepad++ as well, but I have had absolutely no luck, even with significant effort, of making Octave use an external default editor of any kind (even when I remove the .exe program as the default for .txt files). Thanks in advance for any advice you can offer.
You can send command-line commands from Octave using the system() function.
For example, to open the file in notepad, you could do
[status, output] = system("notepad <path_to_text_file>.txt");
If notepad isn't in your system path, you will have to add it to or use the full path to the notepad executable
Or, if you want to use Notepad++, add it to your system path and then do
[status, output] = system("notepad++ <path_to_text_file>.txt");

Getting corrupted PDF file after reading and rewriting it to a new file

I am exploring PDF file format and trying to edit and manipulate its internal data. the problem is that I noticed I always get corrupted files after making any minor change to a file so I tried a very simple example to just read the pdf data and rewrite it to a new "file.pdf" without making any changes, as follows:
file = open('sample.pdf','r',encoding='ansi').read()
file_ = open('output.pdf','w').write(file)
but again I got a corrupted file (can't be opened using Adode reader) so I tried to open it using Google Chrome and it worked properly but with the font has changed to the default instead of the original font file.
I opened the input and output files and compared them using notebad++ and two files matched exactly!
I also opened the output file and copied its content and pasted it to the input file and surprisingly, it worked well, exactly as the input file.
Any ideas what is the problem?

File created in linux transferred to Windows shows corrupted

I have created an Excel file from delimted text file using awk in linux terminal transferring the same to windows. when opened it shows a pop-up "This file might be corrupted or unsafe.would you like to open?"But on tapping yes I could see data everything is fine as expected.How to avoid such pop-up.
I have tried to convert to .xlsx then I couldn't even see the data
I tried to zip and send then unzip same warning popsup
My guess as to what is going on is that the incoming Excel file is still basically a Linux file, but MS Office, being flexible, is allowing you to open it. For a one time fix, try the following steps from Windows Excel:
Open the Linux Excel file (some_file.xlsx)
Save as another file name (some_new_file.xlsx)
Close Excel
Delete some_file.xlsx and rename some_new_file.xlsx to some_file.xlsx
Now try opening the file again, and hopefully the error message will have gone away.

Corrupt Text File read/write/open

I have a large text file that I take notes in; Recently, after saving it, it won't open and gives following error. I tried a few things on web that didn't work---opening in different encoding format, etc. Nothing worked. Any idea how I can open it again? Is there a language I can use from bash? I'm very familiar with PHP. Any ideas? Different text editor?
Error:
"The document “ToDo.txt” could not be opened. Text encoding Unicode (UTF-8) isn’t applicable."
"The file may have been saved using a different text encoding, or it may not be a text file."
cat the file from the CLI and make sure your data is still there. Then you could simply copy and paste the output into a new file and hopefully get rid of whatever weird encodings are causing that text editor to not read the file.

PDF display garbled in Chrome

I see this when clicking a link to a PDF stored on Amazon S3 in Chrome:
If I download the same URL using wget or follow the same link in Firefox the PDF displays normally.
It looks like Chrome is not interpreting the file as a PDF. Is the problem with the PDF file or with Chrome? The PDF file was generated by wkhtmltopdf 0.12.3 (with patched qt) on Arch Linux.
Edit: it seems like a problem with the PDF because when I use file to identify the format it returns "data" whereas a normal PDF returns something like "PDF document, version 1.6".
I figured it out. I was using PDFKit to generate PDFs with the verbose option on. The verbose option somehow put all of stdout inside the PDF itself which caused Chrome to not detect the file as a PDF.

Resources