#1
|
|||
|
|||
Convert indent to tabs a document converted from PDF
Ho All—
I ran into a problem that I just could find anything that helps. I converted a PDF file to an MS Word file via Adobe Pro. The document contains various different length indents. When I aligned the text to the right, all indents disappeared. The problem: I want to change the various indents on the Word document to spaces or tabs, so that when I align all text, the indented part will remain indented. Is there a way, particularly for a large document, to change all indents to tabs or spaces? Thanks you in advance, EK |
#2
|
|||
|
|||
There is no Automatic way. You could try AutoFormat on a copy of your converted document. First set your AutoFormat options under AutoCorrect Options on the Proofing options. Then Alt+Ctrl+K in the document starts AutoFormat.
Generally I do not work with converted documents. I import the text into a clean Word document as plain text and reformat it using Styles. The conversion processes used by any software I've used, including those by Word, give very messy documents when you try to edit them. In addition, I suspect that some of those Indents are margin changes (section breaks). |
#3
|
||||
|
||||
That is a really bad approach! Inserting spaces and/or tabs to mimic indents makes any document a nightmare to maintain. What's wrong with using separate, indented, paragraphs (based on a properly-defined paragraph Style) where you need them?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Thank you for the input. The reason I want to convert indents to tabs or spaces is that I downloaded a PDF copy (more than 1000 pages) of a book I bought. The book is a computer programming book. I want to convert the PDF to an MS Word because then I can copy the code parts and paste them on my editor so I can run them without having to indent them manually and indenting is important for this language.
Here is an example. The general text, the first 2 lines and the last one, and the indented code in between. I want if possible to select-or any other way- all the code parts and replace indents with tab or spaces. …..only when the file is run as a top-level script, not when it is imported (this new version of the module file is renamed minmax2.py here): print(‘I am:’, name) def minmax(test, *args): res = args[0] for arg in args[1:]: if test(arg, res): res = arg return res We’re also printing the value of nameat the top here to trace its value. Python creates and……. PS..i hope the indents are visible when posted |
#5
|
|||
|
|||
Please note that the on my previous post, the first 2 lines and the last one are not indented but the ones in between are with variable indent length. Thanks. EK
|
#6
|
||||
|
||||
The indents didn't survive (you'd need to enclose the code in the board's Code tags for that - they're on the 'Go Advanced' tab).
That said, I am aware that code indenters are available for a range of platforms, so that may be a better solution than trying to do it from within Word. Conversely, I've written macros before for (IIRC) going the other way, so it shouldn't be too difficult to reverse the process.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
||||
|
||||
Try something along the following lines:
Code:
Sub Demo() Application.ScreenUpdating = True Dim i As Long With Selection For i = 1 To .Paragraphs.Count With .Paragraphs(i).Range.Characters.First Select Case Int(PointsToInches(.Information(wdHorizontalPositionRelativeToTextBoundary)) * 4) Case 1: .InsertBefore vbTab Case 2: .InsertBefore vbTab & vbTab Case 3: .InsertBefore vbTab & vbTab & vbTab Case 4: .InsertBefore vbTab & vbTab & vbTab & vbTab Case 5: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab Case 6: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab Case 7: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab Case 8: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab Case 9: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab End Select End With Next .ParagraphFormat.Alignment = wdAlignParagraphLeft .ClearParagraphAllFormatting End With Application.ScreenUpdating = True End Sub Code:
Sub Demo() Application.ScreenUpdating = True Dim i As Long, j As Long, StrTmp As String With Selection For i = 1 To .Paragraphs.Count StrTmp = vbNullString With .Paragraphs(i).Range.Characters.First For j = 0 To Int(PointsToInches(.Information(wdHorizontalPositionRelativeToTextBoundary)) * 4) StrTmp = StrTmp & vbTab Next .InsertBefore StrTmp End With Next .ParagraphFormat.Alignment = wdAlignParagraphLeft .ClearParagraphAllFormatting End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 02-24-2014 at 09:49 PM. Reason: Alternative macro |
#8
|
|||
|
|||
Quote:
Quote:
If I wanted to copy/paste a code example from a .pdf into an editor I wouldn't use Word (or anything else) as an intermediate program. Might it not save time in the long run to copy/paste each code example as you need it, rather than try to process the whole book all at once? you can always save each code snippet in a reference file outside the code … |
#9
|
||||
|
||||
That's all very well if copying & pasting into an IDE preserves the indents, but few do - they generally rely on spaces/tabs to provide that, not paragraph indents.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Thank Paul and other for the great input and the code for the macros- a great help. Obviously there are other ways that might be even more efficient to accomplish what I had asked for, but for now, this works out well for me; that’s copying code directly from a Word document to IDLE.
I tried the 1st macro and it works very well. After running the macro, all I had to do is to replace tabs with the default number of space in IDEL Thank you all again and best of luck. EK Esawi |
#11
|
||||
|
||||
Quote:
PS: I've inserted '_' characters because the board software deletes repeated spaces.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Thanks again Paul and others. I am finding out how hard and how much work is needed to get the 1500 page book converted to MS Word, and converting it accurately. I thought I can divide it into several parts and once I made the changes in one, I can record a macro and run it for the others. But I am already discouraged and not sure if it’s worth it.
I am about to give up on the converting idea. Instead I will indent manually short code; for longer code I will convert it to Word and run the macro you posted to preserve the indenting and go from there. Thanks again. EK Esawi |
#13
|
|||
|
|||
Quote:
|
#14
|
|||
|
|||
Hi Again,
I hope this question is not out of place here. I have Adobe Acrobat Pro Version 10. Is there a way to change the margins and font for the whole document? I could only change the font size one page at a time and could not find how, if all possible, to change the margins. When I changed the font w/o changing the margins, part of the text is invisible. Thanks again. EK Esawi |
#15
|
||||
|
||||
It's not clear from your post whether you want to make the change in Adobe Acrobat Pro or in Word. In Word, press Ctrl-A selects the entire document, so you can make global changes. It would probably be unwise to change all the indents that way, though.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Convert word document to pdf | Catty | Word VBA | 1 | 12-11-2013 03:57 PM |
Words in my document were converted to numbers???? | MikeD23 | Word | 1 | 08-26-2012 11:09 AM |
Can you see how much time I worked on Word 2007/2010 document when converted to PDF? | Papa Bear | Word | 1 | 08-14-2012 05:14 AM |
My plain text post got converted to rich text in a reply, how to convert it back? | david.karr | Outlook | 0 | 01-05-2012 09:46 AM |
PDF to Word(.doc) document not convert correctly | gonner | Word | 1 | 09-10-2011 03:25 AM |