You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Aaron Mulder <am...@gmail.com> on 2019/01/31 01:52:37 UTC

Flattening (?) Problem 2.0.5->2.0.11

I have a PDF workflow where I take a base document with forms, then
append a footer that puts values in the form fields and save the
result, then open it with PDFBox and flatten it:

doc = PDDocument.load(tempFile);
doc.getDocumentCatalog().getAcroForm().flatten();

Then I add an image to the page and save and close the doc:

PDPage page = doc.getPage(0);
PDImageXObject image = LosslessFactory.createFromImage(doc,
toBufferedImage(generateBarcode("PC"+pcId)));
PDPageContentStream contentStream = new PDPageContentStream(doc, page,
PDPageContentStream.AppendMode.APPEND, true);
contentStream.drawImage(image, 246, 36 );
contentStream.close();
doc.save(tempFile);
doc.close();

Finally, I print it from the command line.  With PDFBox 2.0.5 the
resulting document prints fine.  I'm using this command on macOS:

/usr/bin/lpr -P TestPrinter -o InputSlot=Tray2 file.pdf

With PDFBox 2.0.11 when I do the same, the form fields all come
through as empty on the printout.  (They do appear when I open the doc
in Preview.)

I don't really know why; I just tried updating to the latest on a
lark.  It feels like the flattening failed on 2.0.11.  The printer is
a bit dated and I think I went with flattening in the first place
because that was the only way to get the doc to print correctly from
the command line.

I will stick with 2.0.5 for now because for this case it's critical
that the printouts work.  :)

Thanks,
      Aaron

Output from 2.0.5: http://opentools.org/files/print-job-2514255277731407198.pdf
Output from 2.0.11: http://opentools.org/files/print-job-4933385101348305078.pdf

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Flattening (?) Problem 2.0.5->2.0.11

Posted by Aaron Mulder <am...@gmail.com>.
Exactly.  That entire StackOverflow thread represents my experience
perfectly: specifying a paper type or paper tray involves a lot of
code and even then it just doesn't work.  One person tried writing
their own driver and THAT didn't work.  Another used a perl script to
intercept jobs and do something Java couldn't/wouldn't.  An apologist
says "gee, it's HARD to identify printer capabilities cross-platform."
 As if, you know, implementing a whole VM is a piece of cake -- it's
only printing that's hard.  Right?

Anyway, reading that hasn't given me much incentive to change my
approach of using "lpr".  :)

And, for what it's worth, I'm perfectly happy to continue using 2.0.5
with lpr since that works for me.  I will still try the latest and
that extra parameter when I get a chance, though.

Thanks,
      Aaron

On Fri, Feb 1, 2019 at 12:57 PM Tilman Hausherr <TH...@t-online.de> wrote:
>
> Am 01.02.2019 um 14:50 schrieb Aaron Mulder:
> > Historically, I haven't been able to print from within Java because I
> > must be able to turn duplex on and off and specify a source paper tray
> > (one has paper, one has labels, and different jobs go to each).  I
> > never got that to work except via lpr.  Though, it's probably been a
> > couple years since I tried because the current system works.  :)
>
>
> Duplex is like this:
>
>
>              PrinterJob job = PrinterJob.getPrinterJob();
>              job.setPageable(new PDFPageable(document));
>              PrintRequestAttributeSet pras = new
> HashPrintRequestAttributeSet();
>              pras.add(Sides.TWO_SIDED_LONG_EDGE);
>
>              if (job.printDialog(pras))
>              {
> setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
>                  try
>                  {
>                      job.print(pras);
>                  }
>                  finally
>                  {
>                      setCursor(Cursor.getDefaultCursor());
>                  }
>              }
>
> tray is more tricky, see e.g.
>
> https://stackoverflow.com/questions/14328012/printing-with-attributestray-control-duplex-etc-using-javax-print-library
>
> Tilman
>
>
> >
> > I'll try the snapshot and code change when I get a chance.
> >
> > Thanks,
> >         Aaron
> >
> > On Thu, Jan 31, 2019 at 12:17 AM Tilman Hausherr <TH...@t-online.de> wrote:
> >> Hi,
> >> The current version is 2.0.13. Did you try with that one? Also try with
> >> a 2.0.14 snapshot
> >> https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.14-SNAPSHOT/
> >>
> >> and please share the source file, and modify the code so that the fifth
> >> parameter of
> >>
> >> PDPageContentStream() is true.
> >>
> >> Consider printing from PDFBox itself.
> >>
> >> Tilman
> >>
> >> Am 31.01.2019 um 02:52 schrieb Aaron Mulder:
> >>> I have a PDF workflow where I take a base document with forms, then
> >>> append a footer that puts values in the form fields and save the
> >>> result, then open it with PDFBox and flatten it:
> >>>
> >>> doc = PDDocument.load(tempFile);
> >>> doc.getDocumentCatalog().getAcroForm().flatten();
> >>>
> >>> Then I add an image to the page and save and close the doc:
> >>>
> >>> PDPage page = doc.getPage(0);
> >>> PDImageXObject image = LosslessFactory.createFromImage(doc,
> >>> toBufferedImage(generateBarcode("PC"+pcId)));
> >>> PDPageContentStream contentStream = new PDPageContentStream(doc, page,
> >>> PDPageContentStream.AppendMode.APPEND, true);
> >>> contentStream.drawImage(image, 246, 36 );
> >>> contentStream.close();
> >>> doc.save(tempFile);
> >>> doc.close();
> >>>
> >>> Finally, I print it from the command line.  With PDFBox 2.0.5 the
> >>> resulting document prints fine.  I'm using this command on macOS:
> >>>
> >>> /usr/bin/lpr -P TestPrinter -o InputSlot=Tray2 file.pdf
> >>>
> >>> With PDFBox 2.0.11 when I do the same, the form fields all come
> >>> through as empty on the printout.  (They do appear when I open the doc
> >>> in Preview.)
> >>>
> >>> I don't really know why; I just tried updating to the latest on a
> >>> lark.  It feels like the flattening failed on 2.0.11.  The printer is
> >>> a bit dated and I think I went with flattening in the first place
> >>> because that was the only way to get the doc to print correctly from
> >>> the command line.
> >>>
> >>> I will stick with 2.0.5 for now because for this case it's critical
> >>> that the printouts work.  :)
> >>>
> >>> Thanks,
> >>>         Aaron
> >>>
> >>> Output from 2.0.5: http://opentools.org/files/print-job-2514255277731407198.pdf
> >>> Output from 2.0.11: http://opentools.org/files/print-job-4933385101348305078.pdf
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> >>> For additional commands, e-mail: users-help@pdfbox.apache.org
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> >> For additional commands, e-mail: users-help@pdfbox.apache.org
> >>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> > For additional commands, e-mail: users-help@pdfbox.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Flattening (?) Problem 2.0.5->2.0.11

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 01.02.2019 um 14:50 schrieb Aaron Mulder:
> Historically, I haven't been able to print from within Java because I
> must be able to turn duplex on and off and specify a source paper tray
> (one has paper, one has labels, and different jobs go to each).  I
> never got that to work except via lpr.  Though, it's probably been a
> couple years since I tried because the current system works.  :)


Duplex is like this:


             PrinterJob job = PrinterJob.getPrinterJob();
             job.setPageable(new PDFPageable(document));
             PrintRequestAttributeSet pras = new 
HashPrintRequestAttributeSet();
             pras.add(Sides.TWO_SIDED_LONG_EDGE);

             if (job.printDialog(pras))
             {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                 try
                 {
                     job.print(pras);
                 }
                 finally
                 {
                     setCursor(Cursor.getDefaultCursor());
                 }
             }

tray is more tricky, see e.g.

https://stackoverflow.com/questions/14328012/printing-with-attributestray-control-duplex-etc-using-javax-print-library

Tilman


>
> I'll try the snapshot and code change when I get a chance.
>
> Thanks,
>         Aaron
>
> On Thu, Jan 31, 2019 at 12:17 AM Tilman Hausherr <TH...@t-online.de> wrote:
>> Hi,
>> The current version is 2.0.13. Did you try with that one? Also try with
>> a 2.0.14 snapshot
>> https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.14-SNAPSHOT/
>>
>> and please share the source file, and modify the code so that the fifth
>> parameter of
>>
>> PDPageContentStream() is true.
>>
>> Consider printing from PDFBox itself.
>>
>> Tilman
>>
>> Am 31.01.2019 um 02:52 schrieb Aaron Mulder:
>>> I have a PDF workflow where I take a base document with forms, then
>>> append a footer that puts values in the form fields and save the
>>> result, then open it with PDFBox and flatten it:
>>>
>>> doc = PDDocument.load(tempFile);
>>> doc.getDocumentCatalog().getAcroForm().flatten();
>>>
>>> Then I add an image to the page and save and close the doc:
>>>
>>> PDPage page = doc.getPage(0);
>>> PDImageXObject image = LosslessFactory.createFromImage(doc,
>>> toBufferedImage(generateBarcode("PC"+pcId)));
>>> PDPageContentStream contentStream = new PDPageContentStream(doc, page,
>>> PDPageContentStream.AppendMode.APPEND, true);
>>> contentStream.drawImage(image, 246, 36 );
>>> contentStream.close();
>>> doc.save(tempFile);
>>> doc.close();
>>>
>>> Finally, I print it from the command line.  With PDFBox 2.0.5 the
>>> resulting document prints fine.  I'm using this command on macOS:
>>>
>>> /usr/bin/lpr -P TestPrinter -o InputSlot=Tray2 file.pdf
>>>
>>> With PDFBox 2.0.11 when I do the same, the form fields all come
>>> through as empty on the printout.  (They do appear when I open the doc
>>> in Preview.)
>>>
>>> I don't really know why; I just tried updating to the latest on a
>>> lark.  It feels like the flattening failed on 2.0.11.  The printer is
>>> a bit dated and I think I went with flattening in the first place
>>> because that was the only way to get the doc to print correctly from
>>> the command line.
>>>
>>> I will stick with 2.0.5 for now because for this case it's critical
>>> that the printouts work.  :)
>>>
>>> Thanks,
>>>         Aaron
>>>
>>> Output from 2.0.5: http://opentools.org/files/print-job-2514255277731407198.pdf
>>> Output from 2.0.11: http://opentools.org/files/print-job-4933385101348305078.pdf
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Flattening (?) Problem 2.0.5->2.0.11

Posted by Aaron Mulder <am...@gmail.com>.
Historically, I haven't been able to print from within Java because I
must be able to turn duplex on and off and specify a source paper tray
(one has paper, one has labels, and different jobs go to each).  I
never got that to work except via lpr.  Though, it's probably been a
couple years since I tried because the current system works.  :)

I'll try the snapshot and code change when I get a chance.

Thanks,
       Aaron

On Thu, Jan 31, 2019 at 12:17 AM Tilman Hausherr <TH...@t-online.de> wrote:
>
> Hi,
> The current version is 2.0.13. Did you try with that one? Also try with
> a 2.0.14 snapshot
> https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.14-SNAPSHOT/
>
> and please share the source file, and modify the code so that the fifth
> parameter of
>
> PDPageContentStream() is true.
>
> Consider printing from PDFBox itself.
>
> Tilman
>
> Am 31.01.2019 um 02:52 schrieb Aaron Mulder:
> > I have a PDF workflow where I take a base document with forms, then
> > append a footer that puts values in the form fields and save the
> > result, then open it with PDFBox and flatten it:
> >
> > doc = PDDocument.load(tempFile);
> > doc.getDocumentCatalog().getAcroForm().flatten();
> >
> > Then I add an image to the page and save and close the doc:
> >
> > PDPage page = doc.getPage(0);
> > PDImageXObject image = LosslessFactory.createFromImage(doc,
> > toBufferedImage(generateBarcode("PC"+pcId)));
> > PDPageContentStream contentStream = new PDPageContentStream(doc, page,
> > PDPageContentStream.AppendMode.APPEND, true);
> > contentStream.drawImage(image, 246, 36 );
> > contentStream.close();
> > doc.save(tempFile);
> > doc.close();
> >
> > Finally, I print it from the command line.  With PDFBox 2.0.5 the
> > resulting document prints fine.  I'm using this command on macOS:
> >
> > /usr/bin/lpr -P TestPrinter -o InputSlot=Tray2 file.pdf
> >
> > With PDFBox 2.0.11 when I do the same, the form fields all come
> > through as empty on the printout.  (They do appear when I open the doc
> > in Preview.)
> >
> > I don't really know why; I just tried updating to the latest on a
> > lark.  It feels like the flattening failed on 2.0.11.  The printer is
> > a bit dated and I think I went with flattening in the first place
> > because that was the only way to get the doc to print correctly from
> > the command line.
> >
> > I will stick with 2.0.5 for now because for this case it's critical
> > that the printouts work.  :)
> >
> > Thanks,
> >        Aaron
> >
> > Output from 2.0.5: http://opentools.org/files/print-job-2514255277731407198.pdf
> > Output from 2.0.11: http://opentools.org/files/print-job-4933385101348305078.pdf
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> > For additional commands, e-mail: users-help@pdfbox.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Flattening (?) Problem 2.0.5->2.0.11

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
The current version is 2.0.13. Did you try with that one? Also try with 
a 2.0.14 snapshot
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.14-SNAPSHOT/

and please share the source file, and modify the code so that the fifth 
parameter of

PDPageContentStream() is true.

Consider printing from PDFBox itself.

Tilman

Am 31.01.2019 um 02:52 schrieb Aaron Mulder:
> I have a PDF workflow where I take a base document with forms, then
> append a footer that puts values in the form fields and save the
> result, then open it with PDFBox and flatten it:
>
> doc = PDDocument.load(tempFile);
> doc.getDocumentCatalog().getAcroForm().flatten();
>
> Then I add an image to the page and save and close the doc:
>
> PDPage page = doc.getPage(0);
> PDImageXObject image = LosslessFactory.createFromImage(doc,
> toBufferedImage(generateBarcode("PC"+pcId)));
> PDPageContentStream contentStream = new PDPageContentStream(doc, page,
> PDPageContentStream.AppendMode.APPEND, true);
> contentStream.drawImage(image, 246, 36 );
> contentStream.close();
> doc.save(tempFile);
> doc.close();
>
> Finally, I print it from the command line.  With PDFBox 2.0.5 the
> resulting document prints fine.  I'm using this command on macOS:
>
> /usr/bin/lpr -P TestPrinter -o InputSlot=Tray2 file.pdf
>
> With PDFBox 2.0.11 when I do the same, the form fields all come
> through as empty on the printout.  (They do appear when I open the doc
> in Preview.)
>
> I don't really know why; I just tried updating to the latest on a
> lark.  It feels like the flattening failed on 2.0.11.  The printer is
> a bit dated and I think I went with flattening in the first place
> because that was the only way to get the doc to print correctly from
> the command line.
>
> I will stick with 2.0.5 for now because for this case it's critical
> that the printouts work.  :)
>
> Thanks,
>        Aaron
>
> Output from 2.0.5: http://opentools.org/files/print-job-2514255277731407198.pdf
> Output from 2.0.11: http://opentools.org/files/print-job-4933385101348305078.pdf
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org