Free Support Forum - aspose.com

Document.Print

Im finding that the Print method is taking an absolute age to complete.

Im creating a sample document (<100Kb) and then running the following line of code

Dim doc as Document=getMySampleDoc()
Dim settings as New System.Drawing.Printing.PrinterSettings()

settings.PrinterName="\MyServer\MyPrinter"

doc.Print(settings,“MyAsposeDoc”)


The doc does eventually appear on the print queue but anything up to an hour later!

If I change the printer to a local printer then it appears on the queue immediately

If I send a document to printer from notepad or word directly, the doc appears on print queue immediately

Any help appreciated



Hi,


Thanks for your inquiry. It would be great if you please share following information for investigation purposes.

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • Please supply us with the input document that is causing the issue
  • Are you facing this issue will all document or only with specific document?

As soon as you get these pieces of information to us we’ll start our investigation into your issue.
This is happening to all documents. Code for sample is provided below.
In th staging server environment, the document never gets to the print queue. From the logging I have added to app, I can see that execution does not move beyond the Doc.Print line...

In the dev environment, the doc does get to the print queue after a 5/10 min delay


Dev Machine
Win 7 Enterprise SP1
64 Bit

Staging Server
Win 2008 Server R2 Datacenter
64-bit

Code

Sub PrintSampleDoc(PrinterName As String)

Dim doc As Document = GetSampleDoc()

Dim settings As New System.Drawing.Printing.PrinterSettings

settings.PrinterName = PrinterName

doc.Print(settings, "CustomDocName")

End Sub

Private Function GetSampleDoc() As Document

Dim l As License = New License()

l.SetLicense("\\MyLicenseLocation\Aspose.Words.lic")

Dim doc As New Document()

'Once the builder is created, its cursor is positioned at the beginning of the document.

Dim builder As New DocumentBuilder(doc)

'Specify font formatting before adding text.

builder.Font.Size = 16

builder.Font.Bold = True

builder.Font.Color = System.Drawing.Color.Blue

builder.Font.Name = "Arial"

builder.Underline = Underline.Dash

builder.Write("This text")

builder.Underline = Underline.None

builder.Write(" is inserted at the beginning of the document and demonstrates ")

'Set shading and border around a run of text, then clear the border.

builder.Font.Shading.ForegroundPatternColor = System.Drawing.Color.Cyan

builder.Font.Shading.Texture = TextureIndex.TextureSolid

builder.Write("various font")

builder.Font.Shading.ClearFormatting()

builder.Font.Border.LineStyle = LineStyle.Single

builder.Write(" formatting ")

builder.Font.Border.ClearFormatting()

builder.Writeln("options.")

builder.InsertParagraph()

'Specify paragraph formatting before calling InsertParagraph or Writeln.

builder.ParagraphFormat.Borders.LineStyle = LineStyle.Single

builder.ParagraphFormat.Borders.LineWidth = 1.5

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center

builder.ParagraphFormat.Shading.ForegroundPatternColor = System.Drawing.Color.LightBlue

builder.ParagraphFormat.Shading.Texture = TextureIndex.TextureSolid

builder.ParagraphFormat.LeftIndent = ConvertUtil.InchToPoint(0.3)

builder.ParagraphFormat.SpaceBefore = 12

builder.ParagraphFormat.SpaceAfter = 12

builder.Font.Name = "Arial"

builder.Font.Size = 12

builder.Write("This fragment demonstrates use of paragraph formatting to specify ")

builder.Writeln("alignment, spacing, borders and shading.")

builder.ParagraphFormat.ClearFormatting()

'Insert another section and demonstrate page setup properties.

builder.MoveToDocumentEnd()

builder.Font.Size = 12

builder.InsertBreak(BreakType.SectionBreakNewPage)

builder.PageSetup.PaperSize = Aspose.Words.PaperSize.A5

builder.PageSetup.Orientation = Orientation.Landscape

builder.Writeln("This text is in a section with different page size and orientation.")

builder.Writeln("Insert an image into the document here.")

'Move to a position in the header.

builder.MoveToMergeField("MyHeader")

builder.Font.ClearFormatting()

builder.Font.Italic = True

builder.Write("This text is inserted into the header.")

Return doc

End Function

Hi,


Thanks for sharing the detail. Please note that the Aspose.Words Print method uses System.Drawing and standard .NET printing classes.

Please try following code snippet for testing at your end. This code does not use Aspose.Words at all. So if it will not work, the problem is somewhere on your side.

PrintDocument doc = new PrintDocument();<o:p></o:p>

doc.PrinterSettings.PrinterName = @"\192.168.0.2\hp LaserJet 1010 Series Driver";<o:p></o:p>

doc.PrintPage += Doc_PrintPage;<o:p></o:p>

doc.Print();

============================================================================

private void Doc_PrintPage(object sender, PrintPageEventArgs e)<o:p></o:p>

{<o:p></o:p>

e.Graphics.DrawImage(Image.FromFile(@“Common\test.jpg”), e.MarginBounds.Left, e.MarginBounds.Top);<o:p></o:p>

}

This code just prints an image. Please let us know if you have any more queries.


The code below took 8 secs to run

Dim ts As DateTime = Now

Dim doc As PrintDocument = New PrintDocument()

doc.PrinterSettings.PrinterName = txtPrinter.Text

AddHandler doc.PrintPage, AddressOf Doc_PrintPage

doc.Print()

Dim dur As TimeSpan = Now.Subtract(ts)

MsgBox(dur.TotalSeconds) '8 secs

My original code takes 110 secs today

Hi,


Thanks for your feedback. I have tested the scenario (with your code share here) at following environment and have not found the shared issue while using latest version of Aspose.Words for .NET.

Windows 7 (64 bit)
Windows Server 2008 R2 (printer is installed at this machine)

Please test this scenario at some other machines and let us know if you still face problem. I would suggest you please upgrade to the latest version (v13.2.0) from here and let us know how it goes on your side.