I just got the compare word in command line solution.
And try to compare two word file by TortoiseSVN diff scripts (diff-doc.js), but I found it shows to many differences about font or paragraph settings.
Is there any code sample about how to modify the diff-doc.js to ignore font change and ignore paragraph format change? I just want to focus on the text content at first time.
Im not 100% sure what you are asking, but you can do something like this in vbscript:
strPath1 = [the location of the first file]
strPath2 = [the location of the second file]
strLog = [the location of a log file]
set ofs = CreateObject("Scripting.FileSystemObject")
'create a log file
If Not oFs.FileExists(strLog) Then
set logFile = oFs.CreateTextFile(strLog, true)
else
set logFile = oFs.openTextFile (strLog, 8, True)
End if
set file1 = ofs.openTextFile (strPath1)
strFile1Buffer = file1.readAll
file1.close
set file2 = ofs.openTextFile (strPath2)
do while not file2.atEndOfStream
strLine = file2.readLine
If InStr(strFile1Buffer, strLine) = 0 Then
strLogEntry = strLogEntry & strLine & vbCrLf
End If
Loop
file2.Close
strLogEntry = "Lines that are in file1 but not in file2:" & vbCrLf & strLogEntry
logFile.WriteLine strLogEntry
objFile3.Close
Check out this: http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/24/how-can-i-compare-the-contents-of-two-text-files.aspx
Related
I am trying to parse the xref stream from PDF in JavaScript. I managed to succesfully isolate the stream itself (I checked that it's ok by comparing it in debugging mode with the value between steram. and endstream tags in PDF.
However, when I try to inflate it using pako lib, I get an error saying: ERROR incorrect header check.
The compression method is FlateDecode, which can be seen from the dictionary.
Here is the code in question:
const dict = pdfStr.slice(pdf.startXRef);
const xrefStreamStart = this.getSubstringIndex(dict, 'stream', 1) + 'stream'.length + 2;
const xrefStreamEnd = this.getSubstringIndex(dict, 'endstream', 1) + 1;
const xrefStream = dict.slice(xrefStreamStart, xrefStreamEnd);
const inflatedXrefStream = pako.inflate(this.str2ab(xrefStream), { to: 'string' });
pdfStr is the whole PDF read as a string, while *pdf.startXRef* holds the value of the position of the xref stream object.
Here's the whole PDF if someone wants to have a look: https://easyupload.io/lzf9he
EDIT: As mcernak has suggested I had a problem that I included /r and /n in the stream. However, now that I corrected the code I got a different error: invalid distance too far back
The stream content is located between stream\r\n and \r\nendstream.
You need to take into account those two additional characters (\r\n) at the beginning and at the end to read the correct data:
const dict = pdfStr.slice(pdf.startXRef);
const xrefStreamStart = this.getSubstringIndex(dict, 'stream', 1) + 'stream'.length + 2;
const xrefStreamEnd = this.getSubstringIndex(dict, 'endstream', 1) - 2;
const xrefStream = dict.slice(xrefStreamStart, xrefStreamEnd);
const inflatedXrefStream = pako.inflate(this.str2ab(xrefStream), { to: 'string' });
I have a string - project description ( as part of an object ) coming from a user form submission that is shown on a page of a report. If the line numbers exceed 24 I want to show the rest of the string on a new page. My initial idea was to cut it based on characters but this can't be done precisely as if line breaks are made when submitting the form, the characters can't be calculated as we donĀ“t know if the line break was made in the middle of a line or the end or wherever. I don't know what could be the solution?
How can I cut a string based on number of lines?
This is what I have done so far:
function countLines (el) {
let projectDetails = $rootScope.report.description;
var el = document.getElementById(el);
var divHeight = el.offsetHeight
var lines = divHeight / 17;
//console.log("Lines counted: " + lines);
if(lines > 24) {
$scope.secondDescriptionPage = true;
$scope.projectDetailsTextFirstPart = // this should be calculated
//$scope.projectDetailsTextSecondPart = // this should be calculated )
}
}
With the -webkit-line-clamp CSS property you can cut text by a certain number of lines. See MDN for details. It will not work in IE11 however.
I am designing a vba code that allows users to input a set of technical drawing numbers and create a packet from it. I have run into a problem when dealing with autocad files. Because our company has AutoCAD LT I am unable to utilize the api, thus I am using adobe's PDFMaker api to convert the files directly to pdf. Unfortunately the settings for pdfMaker are rather limited so I need to parse through the outputted pdf packet and print it in black and white (monochrome). I currently have a subroutine that opens the packet and prints the necessary pages, however, it only prints black and white if I specifically open up acrobat and select my "Monochrome" configuration in the advanced settings. Is there a way to send the command (I believe it's in javascript?) to set this color configuration and set the size option to fit? Here is my code.
Public xlBook As Workbook
Public xlSheet As Worksheet
Public LastRow As Integer
Public ItemNumber As String
Public Vin5 As String
Public Vin As String
Public FullPath As String
Sub PdfFormat()
Dim strMakeFile As String
Dim LastRow As Integer
Set xlBook = ActiveWorkbook
Set xlSheet = xlBook.Sheets(1)
ItemNumber = Range("E1")
Vin5 = Range("F1")
Vin = ItemNumber & "0" & Vin5
FullPath = "\\eastfile\Departments\Engineering\MACROS\New Packet Output\" & Vin & "\"
strMakeFile = FullPath & Vin & ".pdf"
LastRow = Range("A" & xlSheet.Rows.Count).End(-4162).Row
Dim AcroExchApp As New Acrobat.AcroApp
Dim AcroExchAVDoc As New Acrobat.AcroAVDoc
Dim AcroExchPDDoc As Acrobat.AcroPDDoc
Dim OpenError As Boolean
Dim PrintError As Boolean
OpenError = AcroExchAVDoc.Open(strMakeFile, "")
!!!!!CODE FOR PRINTER SETTINGS HERE!!!!!
PrintError = AcroExchAVDoc.PrintPagesSilentEx(0, 5, 3, 1, 1, 0, 0, 0, -5)
Debug.Print "Open Error: " & Not (OpenError)
Debug.Print "Print Error: " & Not (PrintError)
Debug.Print Vin
AcroExchApp.CloseAllDocs
End Sub
Thank you for your time
The print parameters in Acrobat you can find in the Acro-js helpfile for example here: Acro JS setting print options
With VBS/VBA there are 2 ways to use it. With the help of Acro-Form API you can execute js-code more or less direkt. Here I gave a simple example: Execute Acro js from VBA/VBS
The other way is to use the JS-Object, which lets you use transformed js-code via VBA/VBS Ole connection. That's documented in the Adobe Acrobat IAC Reference.
How that works you can see in the following example, where I use jso for setting some print parameters. Change the given print parameters to that what you need or search in the Acro JS helfile for some other example and execute it via above described way direct. Good luck, Reinhard
'// print dropped files with printParameter
set WshShell = CreateObject ("Wscript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
if objArgs.Count < 1 then
msgbox("Please drag a file on the script")
WScript.quit
end if
'contact Acrobat
Set gApp = CreateObject("AcroExch.App")
gApp.show 'comment or take out to work in hidden mode
'open via Avdoc and print
for i=0 to objArgs.Count - 1
FileIn = ObjArgs(i)
Set AVDoc = CreateObject("AcroExch.AVDoc")
If AVDoc.Open(FileIn, "") Then
Set PDDoc = AVDoc.GetPDDoc()
Set JSO = PDDoc.GetJSObject
jso.print false, 0, 0, true
set pp = jso.getPrintParams
pp.printerName = "hp deskjet 990c"
pp.firstPage = 0 '-> Zero based (firstPage = 0)
pp.lastPage = 5 '-> Zero based (pageCount - 1)
pp.interactive = pp.constants.interactionLevel.automatic '-> no print dialog
pp.pageHandling = pp.constants.handling.booklet
pp.booklet.duplexMode = pp.constants.bookletDuplexModes.BothSides
pp.booklet.binding = pp.constants.bookletBindings.LeftTall
jso.print(pp)
gApp.CloseAllDocs
end if
next
gApp.hide
gApp.exit
MsgBox "Done!"
Quit()
Sub Quit()
Set JSO = Nothing
Set PDDoc = Nothing
Set gApp = Nothing
Wscript.quit
End Sub
I have a piece of code that loads a website and clicks a link that opens a popup. The contents of this popup is what I need to be imported into Excel (VBA) so I can manipulate that data. The issue is that this link's web address always changes, but the link is always in the same place.
The following code defines the currently active IE instance's URL as "IEURL". I would like to use the code to import the table but I get an error "Run-time error '1004': The address of this site is not valid. Check the address and try again".
Sub Button1_Click()
Dim objIE As SHDocVw.InternetExplorer
Dim IEURL As String
LastRow = Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Set objIE = New InternetExplorerMedium
'apiShowWindow objIE.hwnd, SW_MAXIMIZE
objIE.navigate "http://www.youtube.com"
objIE.Visible = True
Do While objIE.READYSTATE <> 4 And objIE.Busy
DoEvents
Loop
'Call Sleep
Application.Wait (Now + TimeValue("0:00:5"))
IEURL = objIE.LocationURL
ThisWorkbook.Sheets("Sheet1").Activate
Rows("6:250").Delete
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;IEURL", _
Destination:=Range("a6"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Can anyone help me out here?
P.S. I just used YouTube as an example here, as it demonstrates the same problem as the actual website I am trying to import
The objIE.LocationURL property returns a string which you are storing in a string variable. When you later try to use that variable you should append it to a string rather than just putting the name of the variable inside the string. So change
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;IEURL", _
to
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & IEURL, _
btw, in Excel 2013, your sample code fails at IEURL = objIE.LocationURL
I have tried to do this for hours on end with searching the web for answers but none of them produce the results I need.
Currently, I open a .txt file, read the contents and console.log() them in the cmd window. I need to figure out how to output these modified contents onto an html page on the local host.
I create a server at a local host address (127.0.0.1:xxxx) and create a web page where you have hyper text links. I user serverStaticFile() to give it the html file of that page will display they modified version of the .txt file.
I have tried saving the modified version of the .txt file into another .txt file that will be accessed by the html page but only the last line of the original .txt file is saved.
I use lineReader.eachline() because I have to take some parts of the line and put it into another string and then output those strings as the finished product of that line.
lineReader.eachLine( // For every line in the song
'original.txt',
function(line, last) {
var string1 = "";
var string2 = "";
var string3 = "";
var string4 = "";
var stringLine = line;
var skipSpaces = 0;
for (var i=0; i<stringLine.length; i++){ // For every character in the line
if (stringLine[i] == "["){
// If the character is a '[', scan the line until ']' is found.
// Everything in between is for string1
var c = "";
var x = i+1;
var chordString = "";
while (c !== "]") {
chordString += stringLine[x];
x++;
c = stringLine[x];
}
string1 += chordString;
skipSpaces = chordString.length;
i = x;
} else {
// If the character isn't a bracket, add that character to the string2
if (skipSpaces > 0){
// Pad the top line with spaces, unless they should be skipped due to a chord having been added.
skipSpaces--;
} else {
string1 += " ";
}
string2 += stringLine[i];
}
}
console.log(string1);
console.log(string2);
string3 = string1+string2;
string4 += string3;
fs.writeFile("chordpro.txt", string4, function(err) {
if(err) {
console.log(err);
} else {
console.log("");
}
});
if (last) {
return false; // stop reading
}
});
string1 and string2 are the modified contents of the current line being read in the loop.
I save the modified line into one whole string, string3, and try to put all of that into another string that doesn't overwrite the previous modified lines. The problem with this is that it only saves the last line of the original .txt file in the modified.txt file.
I wanted to upload this modified.txt file into the html page which I have not figured out how to do.
Can someone please give me some guidance?
The reason your "chordpro.txt" file only has the last line of the file that's being read from is because for each line in the input file you are writing that line to the output file when you are finished. When you use writeFile() it will overwrite whatever is currently in the file. What you want to do is use appendFile() instead.
fs.appendfile("chordpro.txt", string4, function(err) {
//..
}