From 91fe299483383b7531950c5f1b109dd63bc382ea Mon Sep 17 00:00:00 2001 From: "d.breimaier" Date: Tue, 26 Sep 2023 13:13:22 +0200 Subject: [PATCH] getPDFfromURLStream --- .../DATENSERVER/cDATENSERVER.vb | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb b/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb index 72af02c1..81536dcb 100644 --- a/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb +++ b/VERAG_PROG_ALLGEMEIN/DATENSERVER/cDATENSERVER.vb @@ -7,6 +7,11 @@ Imports System.Runtime.InteropServices Imports System.Windows.Forms Imports System.Drawing Imports Spire.Pdf.Print +Imports Spire.Pdf +Imports Spire.Pdf.HtmlConverter +Imports System.Threading +Imports System.Net +Imports Spire.Pdf.Tables Public Class cDATENSERVER @@ -1332,12 +1337,15 @@ Public Class cFormularManager - Public Shared Function getPDFViaSpirePDF_FromURL(URL As String, Optional targetPath As String = "", Optional openFileAfterDownload As Boolean = False) As String + Public Shared Function getPDFViaSpirePDF_FromURL(URL As String, Optional targetPath As String = "") As String Try If targetPath = "" Then targetPath = getTMPPath_PDF() VERAG_PROG_ALLGEMEIN.cProgramFunctions.spireLoadLicense() Dim doc As New Spire.Pdf.PdfDocument '= New Spire.Pdf.PdfDocument(URL) + + + doc.LoadFromHTML(URL, True, True, True) If doc IsNot Nothing Then doc.PageSettings.Size = Spire.Pdf.PdfPageSize.A4 @@ -1348,28 +1356,9 @@ Public Class cFormularManager doc.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.FitSize, True) ' doc.PrinterName = printerName ' doc.PrintDocument.Print() - doc.SaveToFile(targetPath) + End If - 'For Each doc As Spire.Pdf.PdfDocument In docs - 'Dim doc As New Spire.Pdf.PdfDocument() - - 'Using webClient As New Net.WebClient() - ' Dim data() As Byte = webClient.DownloadData(URL) - ' Using stream As New MemoryStream(data) - ' Dim doc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument(stream) - ' If doc IsNot Nothing Then - ' doc.PageSettings.Size = Spire.Pdf.PdfPageSize.A4 - ' doc.PrintDocument.DefaultPageSettings.Landscape = True - ' doc.PageScaling = Spire.Pdf.PdfPrintPageScaling.FitSize - ' ' doc.PrinterName = printerName - ' ' doc.PrintDocument.Print() - ' doc.SaveToFile(targetPath) - ' End If - ' End Using - 'End Using - - ' doc.LoadFromHTML(pdfPath, True, True, True) Return targetPath @@ -1380,6 +1369,33 @@ Public Class cFormularManager End Function + + Public Shared Function getPDFViaSpirePDF_FromURLStream(URL As String, Optional targetPath As String = "", Optional openFileAfterDownload As Boolean = True) As String + Try + If targetPath = "" Then targetPath = getTMPPath_PDF() + + VERAG_PROG_ALLGEMEIN.cProgramFunctions.spireLoadLicense() + + Using webClient As New Net.WebClient() + Dim data() As Byte = webClient.DownloadData(URL) + Using stream As New MemoryStream(data) + Dim doc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument(stream) + If doc IsNot Nothing Then + doc.PageSettings.Size = Spire.Pdf.PdfPageSize.A4 + doc.SaveToFile(targetPath) + If openFileAfterDownload Then + + End If + End If + End Using + End Using + + Return targetPath + Catch ex As Exception + MsgBox(ex.Message & ex.StackTrace) + End Try + Return "" + End Function Public Shared Sub PrintViaGS(PDFFile As String, printerName As String) Try Dim assembly = System.Reflection.Assembly.GetExecutingAssembly()