none
PrintForm & Microsoft XPS Document Writer Filename

    Question

  •   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    
        Dim PDFFileName, PDFTest As String
        Dim PDFNameLength, SlashLocator As Integer
    
        PDFNameLength = Len(Form3.OpenFileDialog1.FileName)
    
        PDFTest = Form3.OpenFileDialog1.FileName
    
        SlashLocator = InStr(PDFTest, "\")
    
        Do Until SlashLocator = 0
    
          SlashLocator = InStr(PDFTest, "\")
    
          PDFTest = Microsoft.VisualBasic.Right(PDFTest, PDFNameLength - SlashLocator)
    
          PDFNameLength = Len(PDFTest)
    
        Loop
    
        PDFFileName = Microsoft.VisualBasic.Left(PDFTest, PDFNameLength - 4)
    
        PrintForm1.DocumentName = PDFFileName + ".xps"
    
    
    
        With Me.PrintForm1
    
          .PrinterSettings.PrinterName = "Microsoft XPS Document Writer"
    
          Dim MyMargins As New Margins
    
          With MyMargins
            .Left = 50
            .Right = 0
            .Top = 40
            .Bottom = 0
          End With
    
          .PrinterSettings.DefaultPageSettings.Margins = MyMargins
    
          Try
            .Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
          Catch ex As Exception
            MessageBox.Show("Adobe Printer NOT Installed," & vbCrLf & "cannot create pdf!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            .PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters(1)
          End Try
    
        End With
    
      End Sub
    

    Is there a way to supply a file name to the XPS printer? I've used the attached code with success when the printer name is Adobe PDF so I thought all I'd have to do is change it to Microsoft XPS Document Writer and off I'd go. How wrong was I? VERY. The file is created after I supply a file name in the "Save As" dialog box that now pops up. With the Adobe PDF Printer the file was created without user interaction using the PDFFileName variable. I'm doing something wrong, can anyone help? FYI I left the variable names as PDF since they are juat a name, I would change them to XPS if I could get this to work with a file name.

    Thanks, rmcabc


    RMCABC
    Tuesday, March 15, 2011 11:21 AM

Answers

  • Thank you for your response, but I'm afraid I  led you down the garden path. I should have taken any reference to pdf out of my code as I am not making a pdf document at all so there is nothing to convert. I'm going straight to an xps file. From all of the reasearch I did yesterday I've discovered that the xps driver won't accept a variable to set the file name, human interface is always required; that is why the 'save as' dialog box always pops up. My apologies for the confusion.

    rmcabc


    RMCABC
    • Marked as answer by RMCABC Sunday, March 20, 2011 3:39 PM
    Wednesday, March 16, 2011 11:23 AM

All replies

  •  

    Hi There,

    Please see solution here...

    http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/52f7b1ec-9db1-4550-af47-3fd1de9b94c9

    Thanks,


    Mubi | www.mrmubi.com | Mark The Best Replies As Answers!
    Wednesday, March 16, 2011 7:37 AM
  • Thank you for your response, but I'm afraid I  led you down the garden path. I should have taken any reference to pdf out of my code as I am not making a pdf document at all so there is nothing to convert. I'm going straight to an xps file. From all of the reasearch I did yesterday I've discovered that the xps driver won't accept a variable to set the file name, human interface is always required; that is why the 'save as' dialog box always pops up. My apologies for the confusion.

    rmcabc


    RMCABC
    • Marked as answer by RMCABC Sunday, March 20, 2011 3:39 PM
    Wednesday, March 16, 2011 11:23 AM
  • Moderator: I have marked this as answered but I'd recommend that you delete this thread. I've found that there is no way to set via variable in the XPS printer driver. This is documented in several threads, moreover; the print quality of the xps document is terrible. I have since found doPDF which is free. It will create a .pdf document that is in the Adobe format. Thanks, rmcabc
    RMCABC
    Sunday, March 20, 2011 3:44 PM