Ankit Srivastava
Ankit Srivastava

Reputation: 1

Saving / Printing a PrintDocument object to a JPEG/ BMP or any image format

I know this question is not new, but unfortunately I am not able to get the right answer yet. Therefore trying to ask this question again. My Scenario I am building a payment receipt using the data that I am collecting during the entire shopping cart and billing process. All these steps are done, and I am able to create a printdocument at run time, and also save it to PDF format using the code etc. All that is working fine.

Required business process:

I want to give the end user two options. a) To print the bill using a small printer, which generally picks smaller size paper rolls and do hot printing, similar to credit card readers etc. b) If the customer does not want a hard copy of the bill, then send the bill to customer's whatsapp.

Now, I have done the required things for achieving a) above, and there is absolutely no problem in that, however when I try to print the PrintDocument using internal PDF printer it always prints the document in full A4 paper size, whereas I specifically define the paper size to be only 250 wide and 700 height.

The problem now comes as the PDF document which comes out of the printdocument printing, has a lot of white space on the right and the bottom.

Question:

My basic problem is to get rid of this white space. How do I get rid of this extra white space after printing.

My thoughts:

Since I can not control the default paper size of the inbuilt pdf creator, I thought instead of creating a pdf file, I can create an image file using the printdocument that I am anyways creating in my code. The problem is I do not know how.

If any one of you can help me figuring out how to achieve this, I would be really thankful.

Not sharing my code here, because I think making a printdocument is very straight forward, because all i am doing is putting some e.graphics.drawstring lines to put some title and some product names etc on the print document.

I can still share if needed, but i know for experts like you it is pretty standard.

Please help me in either

a) eliminating the extra white spaces directly in the pdf document itself so that it can be shared directly with the customer

OR

b) Save/Print the printdocument to an image so that the JPG file only contains the correct image without the extra white space on the right and bottom side.

Thanks in advance.

What I already tried

I tried installing some printers available online which can print in jpg formats but they are not free. either they leave a watermark or need license. Also, using these printers in code creates a .prn file, which is of no good, as the user will have to manually print them again using these printers to get the JPG file.

I want all of this receipt generation activity to be unseen by the user. The moment the user clicks on save bill, the system should be able to create the printdocument ready, and then either the user can print the document using the correct printer, or close print preview and use the JPG file to upload in whatsapp of the customer.

Upvotes: 0

Views: 142

Answers (0)

Related Questions