Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.prefs
*.cset
*.launch
3 changes: 3 additions & 0 deletions IRP/src/CommonModules/Localization/Module.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,9 @@ Strings.Insert("ExternalAccountingOperationExchangeReport", NStr("en = 'External
Strings.Insert("Error_UnknownRefType", NStr("en = 'Unknown ref type: %1'", Lang));
Strings.Insert("Error_StepsEnablerNotDefined", NStr("en = 'Steps enabler is not defined [%1]'", Lang));
Strings.Insert("Error_UnsupportedExternalLinkSC3", NStr("en = 'Not supported External link for [SC] to [%1]'", Lang));
Strings.Insert("Error_CreatingPDF", NStr("en = 'Error creating PDF'", Lang));
Strings.Insert("Error_ReadingPDF", NStr("en = 'Error reading PDF'", Lang));
Strings.Insert("Error_ChromiumNotFound", NStr("en = 'Chromium not found'", Lang));
#EndRegion

#Region Tasks
Expand Down
138 changes: 138 additions & 0 deletions IRP/src/CommonModules/PDFFunctionsClientServer/Module.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@

// Is PDF.
//
// Parameters:
// FileRef - CatalogRef.Files - File ref
//
// Returns:
// Boolean - Is PDF
Function IsPDF(FileRef) Export

Extension = CommonFunctionsServer.GetRefAttribute(FileRef, "Extension"); // String
Return Not StrCompare(Extension, "pdf");

EndFunction

// Set data in PDFViewer.
//
// Parameters:
// PDFViewer - PDFDocument - PDFViewer
// Data - BinaryData - Data
// IsAsync - Boolean - Is async
Procedure SetDataInPDFViewer(PDFViewer, Data, IsAsync = False) Export

Try
Buffer = GetBinaryDataBufferFromBinaryData(Data);
Stream = New MemoryStream(Buffer);
If IsAsync Then
PDFViewer.ReadAsync(Stream);
Else
PDFViewer.Read(Stream);
EndIf;
Except
Raise R().Error_ReadingPDF + Chars.CR + ErrorDescription();
EndTry;

EndProcedure

// Read data from PDFViewer.
//
// Parameters:
// PDFViewer - PDFDocument - PDFViewer
/// IsAsync - Boolean - Is async
//
// Returns:
// Undefined, BinaryData - Read data from PDFViewer
Function ReadDataFromPDFViewer(PDFViewer, IsAsync = False) Export

Try
If PDFViewer.PageCount() = 0 Then
Return Undefined;
EndIf;

MemoryStream = New MemoryStream();

If IsAsync Then
PDFViewer.WriteAsync(MemoryStream);
Else
PDFViewer.Write(MemoryStream);
EndIf;

Data = MemoryStream.CloseAndGetBinaryData();
Except
// document not set
Return Undefined;
EndTry;

Return Data;

EndFunction

// Create PDF from HTML.
//
// Parameters:
// HTML - String - HTML
//
// Returns:
// Structure - Create PDFFrom HTML:
// * BinaryData - BinaryData, Undefined - PDF from HTML
// * Error - String - error text
Function CreatePDFFromHTML(HTML) Export

Result = New Structure("BinaryData, Error", Undefined, "");

PathToChromium = GetPathToChromium();
If IsBlankString(PathToChromium) Then
Result.Error = R().Error_ChromiumNotFound;
Return Result;
EndIf;

PDFtmp = GetTempFileName(".pdf");
HTMLtmp = GetTempFileName(".html");

TextFile = New TextWriter(HTMLtmp);
TextFile.Write(HTML);
TextFile.Close();

PathToChromium = """" + PathToChromium + """";
Args = " --headless --disable-gpu --run-all-compositor-stages-before-draw --no-sandbox --print-to-pdf=" + PDFtmp + " " + HTMLtmp;

Try
RunApp(PathToChromium + Args, , True);
Result.BinaryData = New BinaryData(PDFtmp);
Except
Result.Error = R().Error_CreatingPDF + Chars.LF + ErrorProcessing.DetailErrorDescription(ErrorInfo());
EndTry;

DeleteFiles(HTMLtmp);
DeleteFiles(PDFtmp);

Return Result;

EndFunction

// Get path to chromium.
//
// Returns:
// String - Get path to chromium
Function GetPathToChromium()
// On the server side, the path can be set as Constant,
// but on the client side, the paths may differ.
// Let's try to find it by enumeration.

PossiblePaths = New Array; // Array of String
PossiblePaths.Add("C:\Program Files\Google\Chrome\Application\chrome.exe");
PossiblePaths.Add("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
PossiblePaths.Add("C:\Program Files\Chromium\Application\chrome.exe");
PossiblePaths.Add("C:\Program Files (x86)\Chromium\Application\chrome.exe");
PossiblePaths.Add("C:\Chromium\Application\chrome.exe");

For Each Path In PossiblePaths Do
PathFile = New File(Path);
If PathFile.Exists() Then
Return Path;
EndIf;
EndDo;

Return "";
EndFunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="94100865-4629-4766-a4b1-bf122434924f">
<name>PDFFunctionsClientServer</name>
<synonym>
<key>en</key>
<value>PDF functions client server</value>
</synonym>
<clientManagedApplication>true</clientManagedApplication>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>
4 changes: 1 addition & 3 deletions IRP/src/CommonModules/PictureViewerClient/Module.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ Procedure SetPDFForView(FileRef, PDFViewer) Export
URI = GetPictureURL(PictureParameters); //String
BD = GetFromTempStorage(URI); // BinaryData
If Not BD = Undefined Then
BDB = GetBinaryDataBufferFromBinaryData(BD);
MemoryStream = New MemoryStream(BDB);
PDFViewer.ReadAsync(MemoryStream);
PDFFunctionsClientServer.SetDataInPDFViewer(PDFViewer, BD, True);
Else
CommonFunctionsClientServer.ShowUsersMessage(R().InfoMessage_040);
EndIf;
Expand Down
1 change: 1 addition & 0 deletions IRP/src/Configuration/Configuration.mdo
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@
<commonModules>CommonModule.DocIncomingExchRateAdjustmentInvoiceServer</commonModules>
<commonModules>CommonModule.DocOutgoingExchRateAdjustmentInvoiceClient</commonModules>
<commonModules>CommonModule.DocOutgoingExchRateAdjustmentInvoiceServer</commonModules>
<commonModules>CommonModule.PDFFunctionsClientServer</commonModules>
<commonAttributes>CommonAttribute.Author</commonAttributes>
<commonAttributes>CommonAttribute.Branch</commonAttributes>
<commonAttributes>CommonAttribute.Comment</commonAttributes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,14 +1013,6 @@ Procedure WriteOtherAttachmentInput(Structure)

EndProcedure

&AtClient
Function IsPDF(FileRef)

Extension = CommonFunctionsServer.GetRefAttribute(FileRef, "Extension"); // String
Return Not StrCompare(Extension, "pdf");

EndFunction

&AtClient
Procedure CurrentFilesTableSelection(Item, SelectedRow, Field, StandardProcessing)

Expand All @@ -1030,7 +1022,7 @@ Procedure CurrentFilesTableSelection(Item, SelectedRow, Field, StandardProcessin
Structure.Insert("FileRef", FileRef);
Structure.Insert("Title", StrTemplate("%1", FileRef));
Structure.Insert("Description", "");
Structure.Insert("IsPdf", IsPDF(FileRef));
Structure.Insert("IsPdf", PDFFunctionsClientServer.IsPDF(FileRef));
OpenForm("DataProcessor.AttachedFilesToDocumentsControl.Form.PictureViewer", Structure, , , , , ,FormWindowOpeningMode.LockOwnerWindow);

EndProcedure
Expand Down