Related
For example, I have files named "a" from locations a and b and I put them together into same folder. Is there some best practice, how to rename those duplicates so the old name remains distinguishable?
The content of those files is downloaded via libcurl from various URLs, so I have the host-names of those files, but there can be the same file-name on same host with different path and I know the paths of those files, but the paths can be too long to be stored in a file-name.
I also have Adler-32 hashes of those files, but there can be a file with the same content with the same name, so putting the hash into the file-name would result into new duplicates.
So I want to store the original file-name into new file-name to not lose the original name, but add something to not overwrite the older files. I am not satisfied with Windows systems appending " - copy", because you end up getting file-names like "a - copy - copy", I am not satisfied with Ubuntu appending " (copy)"/" (another copy)"/" (3rd copy)"/" (4th copy)"/...
Maybe just adding number of instance of file-name would be fine, but putting the number at the beginning of the file-name breaks file-name sorting and putting it at the end changes the extension if there wasn't any like "a" => "a.0".
I have large batches of pdf files that must be merged.
Folder1 FileName Explaination: invoice12-105767-1510781492.pdf - 105767 is the component that will match with a pdf filename in Folder2.
"invoice12-" First section of the filename. This can sometimes be "invoice11-" or "invoice6-" so merging based on character length became challenging. The "invoicexx-" are based on where in the system the file came from.
"105767" Second part of the filename. This is the key component for matching and merging. this will be the filename in Folder2 it belongs with.
"-1510781492.pdf" Third part of the filename is a system generated unique ID, which can contain more or less characters.
Folder1:
invoice12-105767-1510781492.pdf
invoice12-105768-1510781484.pdf
invoice12-105769-1510781469.pdf
Folder2:
105767.pdf
105768.pdf
105769.pdf
OutputFolder:
Example I don't want to merge all the files in both folders into 1 huge file. I need them merged based on the Folder2 filename. (105767.pdf + invoice12-105767-1510781492.pdf) in that order specifically, also.
The final output should be three pdf files merged in order as follows:
105767.pdf + invoice12-105767-1510781492.pdf to make 1 file named 105767.pdf
105768.pdf + invoice12-105768-1510781484.pdf to make 1 file named 105768.pdf
105769.pdf + invoice12-105769-1510781469.pdf to make 1 file named 105769.pdf
I would appreciate any assistance with a way to automate this process. I merge over 800 files per day. This small automation would shave hours off my day and my wrist from carpel tunnel.
I primarily use Mac OS 10.13.1. I have looked around in Mac's "Automater" program and cannot figure out how to get it to do what I need. (I did figure out a great way to split files into single pages)
I downloaded pdftk server (since that is Mac compatible) but cannot figure out if this type of match and merge is capable with this program.
I have Adobe Acrobat DC Professional and it does not seem to have this match and merge function.
I am even open to other paid programs. I just need a fairly future-proof way of getting this mundane task done through automation on my Mac.
You can take a look at the APDFL library examples that are provided with sample code. These libraries are supported on Mac, but are not free.
https://dev.datalogics.com/adobe-pdf-library/sample-program-descriptions/c1samples/#mergedocuments
Here is a snippet of the code you would need to use:
APDFLDoc doc1 ( csInputFileName1.c_str(), true);
APDFLDoc doc2 ( csInputFileName2.c_str(), true);
// Insert doc2's pages into doc1.
// Here, we've stated PDLastPage, which adds the pages just before the last page of the target.
// If we specify PDBeforeFirstPage instead, doc2's pages will be inserted at the head of doc1.
PDDocInsertPages ( doc1.getPDDoc(),
PDLastPage,
doc2.getPDDoc(),
0,
PDAllPages,
PDInsertAll,
NULL, NULL, NULL, NULL);
doc1.saveDoc ( csOutputFileName.c_str(), PDSaveFull | PDSaveLinearized);
I have a big folder with many files in it that need to rename, by comparing it to a list of a JSON output.
Here is a sample of the JSON output:
[
{"title":"The Little Hours","year":"2017","imdbid":"tt5666304","scid":"10080"},
{"title":"CarGo","year":"2017","imdbid":"tt6680792","scid":"10079"},
{"title":"My Little Pony: The Movie","year":"2017","imdbid":"tt4131800","scid":"10078"},
{"title":"Amityville: The Awakening","year":"2017","imdbid":"tt1935897","scid":"10077"}
]
The actual list has over 10,000 entries. In my folder I have the file names that matches with the scid. For example 10080.mp4. In the JSON list, scid 10080 is equals to the title The Little Hours
I know how to loop through the entire folder to read the names of the file, but I am stuck on reading this JSON file.
my pseudo code is something like:
For each file in (folder)
if file.name = Json.scid then
Rename(file, json.title(of that scid))
I'be Googled around but the other JSON examples does not look similar to the JSON output I have.
For every typescript file visual studio code uses an auto indentation of 8 spaces. This is a bit too much for my taste but I can't find where to change it.
Maybe it's available as a setting but under a different name as I can't find anything related to indentation.
UPDATE
I'm currently using the Prettier code formatter and that solves all formatting problems by auto formatting on save (if there is no syntax error)
In the toolbar in the bottom right corner you will see a item that looks like the following:
After clicking on it you will get the option to indent using either spaces or tabs. After selecting your indent type you will then have the option to change how big an indent is. In the case of the example above, indentation is set to 4 space characters per indent. If tab is selected as your indentation character then you will see Tab Size instead of Spaces
If you want to have this apply to all files and not on an individual file basis, then override the Editor: Tab Size and Editor: Insert Spaces settings in either User Settings or Workspace Settings depending on your needs
Edit 1
To get to your user or workspace settings go to Preferences -> Settings. Verify that you are on the User or Workspace tab depending on your needs and use the search bar to locate the settings. You may also want to disable Editor: Detect Indentation as this setting will override what you set for Editor: Insert Spaces and Editor: Tab Size when it is enabled
You can change this in global User level or Workspace level.
Open the settings: Click the gear on the bottom left, then click Settings as shown below.
Then, do the following 2 changes: (type tabSize in the search bar)
Uncheck the checkbox of Detect Indentation
Change the tab size to be 2/4 (Although I strongly think 2 is correct for JS. Haha :))
To change the indentation based on programming language:
Open the Command Palette (CtrlShiftP | macOS: ⇧⌘P).
Type and select: Preferences: Configure Language Specific Settings... (command id: workbench.action.configureLanguageBasedSettings).
Select a programming language (for example TypeScript).
If Settings menu is opened (since 1.66.0):
4. Press → to place the cursor right beside the language filter (e.g. #lang:typescript).
5. Type Tab Size and enter your preferred value in the text box.
If settings.json file is opened:
4. Add this code:
"[typescript]": {
"editor.tabSize": 2
}
See also: VS Code Docs
Code Formatting Shortcut:
VSCode on Windows - Shift + Alt + F
VSCode on MacOS - Shift + Option + F
VSCode on Ubuntu - Ctrl + Shift + I
You can also customize this shortcut using preference setting if needed.
column selection with keyboard
Ctrl + Shift + Alt + Arrow
You might also want to set the editor.detectIndentation to false, in addition to Elliot-J's answer.
VSCode will overwrite your editor.tabSize and editor.insertSpaces settings per file if it detects that a file has a different tab or spaces indentation pattern. You can run into this issue if you add existing files to your project, or if you add files using code generators like Angular Cli. The above setting prevents VSCode from doing this.
In my case "EditorConfig for VS Code" extention is overriding VSCode settings.
If you have it installed, then check .editorconfig file in the root folder of the project.
Here is an example config. The "indent_size" sets the number of spaces for a tab.
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
How to turn 4 spaces indents in all files in VS Code to 2 spaces
Open file search
Turn on Regular Expressions
Enter: ( {2})(?: {2})(\b|(?!=[,'";\.:\*\\\/\{\}\[\]\(\)])) in the search field
Enter: $1 in the replace field
How to turn 2 spaces indents in all files in VS Code to 4 spaces
Open file search
Turn on Regular Expressions
Enter: ( {2})(\b|(?!=[,'";\.:\\*\\\/{\}\[\]\(\)])) in the search field
Enter: $1$1 in the replace field
NOTE: You must turn on PERL Regex first. This is How:
Open settings and go to the JSON file
add the following to the JSON file "search.usePCRE2": true
Hope someone sees this.
Simplified explanation with pictures for those that googled "Change indentation in VS Code"
Step 1: Click on Preferences > Settings
Step 2: The setting you are looking for is "Detect Indentation", begin typing that. Click on "Editor: Tab Size"
Step 3: Scroll down to "Editor: Tab Size" and type in 2 (or whatever you need).
Changes are automatically saved
Example of my changes
To set all existing files and new files to space identation to 2 just put it in your settingns.json (in the root of json):
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
you can add the language type of the configuration:
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
Setting the indentation in preferences isn't allways the solution. Most of the time the indentation is right except you happen to copy some code code from other sources or your collegue make something for you and has different settings. Then you want to just quickly convert the indentation from 2 to 4 or the other way round.
That's what this vscode extension is doing for you
Step 1: Open settings.json in vscode
Step 2: Add the lines as below for the programming language (an example is below)
For typescript and javascript
"editor.detectIndentation": false,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
},
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
Problem: The accepted answer does not actually fix the indentation in the current document.
Solution: Run Format Document to re-process the document according to current (new) settings.
Problem: The HTML docs in my projects are of type "Django HTML" not "HTML" and there is no formatter available.
Solution: Switch them to syntax "HTML", format them, then switch back to "Django HTML."
Problem: The HTML formatter doesn't know how to handle Django template tags and undoes much of my carefully applied nesting.
Solution: Install the Indent 4-2 extension, which performs indentation strictly, without regard to the current language syntax (which is what I want in this case).
I wanted to change the indentation of my existing HTML file from 4 spaces to 2 spaces.
I clicked the 'Spaces: 4' button in the status bar and changed them to two in the next dialog box.
I use 'vim' extension. I don't how to re-indent without vim
To re-indent my current file, I used this:
gg
=
G
Check tabWidth if you are using a formatter, that was the issue in my case. It represents the number of spaces used in tabs.
Adding on: yes, you can use the bottom-right UI to configure the space settings. But if you have existing code that's not formatted to the new spacing, then you can right-click anywhere within the file and click Format Document. Took me a while to figure this out until I stumbled on this issue.
Format Document menu
For me it was docs-markdown andDocs Authoring Pack. Microsoft's many modules messing with each other yet again! Disabled the extensions and now good to go again 😀
The Problem of auto deintending is caused due to a checkbox being active in the settings of VSCode.
Follow these steps:
goto preferences
goto settings
search 'editor:trim auto whitespace'
Uncheck The box
The following search-and-replace regex changes the number of spaces per indentation level from 4 to 2 in existing files. It's relatively easy to understand, reliable, and doesn't require installing anything.
Instructions
Press CtrlH (or ⌥⌘F on macOS).
Make sure regex matching is on by clicking on the .* button in the search popup or pressing AltR (or ⌥⌘R on macOS).
In the Find field, enter ^(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?
In the Replace field, enter $1$2$3$4$5$6$7$8$9
Finally press CtrlEnter (or ⌘Enter on macOS) to apply to the current file.
You could also use this in the Search pane on the left to do this across all files in your project. However, note that this should only be run once per file. It will mess up the indentation of files that already use 2 spaces.
Extra Credit: How It Works
The way the regular expression works is it matches groups (?: ... ) of four spaces at a time at the beginning ^ ... of each line, only capturing ( ... ) the first two spaces. Each indentation level is optional ... ?, so it works for as many indentation levels as the pattern is repeated and there are in each line. Then it replaces the whole pattern with only the captured spaces $1, $2, ..., effectively replacing every four-space indentation level with two spaces.
This pattern only works up to 9 indentation levels (I'm not sure if $10 would work, but if so this could be expanded indefinitely).
Extra Extra Credit: Extending
You could adapt the pattern to decrease the number of spaces per indentation level in a file from any original number to another lower target number.
Put the target number of spaces inside the inner parenthesis. Then, put the remaining original number of spaces in the outer parenthesis, so the total number of spaces in the pattern is the original.
For example, if you want to change the indentation level from 6 to 4, repeat this search pattern as many times as you like:
^(?:( ) )? or ^(?:( {4}) {2})?
And use the same number of $1, $2 in the replacement pattern.
First, check if you have installed "EditorConfig for VS Code". It was overriding my editor settings. I spent all day correcting this problem.
In the project find .editorconfig file and ones changed there it will work.
I like these settings for indentation you can modify them according to need.
You can open VScode setting.json file by typing CTRL+SHIFT+P and paste below the JSON setting
setting.json
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"editor.wrappingIndent": "deepIndent",
"editor.autoIndent": "full"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"editor.wrappingIndent": "deepIndent",
"editor.autoIndent": "full"
}
With VSCode 1.75 (Jan. 2023), indentation is also customizable on VSCode terminals, not just VSCode views.
See issues 170432: "Add a terminal tab stop size (editor.tabSize) setting"
When a tab is printed in the terminal, it has a tab size of 8 spaces, regardless of the tab size setting.
Therefore, PR 170733 adds a new setting:
terminal.integrated.tabStopWidth: The number of cells in a tab stop
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking for a free tool that allows re-arranging pages of a PDF document and combining multiple pages per sheet. The first part (re-arranging) is easily solved by many tools (I use PyPDF).
The problem is with the second requirement: to combine two (or more) pages into single page. For example, take two pages (A and B), rotate them, scale and combine into a single page like this
------ ------ ------
| | | | | |
| A | | B | | a |
| | | | | |
| | | | ---> ------
| | | | | |
| | | | | b |
| | | | | |
------ ------ ------
The solution needs to work on Linux and preferably on Windows too. I'm looking for either console application or library with Python or Perl bindings.
Edit there is pdfnup library that is supposed to perform exactly this kind of transformation, and is cross-platform, however I cannot use it due to a bug similar to this.
This is a summary of the tools I found for PDF (I wanted to find the equivalent of psup and psbook)
Create booklets: pdfbook, pdf-tools (command: pdfbklt)
Merge PDF files: pdfmerge, pdfjam (command: pdfjoin)
Rotate pages: pdfjam (command: pdf90)
Multiple pages per sheet: pdfjam (command: pdfnup)
Create posters (multiple sheets per page): pdfposter
From my package manager:
pdf-tools: http://search.cpan.org/dist/Text-PDF
pdfbook: http://www.ctan.org/tex-archive/support/pdfbook/
pdfmerge: https://github.com/dmaphy/pdfmerge
pdfjam: http://go.warwick.ac.uk/pdfjam
pdfposter: http://pdfposter.origo.ethz.ch/
Create an A6 booklet:
pdfbook -2 -p a5 infile.pdf outfile.pdf
pdf-tools contains:
pdfbklt: create booklets
pdfrevert: Removes one layer of changes to a PDF file, trying to maximise the size of the output file (to account for linearised PDF).
pdfstamp: Adds the given string to the infile .pdf file at the given location, font and size.
There is also multivalent: http://multivalent.sourceforge.net/Tools/index.html
On Linux, you can convert the PDF files to Postscript and use psnup. The exact way to invoke it depends on exactly how you want the pages to be put together, whether you want them rotated, what paper size(s) you want to use, etc. but it'll be something like this:
pdf2ps infile.pdf infile.ps
psnup -2 infile.ps outfile.ps
ps2pdf outfile.ps outfile.pdf
Depending on what tools you have available, you might have a more efficient way to do this - psnup is certainly not the only way, but it's a relatively well-known program (on Linux anyway).
If you use Linux, you can use BookletImposer for putting multiple PDF pages on one single page.
For Ubuntu users, this tool is available at Ubuntu Software Center.
Check out this answer that uses Multivalent to impose PDF pages
In answer to your question, you'll need a PDF 'Imposition' tool, which is a fancy way of saying a tool that arranges PDF page images onto a particular array to create a NEW single PDF page. Imagine it's something like typesetting a newspaper. You define an array of slots a certain number of columns wide, by a certain number of rows deep, on a page of a certain fixed dimensions (in cm). Then you fill those empty slots top to bottom, left to right with pages from a pdf source-file. In the case of the OP, they want to create a single page, composed of two 8.5x11 pages arranged in a 1x2 array (1 column, 2 rows). Their pages will be dropped into the array in the following order: 1,2. So you are dropping the first page (page 1 of the pdf) into the first slot of your array (Column 1, row 1), and you are dropping the second page (page 2) into the second slot (Column 1, row 2).
How to use the tool to make this happen:
Download the old version of Multivalent. Note the author removed the good tool classes from the latest edition without explanation, so you have to use an older one. Here's a working link as of 02/12:
http://code.google.com/p/pdfsizeopt/downloads/detail?name=Multivalent20060102.jar
For simplicity, I renamed the jar file to m.jar.
It sort of goes without saying that you need to install JRE for this to work, but I'll put it out there.
Add m.jar to your Java Class Path Environment variables (for scripting) or run the command line syntax with the -cp option and the relative path (shown below). Note, I ran it FROM the command-line at the install directory in my example below. Provide an absolute path from root otherwise (like c:\1\bin\m.jar).
Here is an example that will accomplish exactly what OP posted about:
C:\1\bin>java -cp m.jar tool.pdf.Impose -dim 1x2 -verbose -papersize "21.59x55.88cm" -layout "1,2" yourfilename.pdf
Note, the -dim option creates the array in Columns x Rows. The -papersize is specified in centimeters here, but if you need inches, just multiply inches by 2.54 to get cm. The -layout option gives you the order you want to fill the empty slots in your array, filling from top to bottom and left to right. In this case, we want page one of the pdf on top and page two on the bottom, so our argument is "1,2". The final argument is your actual source file. The tool will output a file called yourfilename-up.pdf when you are done.
Hope that helps.
-Matt Zweil
Check the source code of PyPDF, especially the rotateClockwise() method. There must be a place where the content of a page is written. Insert a "q" operator (save state) and "cm" (with the correct parameters for a scaling matrix) before the content and a "Q" operator (restore state) afterwards.
See the PDF documentation for an explanation of operators and the structure of a page (scroll to the bottom for some useful links).
Don't forget to send a patch to PyPDF :)
[EDIT] You might also want to check the pdfjam sources which include a pdfnup command.
This is a perl function I use to grab a directory full of prn files from a 3rd party app and create a single merged pdf.
sub runMerged($)
{
my($path) = #_;
print "Generating merged PDFs for $path\n";
my #files = sort(getFiles($path, ".prn\$"));
if (scalar(#files))
{
open(MERGE, ">$path/merged.prn");
for (my $i = 0; $i < scalar(#files); $i++)
{
print MERGE "^L\n" if ($i > 0);
open(FN, "$path/" . $files[$i]);
while (my $line = <FN>)
{
print MERGE $line;
}
close(FN);
}
chdir("$BASE_PATH/txt2pdf");
print `./txt2pdf.pl $path/merged.prn`;
}
}
I Had a similar need this week.
But I needed to repeat each A4 page (landscape) "twice" in the A3 sheet (portrait), to later cut then in half.
I found a Acrobat Plugin with tons of imposition features that worked great for my needs, and with a fully functional 30 days trial.
Hope It could be helpfull for someone else.
http://www.pdfsnake.com/
I had the same issue as you and this is what I did:
Extracted all the pages in the pdf file as a separate file each
In irfanView (with plugins) I created a Vertical "Panoramic" image
Dragged the pdf files over to the images section
Clicked created
The "image" is created with all the pages following each other as one very long vertical image
You can export to PDF with almost no loss in quality.
Enjoy
Here's a script for repeating pages (like A5, landscape) twice on a sheet double this size (A4, portrait):
#!/bin/bash
INPUTFILE=$*
PAGENUM=`pdftk ${INPUTFILE} dump_data | grep NumberOfPages | cut -d : -f 2 | cut -d " " -f 2`
PAGES=`seq 1 ${PAGENUM}`
DUPAGES=`for i in ${PAGES} ; do echo $i $i | tr "\n" " " ; done`
OUTPUT1=`basename ${INPUTFILE} .pdf`.dup.pdf
OUTPUT2=`basename ${INPUTFILE} .pdf`.double.pdf
pdftk ${INPUTFILE} cat ${DUPAGES} output ${OUTPUT1}
pdfjam --nup 1x2 ${OUTPUT1} --outfile ${OUTPUT2}
It's not really elegant; it could be done without the second pdftk call, and it does not work with files containing spaces. But it works with multi-page pdfs.
Using Adobe Acrobat XI Pro, open the 1st document.
Edit, select "take a snapshot", then click at the top corner of what you want to copy and drag to the opposite corner.
Have an open clean sheet in Paint.
Click over to the clean sheet in paint and control V to paste the 1st document into the clean sheet.
Repeat for the 2nd item that you want to combine on the same page except position the 2nd item UNDER the 1st item temporarily in your Paint sheet.
Then drag the 2nd item to position it where you need it in the Paint Sheet.
Save the paint sheet file and you are done!