Free Support Forum - aspose.com

Configuring Margins when printing with PdfViewer

I am having trouble configuring the margins when printing a PDF using PdfViewer. If I leave the margins alone when I create a System.Drawing.Printing.PrinterSetting object the resulting image looks too small. If I set the margins to 0 or if I set the Left and Right margins to the HardMarginX value and the Top and Bottom margins to the HardMarginY value the Bottom and Right sides of the PDF are cropped. If I set the Left and Right margins to twice the HardMarginX value and the Top and Bottom margins to twice the HardMarginY value the image is slightly too small.

We are currently using twice the Hard Margins for printing but our customers feel that the slightly too small image is unacceptable. Is there a better way to set the margins? A code sample follows:

Dim oViewer As New Aspose.Pdf.Kit.PdfViewer
Dim oPrinterSettings As New System.Drawing.Printing.PrinterSettings
Dim oPageSettings As System.Drawing.Printing.PageSettings = Nothing

oPrinterSettings.PrinterName = “MyPrinter”

oPageSettings = oPrinterSettings.DefaultPageSettings

oPageSettings.Margins.Left = Convert.ToInt32(oPageSettings.HardMarginX * 2)
oPageSettings.Margins.Right = Convert.ToInt32(oPageSettings.HardMarginX * 2)
oPageSettings.Margins.Top = Convert.ToInt32(oPageSettings.HardMarginY * 2)
oPageSettings.Margins.Bottom = Convert.ToInt32(oPageSettings.HardMarginY * 2)

oViewer.OpenPdfFile(strmPDF)
oViewer.AutoResize = True
oViewer.AutoRotate = True
oViewer.PrintDocumentWithSettings(oPageSettings, oPrinterSettings)
oViewer.ClosePdfFile()

Hi Andrew,

Please share the PDF file you’re having problem with. We’ll test the issue at our end and update you accordingly.

We’re sorry for the inconvenience.
Regards,

It is happening on all PDFs that I try, but here is one that illustrates the problem well. I have tried this on the following printers with similar reuslts:
Lexmark E234
Lexmark E240
Lexmark E250d

Also not the text box about half way down the first page just above the “COVERAGE INFORMATION” header. When viewed or printed with Adobe Acrobat it looks normal, but when printed with Aspose.Pdf.Kit.PdfViewer there is text outside of the box on the right side.

Hi Andrew,

Thank you very much for sharing the PDF file. We’ll look into the matter and update you accordingly.

We’re sorry for the inconvenience.
Regards,

Hi Andrew,

I have tested the issue at my end couldn’t find the problem. I have attached the printed output with this post. Please have a look at the output and share your thoughts whether the margins are good or not. If you think it is good then please download latest version of Aspose.Pdf.Kit for .NET and test at your end. However, if you find there is still some problem then please clarify the problem using the output file attached.

We’re looking forward to help you out.
Regards,

The problem is not very noticeable when printing with the Microsoft XPS Document Writer. I have attached 2 TIFs that demonstrate the problem.They are both in the zip file. They have been named to show what software originally printed them as well as being labeled in the actual tiff.

One is the PDF attached above (pg 1) printed with Adobe Acrobat Viewer on a Lexmark E240 printer and then scanned in using a Visioneer 9450 USB scanner.

The other is the PDF attached above (pg 1) printed with Aspose.Pdf.Kit.PdfViewer using the code above on a Lexmark E240 printer (same machine and printer as with Adobe) and then scanned in using a Visioneer 9450 USB scanner.

On the actual tifs I made a note of the physical margin sizes in centimeters.

Hi Andrew,

I have reproduced both of the issues i.e margin and the text going out of the box, and logged these issues as PDFKITNET-11681 and PDFKITNET-11682 respectively in our issue tracking system. Our team will be looking into these issues and you’ll be updated via this forum once the issues are resolved.

We’re sorry for the inconvenience.
Regards,

Hi Shazad and Andrew,

I seem to be having the same problem. When comparing the printout of an existing pdf file created by Acrobat reader to the printout created by the PdfViewer class, the PdfViewer output is offset to the right and to the bottom, causing the right side and bottom of the pdf file to be cut off.
I've set my Acrobat 7.0 reader scaling to 'none' when printing.
The margins in the PageSettings used by PdfViewer are set to 0.
I'm using the 4.0.0.0 (.Net 2.0) dll of the Pdf.Kit.

Any updates on the issues?

Regards,

Jim.

Hi Jim,

I’m sorry to inform you that these issues are not yet resolved; however, our team is working on these issues and we’ll update you via this forum thread once these are resolved.

Moreover, it would be better if you could share the original PDF files along with the code snippet you’re using at your end, so we could test the issue with that. This is to make sure that the issue is fixed for your scenario as well.

We’re sorry for the inconvenience and appreciate your cooperation.
Regards,

Hi Shahzad,

I've attached an example. The last decimal of the amounts on the right gets cut off.

Regards,

Jim

Hi Jim,

I have tested this issue at my end using the file you supplied and the latest version (4.0.0), however I couldn’t notice the problem with the printed output. I have attached a sample output with this post as well.

Please have a look at the output shared by me. If I haven’t understood the problem properly then please correct me. However, if the output is fine then can you please make sure that you’re using the latest version at your end? Please remove any existing references and add reference to the new DLL.

If it still doesn’t resolve your problem then please share some more details regarding your development/production environment i.e. OS and printer details etc. The code you’re using at your end might also be helpful in reproducing the problem at our end.

We’re sorry for the inconvenience and appreciate your cooperation.
Regards,

Hi Shahzad,

Unfortunately I cannot scan the output here, but comparing the aspose output to the adobe output, the most right decimal of all the amounts on the right side are cut off. I'm running WinXP SP2 and we're developing a .net 2.0 app using VS2005. Our printer is a Kyocera KM-C3225 KX.

The print code:

public static void PrintPdfStream(Stream pDocumentStream, string PrinterName) {

pDocumentStream.Position = 0;
PrinterSettings printerSettings = null;
PageSettings pageSettings = null;
if (pPrinterName != null) {
printerSettings = new PrinterSettings();
printerSettings.PrinterName = pPrinterName;
if (!printerSettings.IsValid) {
throw new Exception("InvalidPrinter");
}
pageSettings = (PageSettings)printerSettings.DefaultPageSettings.Clone();
pageSettings.Margins.Top = 0;
pageSettings.Margins.Bottom = 0;
pageSettings.Margins.Left = 0;
pageSettings.Margins.Right = 0;
}

ActivateLicense();
PdfViewer pdfViewer = new PdfViewer();
pdfViewer.OpenPdfFile(pDocumentStream);
pdfViewer.PrintPageDialog = false;
pdfViewer.AutoResize = false;
if (printerSettings != null && pageSettings != null) {
pdfViewer.PrintDocumentWithSettings(pageSettings, printerSettings);
}
else {
pdfViewer.PrintDocument();
}
}

Hi Jim,

Thank you very much for sharing the details and code snippet.

We’ll again test this issue at our end in detail and you’ll be updated the earliest possible.

We’re sorry for the inconvenience.
Regards,

Hi Jim,

I have logged this issue as PDFKITNET-13874 in our issue tracking system. We need further testing to reproduce and then resolve this issue. You’ll be updated via this forum thread once the issue is resolved.

We’re sorry for the inconvenience.
Regards,

Hi Shahzad,

Any updates on the issue?

Jim.

Hi Jim,

I would like to share with you that our team is working on this issue; however, I’m afraid, this issue is not yet resolved. We’ll try to resolve it the earliest possible and you’ll be updated accordingly.

We’re sorry for the inconvenience.
Regards,

Hi, I would just like to get a status update on this defect, since it is one key problem forcing us to use a workaround for pdf printing at the moment.

Hi Joacim,

The following two issues are resolved and a fix will be available in our upcoming monthly release due at the end of next week:

PDFKITNET-11682 - Margins are bigger than the original file
PDFKITNET-13874 - Margin issue: right decimal digits are cut off

However, the following issue is not yet resolved and our team is still working on this issue:

PDFKITNET-11681 - Text goes out of borders when printed with PdfViewer

I hope this helps. If you have any further questions, please do let us know.
Regards,

The issues you have found earlier (filed as 11682;13874) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as 11681) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.