I have created a vb.net application that batch processes PDF’s and prints them. I have run into an issue where the image on the PDF is greater than the size of the page. If the image is brought up in the PDF viewer the image size is 31.1%. When it is printed it retains that size. The fit to page setting is set on the PDF image viewer.
If anyone could point me in the direction to programmatically enable the fit to page capabilities it would be extremely appreciatated.
Thanks.
Dim Process As New Process()
Dim pathToExecutable As String = "AcroRd32.exe"
Dim sReport = strFile
Dim starter As New ProcessStartInfo(pathToExecutable, "/t """ + sReport + """ """ + Me.txtPrinter.Text + """")
Process.StartInfo.FileName = sReport
Process.StartInfo.Verb = "Print"
Process.StartInfo.CreateNoWindow = True
Process.Start()
Process.WaitForExit(10000)
Process.CloseMainWindow()
Process.Close()
Process.Dispose()
Process = Nothing
starter = Nothing
Andra ChaharPosted Mar 8, 2019, 3:33 AM
pdf.LoadFromFile("D:\\test.pdf");
PdfPageBase page = pdf.Pages[0];
//extract the image
Image image = page.ExtractImages()[0];
//resize
float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Math.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;
Bitmap m_objBitmap = new Bitmap((int)fitWidth, (int)fitHeight);
Graphics g = Graphics.FromImage(m_objBitmap);
g.DrawImage(image, 0, 0, fitWidth, fitHeight);
PdfImage newImage = PdfImage.FromImage(m_objBitmap);
page.ReplaceImage(0, newImage);
pdf.SaveToFile("D:\\result.pdf");
EjackalPosted Mar 5, 2019, 10:37 PM
Brian DaulPosted Dec 9, 2008, 11:39 AM
Dim Process As New Process()
Dim pathToExecutable As String = "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
Dim sReport = "C:\Temp\TheDocument.pdf"
Dim TheDefaultPrinter = "MyPrinter"
Process.StartInfo.UseShellExecute = False
Process.StartInfo.FileName = pathToExecutable
Process.StartInfo.Arguments = "/t """ + sReport + """ """ + TheDefaultPrinter + """"
Process.StartInfo.Verb = "Print"
Process.StartInfo.CreateNoWindow = True
Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
Process.Start()
Process.Close()
Process.WaitForExit(10000)
Process.CloseMainWindow()
Process.Dispose()
Process = Nothing
The Adobe Reader has a setting in it that allows you to "Fit To Page" under View\Zoom\Fit to Page. Once you select that value and File\Close the Adobe Reader the settings are set in your computer registry.
A Process() instance was started against Adobe Reader with arguments. The arguments included the file name and the printer that it was suppose to use.
This code launched Adobe Reader and used the values that are set in the registry. That way everything fits to the page and it prints with those dimensions.
The drawback is that Adobe Reader is displayed briefly on the screen with the PDF displayed in. It will close after it is done processing.