Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How print a very long single page PDF #4736

Open
zuoliang0 opened this issue Dec 26, 2024 · 9 comments
Open

How print a very long single page PDF #4736

zuoliang0 opened this issue Dec 26, 2024 · 9 comments

Comments

@zuoliang0
Copy link

Is your feature request related to a problem? Please describe.
I have a very long A4 width pdf. My printer is a dot matrix printer that can automatically feed paper. I tried to use this software to print it, but I only got one A4 width page.

Describe the solution you'd like
What I hope is to be able to achieve something like custom paper, so that the content of this page can be printed out completely (without scaling)
Is it possible to customize a paper size by read the width and height of the PDF when printing?

Describe alternatives you've considered
My current alternative is to render the PDF into A4 width and height, divided into many pages, which can be printed at present, but because each page has a little blank space at the end, the printed content will be interrupted (my PDF is a long table)

Additional context
print_1735184594331.pdf test pdf file

@GitHubRulesOK
Copy link
Collaborator

GitHubRulesOK commented Dec 26, 2024

but I only got one A4 width page. is how the default printer is defined.

SumatraPDF does not alter the source page dimensions nor describe how to be printed. Those are all set by the system but there are constraints. SumatraPDF will simply honour the system settings at the time of print handover as pixels so if the system requires A4 pages or requires USA Letter then SumatraPDF uses those page defined pixels units.

Printers have a limited length of paper sizes so a GhostScript printer may easily be limited to a nominal 2 m or 5 m but SumatraPDF can use those length no problem.

If you are using PDF to be printed to a non default size then GhostScript PDL is probably the best command line method.

For a heads up use it is more restricted. I have shown SumatraPDF can work with pages of up to 200" nominal length but dont recommend it be done that way. https://stackoverflow.com/a/78321355/10802527

@zuoliang0
Copy link
Author

I still don't quite understand, what do I need to do to print this file completely?

I just tested using GhostScript to print this file directly, and it can only print the first page (A4 length)
Then I tested manually specifying the width and height of the device, and the printing prompt would be an error

gswin32 -dNOPAUSE -dBATCH -sDEVICE=mswinpr2 -sOutputFile="%printer%EPSON LQ-82KF ESC/P2 (副本 1)" -dDEVICEWIDTHPOINTS 794 -dDEVICEHEIGHTPOINTS 6060 output1.pdf

image

I tried many solutions, but it still doesn't work. Am I trying the wrong direction?

@GitHubRulesOK
Copy link
Collaborator

GitHubRulesOK commented Dec 27, 2024

Command line printers expect to be run in a system command console you seem to be trying to print from within some windows wrapper application ?

Try your commands in the windows command console before move to any form of embedment. use gswin32C.exe

PDF is unitless but has a maximum length so you need to debug what units you are attempting.
also devices may need to be physically configured to use rolls of paper not sheets. That looks like a small sheet printer.

If the file is long and the printer short you need to slice the page into parts (decimation) MuPDF has a poster command.

Mutool poster -x 1 -y ## as may be required to be less than A4 high

For finer control over where a page is split it will need a more complex approach such as via coherent cpdf read chapter 9.3 Chopping up pages

@zuoliang0
Copy link
Author

Thank you very much for your patience.

Yes, we are developing a program for printing HTML to a printer. At first we tried to print directly, but encountered paging problems. Then we tried to make the HTML into a long single-page PDF, but it seems that software like SumatraPDF or pdftopinter can not support direct printing.

I used mutool to crop the file according to your method. From the PDF point of view, there is indeed no upper and lower margins, but when it is printed out through the printer, a blank line will still be generated after printing a page.

I think this blank line is because of the natural behavior of the printer, which can't be avoided by the way we cut pdf.

I feel powerless.

@GitHubRulesOK
Copy link
Collaborator

GitHubRulesOK commented Dec 27, 2024

PDF in effect is borderless i.e. does not have any "margins" as such
So if you have a page of 3.5 x A4 long you would need to make that an additional white space at end of last page to be half a void long this is relatively easy but slightly counter intuitive since that would be a negative half page below the bottom left origin that a PDF uses.

cpdf has the ability to modify page shapes to suit 4 x A4 high before chop and had shown such example in other forums but was deleted !

If you simply need images of pages to send to a printer since ink can be pixels not vectors, it is perhaps simpler to use Magick and here I described a similar case. https://stackoverflow.com/a/78615507/10802527 the accepted answer (below mine) may or may not be better.

dont worry about the maths concentrate on the reasons for each of my 3 methods and the accepted method (not mine) is discussed here ImageMagick/ImageMagick#7402

@zuoliang0
Copy link
Author

It depends. This problem has nothing to do with cropping. I have provided a cropped PDF here. You can see that there are no borders. However, after printing a page through the printer, the printer will still retain 2 lines of blank space.
out.pdf

mutool -x 1 -y 5 out.pdf

I'm trying other methods, maybe I don't need to convert HTML to PDF before printing

@GitHubRulesOK
Copy link
Collaborator

GitHubRulesOK commented Dec 31, 2024

Hmmm several problems with such tables. They are best created with a Spreadsheet application such as Excel where there each page can be controlled with new headers per page.

Microsoft Edge says page size is "280 × 428 mm (portrait)" I know that is clearly wrong so the pages are physically 210 x 321 mm ? which is not European nor American printing paper.

A bigger problem is that it is "tabular" so no easy places to cut unless you aim for a border between cells.

The one tool I know can split with such precision (but needs some trial and error to get perfect) is cpdf -chop-h where you split and split again until all pages are done.

Recently gave an example elsewhere of vertical slicing with 2 precision cuts but it worked https://stackoverflow.com/a/79314388/10802527

@GitHubRulesOK
Copy link
Collaborator

GitHubRulesOK commented Dec 31, 2024

OK forget that suggestion it is exceptionally slow in chopping a very long page such as that, and would be hard to decide where to split. We call this an XY problem where trying to fix a bad input simply is not worth it when the problem lies with the generation of such un-paged format. Page Breaks should be done at the source, or for a roll printer use the printers own language e.g. HPGL for a plotter or ZPL for a Zebra.
output.pdf

cpdf -chop-h 3399 print_1735184594331.pdf -o 2bits.pdf
cpdf -chop-h 2576 2bits.pdf 2 -o 3bits.pdf
cpdf -chop-h 1760 3bits.pdf 3 -o 4bits.pdf
cpdf -chop-h 935 4bits.pdf 4 -o 5bits.pdf
cpdf -chop-h 100 5bits.pdf 5 -o output.pdf
del *bits.pdf

image

@zuoliang0
Copy link
Author

zuoliang0 commented Dec 31, 2024

Yes, not only is it troublesome to cut, but the PDF after paging will still have a blank line when printed. I suspect it is a problem with the printer.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants