0

Server generates A student letter which includes two parts. one about information of student and admission details and other is the identity card.

I want to crop out the identity card of student to jpeg file and print it.

But the problem is the location of the card is not consistent. If it was then there was no problem.

To undertand it better take a look at the structre of the content:

enter image description here

The identity card is inside the cutout part which is lower one.

Now as there is free space and the location of content is changed sometimes.

like in the image the free space is at the bottom and content is not in center but at times the free space is at the top and content is centerd/not centered.

Is it possible to remove blank space from TOP RIGHT BOTTOM LEFT and convert the pdf to jpeg having just the outer border with content inside with Ghostscript ?

If not then is there any way to detect the position of the outer border ?

The PDF Generation server is not under my controll i just have the PDF.

  • Getting the box to stabilize might be accomplished with -dFitPage. To crop look for this: https://stackoverflow.com/questions/12484353/how-to-crop-a-section-of-a-pdf-file-to-png-using-ghostscript/12485020#12485020 – beginner6789 Nov 06 '20 at 17:29
  • I have had good luck using the "fit to page" first converting the pdf to an eps with eps2eps or gs -sDEVICE=eps2write then converting the eps to pdf with gs -dFitPage option. That should give a consistent result for doing the final crop. – beginner6789 Nov 07 '20 at 00:16
  • @beginner6789 so i tried it with various pdfs that i had. converting pdf to eps is showing the magic. converting that eps to pdf is ok. but converting the pdf to image is making more blank space at the top. it is just moving the content to left bottom corner. and the eps file itself has a right margin/blankspace, which i can manage. But the important thing is that it didn't worked on all files. it worked on just an older one. in newer it just didn't did anything rather reduced the quality of output. – ChandraShekharAazad Nov 07 '20 at 06:15
  • this is the sh file `#!/bin/bash gs -dBATCH -dSafer -dNOPAUSE -r300 -dFitPage -sDEVICE=eps2write -sPDFPassword=CHANDRA -sOutputFile=temp/out.eps ELatest.pdf gs -dBATCH -dSafer -dNOPAUSE -r300 -dFitPage -sDEVICE=eps2write -sOutputFile=temp/out.pdf temp/out.eps gs -dBATCH -dSafer -dNOPAUSE -sDEVICE=jpeg -sOutputFile=GSOUT/out.jpeg temp/out.pdf ` – ChandraShekharAazad Nov 07 '20 at 06:15
  • There is also -dEPSCrop that might work instead of -dFitPage. The EPSCrop uses the bounding box comments in the eps file so could help if the size of the box stays the same when moving around the page. Your command line above should have the eps2write output as an eps file. I have been using the eps file as an input to the -sDEVICE=jpeg. – beginner6789 Nov 07 '20 at 13:33
  • I tried both `EPSCrop` and `EPSFitpage` but none worked as expected. However converting pdf to eps is not helping at all as it's not working on newer files, worked on just few older files. and that too with quality loss. i indeed set the `-r300` param. KenS left the community else he would have gave some suggestions. Anyways, do you have any knowledge in machine learning ? if it can help in this scenario ? – ChandraShekharAazad Nov 07 '20 at 15:29

0 Answers0