I have generated a PDF Document which contains a single line of text, printed to a file and sent it to the printer. On the other hand I have generated the same PDF document and have printed it programmatically. Both print-outs are different. The text appears as a single line on the print-out taken from the file. But the print out produced programmatically wraps the text and has the same text in two lines. How can we get the same layout in both methods.
I can send you both print-outs if you need.
Thank you
John.
Difference between Print-outs
Re: Difference between Print-outs
Support · May 10, 2007Hello John,
Can you please send over the saved PDF documents, the code you are using to generate the PDF and the output printouts to our [^a|mailto:support@cete.com|Support Team^] so that they can take a look at these and try to find out the reason for this behavior to occur.
Thanks,
ceTe Software Support Team.
Re: Difference between Print-outs
Forum member · May 11, 2007Hi, the sample VB.Net 2005 code I have written is as follows
Thanks,
John
Imports System
Imports System.Drawing.Printing
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Public Class Form1
Private _printDoc As PrintDocument
Private _pdfDoc As Document
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Document.AddLicense("GEN40NED......")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a PDF Document
_pdfDoc = New Document
' Create a page dimensions object and set the margins
Dim dimensions As PageDimensions = New PageDimensions(PageSize.Letter, PageOrientation.Portrait)
dimensions.BottomMargin = 100
dimensions.TopMargin = 100
dimensions.LeftMargin = 100
dimensions.RightMargin = 100
' Create a page using a page dimensions object and add it to the document
Dim MyPage As Page = New Page(dimensions)
_pdfDoc.Pages.Add(MyPage)
MyPage.Elements.Add(New Rectangle(0, 0, 200, 200))
' Add a label to the page
MyPage.Elements.Add(New Label("Review and provide comments on draft B (stylized) (Class 42) application, direction to legal assistant with respect to issues relating to same.", _
0, 0, 500, 20, New ceTe.DynamicPDF.Text.TrueTypeFont("arial.ttf"), 18))
' Save the PDF
_pdfDoc.Draw(System.IO.Path.Combine(Application.StartupPath, "MyDocument.pdf"))
_printDoc = New PrintDocument()
AddHandler _printDoc.PrintPage, AddressOf OnPrintPage
_printDoc.PrintController = New StandardPrintController()
_printDoc.PrinterSettings.PrinterName = "\\printserver\Nextgen"
' look for highest resolution
For Each pr As PrinterResolution In _printDoc.PrinterSettings.PrinterResolutions
If pr.Kind = PrinterResolutionKind.High Then
_printDoc.DefaultPageSettings.PrinterResolution = pr
Exit For
End If
Next
_printDoc.Print()
End Sub
Public Shared Function DisplayToPoints(ByVal dp As Single) As Single
If dp <= 0.0F Then
Return 0.0F
End If
Return 72 * dp / 100
End Function
Protected Sub OnPrintPage(ByVal sender As Object, ByVal args As PrintPageEventArgs)
Dim grph As Drawing.Graphics = args.Graphics
grph.PageUnit = Drawing.GraphicsUnit.Point
grph.PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.Default
grph.SmoothingMode = Drawing.Drawing2D.SmoothingMode.Default
' get the current page
Dim pg As Page = _pdfDoc.Pages(0)
' adjust margins
Dim leftBound As Single = DisplayToPoints(args.PageSettings.PrintableArea.Left)
Dim topBound As Single = DisplayToPoints(args.PageSettings.PrintableArea.Top)
Dim rightBound As Single = DisplayToPoints(args.PageSettings.PaperSize.Width - args.PageSettings.PrintableArea.Right)
Dim bottomBound As Single = DisplayToPoints(args.PageSettings.PaperSize.Height - args.PageSettings.PrintableArea.Bottom)
'grph.TranslateTransform(pg.Dimensions.LeftMargin - leftBound, pg.Dimensions.TopMargin - topBound)
grph.TranslateTransform(pg.Dimensions.LeftMargin, pg.Dimensions.TopMargin)
'Dim pageW As Single = DisplayToPoints(args.PageSettings.PrintableArea.Width)
'Dim pageH As Single = DisplayToPoints(args.PageSettings.PrintableArea.Height)
'grph.ScaleTransform((pg.Dimensions.Width - (pg.Dimensions.LeftMargin - leftBound) - (pg.Dimensions.RightMargin - rightBound)) / pageW, _
' (pg.Dimensions.Height - (pg.Dimensions.TopMargin - topBound) - (pg.Dimensions.BottomMargin - bottomBound)) / pageH)
' draw it
For Each elem As Object In pg.Elements
If TypeOf elem Is Rectangle Then
With CType(elem, Rectangle)
grph.DrawRectangle(Pens.Black, .X, .Y, .Width, .Height)
End With
ElseIf TypeOf elem Is Label Then
With CType(elem, Label)
grph.DrawString(.Text, New Drawing.Font(.Font.Name, .FontSize, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point), _
Brushes.Black, New Drawing.RectangleF(.X, .Y, .Width, .Height))
End With
End If
Next
End Sub
End Class
Re: Difference between Print-outs
Support · May 11, 2007Hello John,
There is nothing within our product that controls the printing of the PDF document. It depends on the printer settings.
Couple of things that could cause the difference in two print outs are:
1. It could be because of the differences in units. Maybe the calculations you are doing in the OnPrintPage handler are not quite right?
Also it is possible that you may not be translating the .FontSize? Do you see the text larger in the case when the document is printed with text wrapping on two lines?
Thanks,
ceTe Software Support Team