Force to print in legal paper - c#

I'm using iTextSharp to generate PDF documents in my asp.net application. That works great. The only issue I have is when I generate a PDF document with size of a legal paper and print it, the printer use the default paper which is letter size. I have to change the printing options manually in order to print it in legal paper. Is there a way I can specify in which paper size I want the document to print programmatically so that I won't have to do it manually?
I'm using this line of code to specify the page size in iTextSharp:
Document doc = new Document(PageSize.LEGAL.Rotate());

You cannot control the client printer. That would be a huge security problem in the PDF format. It is up to that computer's settings.

Ok, I found the answer in another post: Propagate the orientation setup at iTextSharp.text.Document creation to the Print dialog.
The key is to set the viewer preference Choose paper source by PDF page size to true.
writer.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE);

Related

Microsoft Interop.Word - Ignore Printer Settings When Changing PaperSize

I'm changing the PaperSize property of the document to A3. The currently connected printer can only print A4 so Word isn't allowing me to set the paper size bigger.
Is there a way to ignore this error and have the paper size changed anyway? I'm not wanting to print, just create a Word document of this size.
Thanks
As suggested by #HansPassant changing the printer to be "XPS Document Writer" solved the problem for me.

Prevent chrome to re size PDF for printing

I am generating PDF file using migradoc library in a .NET webpage. PDF gets generated as expected. When I save the PDF from chrome to file system and print it using "Actual size" option, the resulting print is same as PDF preview.
Problem is when I directly print it from chrome, apparently it gets resized, therefore the output PDF doesn't look Identical as preview (Some table borders gets disappeared). Any helping idea is appreciated.
You're essentially printing from two different sources. When you print the PDF document (from your file system) as "Actual Size," that size is going to be dictated by the bounding box/page dimensions specified in the document at the time that it was saved to a file.
When you print your document image directly from Chrome, it's Chrome's print options and display options that will be in effect; e.g. Portrait vs. Landscape, to cite one obvious choice you can make. The Chrome print output will be determined by the settings in effect at the time the print job is generated.

iTextSharp printing variable length document

After trying as many possibilities as I can without successful result, here is my question regarding with iTextsharp component.
I have a requirement on creating a ticket for which I decided to use the iTextSharp Library.
I have used this library on java & .net projects with fixed length documents without problems but in this case document is variable length. The document is created perfectly and accordingly with the spec. After the PDF is created I use System.Diagnostics.Process with the verb “PrintTo” for send it to the printer. Due to the variable length nature of the ticket it is not adequate to set a fixed paper length on the printer, so I use the following line to instruct the printer to take the document size (accordingly with Manning iText in Action 2nd Edition, page 140) but it seem not to function properly.
writer.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, new PdfBoolean(true));
Any ideas on how could I send the document to printer instructing the printer to adjust the paper size to the document size?
Thanks in advance,
By using GhostScript (GHS) and mswinpr2as printing device we were able to print to practically any printer recognized for the Operative System (Windows).
To stablish the paper size it is necesary to set the following arguments when invoking GHS command line utility (gswin32c):
dFIXEDMEDIA
dDEVICEWIDTHPOINTS = value
dDEVICEHEIGHTPOINTS = value
sOutputFile = "%printer%PRINTER_NAME"

Convert MsWord first page to Image

I have an msword document that consists of some pages, i need convert only the first page to image and save it. Each page can consist of images, tables, text, etc. But i can't use clipboard buffer or any commercial software.
May be anybody know some other ways ?
You can turn on the "Generate thumbnail for Document" option and word will generate an image for you (that Windows 7 uses to show the large icon view of the document.
In word 2010, click File-Info
then the Properties Drop down
Then Advanced properties
Then Summary tab
and finally SHOW PREVIEW PICTURE
And what's worse, you can't automate it! Ugh, Something about a security risk.
When you do that, there will be an extra WMF file embedded within the DOCX that you can extract.
Print your first page to the Microsoft Office Document Image Writer.
It will give you a TIFF image.
EDIT
Alternatively, print to the Microsoft XPS Document Writer and then convert XPS to an image.

ReportViewer.PrintDialog() throws exception when printing to Adobe PDF

I am working on a WinForms app that uses the ReportViewer control to show a few Reporting Services reports. On these screens, we allow the user to print the report by calling the PrintDialog() method on the ReportViewer like so:
_reportViewer.PrintDialog();
This works fine in most cases, it brings up the standard windows print dialog, the user chooses what printer they want to print to, and it prints. However, when the user chooses to print to PDF using "Adobe PDF", it throws a Win32Exception: The specified datatype is invalid. The file dialog to choose where to save the pdf doesn't even come up.
This only happens with Adobe PDF printer. I installed NitroPDF and used their PDF printer and it works without a problem.
Does anybody have an idea on what could be causing this to happen?
Edit:
Here is the stack trace:
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Microsoft.Reporting.WinForms.ReportViewer.PrintDialog(PrinterSettings printerSettings)
at Microsoft.Reporting.WinForms.ReportViewer.PrintDialog()
This doesn't truly fix the problem but solves it in the users' eyes.
Trap the error thrown by the PDF Printer then invoke the Export to PDF functionality built into Reporting Services. It doesn't error in Winforms even when printing to the PDF Printer does. From the user perspective they "printed to pdf" like normal and the experience is identical. It's a work around that works. :-)
AFAIK the ReportViewer control just renders each page as a bitmap image. So when printing to PDF, if the resolution is high, it could be a huge bitmap. Maybe AdobePDF has problems with large bitmaps, Adobe have so many other bugs! Try lowering the resolution as a test?
I have an application that uses the ReportServer API to get the page bitmaps and chunks them into parts to be handled by a custom print processor
Could it be that the contents of the report are creating this problem. I mean to say that the report may contain certain characters that Adobe PDF printer is not able to recognize.
Can you try to print a very simple/basic/blank report and see if that works.

Categories

Resources