You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andreas Lehmkühler <an...@lehmi.de.INVALID> on 2024/03/14 20:55:07 UTC

[ANNOUNCE] Apache PDFBox 3.0.2 released

The Apache PDFBox community is pleased to announce the release of
Apache PDFBox version 3.0.2. The release is available for download at:

https://pdfbox.apache.org/download.html

See the full release notes below for details about this release.

Release Notes -- Apache PDFBox -- Version 3.0.2

Introduction
------------

The Apache PDFBox library is an open source Java tool for working with 
PDF documents.

This is an incremental bugfix release based on the earlier 3.0.1 
release. It contains
a couple of fixes and small improvements.

A migration guide is available at 
https://pdfbox.apache.org/3.0/migration.html. It is
still a work in progress and we are happy to include any valuable 
feedback from our
community.

For more details on these changes and all the other fixes and improvements
included in this release, please refer to the following issues on the
PDFBox issue tracker at https://issues.apache.org/jira/browse/PDFBOX.

Bug

[PDFBOX-2725] - [PATCH] Split pdf lose accessibility tags
[PDFBOX-5375] - Allow creating of PDFXObjectImage without accessing to 
the image stream
[PDFBOX-5704] - char not rendered
[PDFBOX-5714] - PDFBox 3.0 regression: duplicate references in 
dictionary values
[PDFBOX-5715] - Lines vanish when printing on MacOS
[PDFBOX-5717] - NullPointerException calling 
saveIncrementalForExternalSigning
[PDFBOX-5721] - The embedded font DroidSansFallbackFull reports an error 
when parsing, and finally uses lastResortFont, resulting in garbled fonts.
[PDFBOX-5722] - Wrong scope for maven dependencies
[PDFBOX-5723] - COSName caches already cached hashCode
[PDFBOX-5724] - CharStringCommand.equals() does not conform to the 
contract of Object.equals
[PDFBOX-5727] - Font operation takes a long time with 3.0.1
[PDFBOX-5728] - NullPointerException in TTFSubsetter.buildPostTable()
[PDFBOX-5730] - The expected SubstFormat for ExtensionSubstFormat1 
subtable is 108 but should be 1
[PDFBOX-5732] - Problem converting PDF to image 
(java.awt.color.CMMException: Can not access specified profile)
[PDFBOX-5733] - lookupType is to be replaced by extensionLookupType in 
type 7 lookup table
[PDFBOX-5735] - Set the default value for PDNonTerminalField
[PDFBOX-5737] - java.lang.ArrayIndexOutOfBoundsException Bug Report
[PDFBOX-5738] - Wrong colors in PDF since PDFBOX-5488
[PDFBOX-5742] - Split result PDFs broken
[PDFBOX-5744] - EOFException while readMultipleSubstitutionSubtable()
[PDFBOX-5745] - EOFException while readSingleLookupSubTable()
[PDFBOX-5748] - Cannot get overlayPDF working on command line interface
[PDFBOX-5751] - Convert to image exception
[PDFBOX-5752] - Font errors after copying a page to another document
[PDFBOX-5754] - PDF conversion in this format is very slow. Is there any 
room for optimization?
[PDFBOX-5757] - streamCacheCreateFunction not passed to PDFParser
[PDFBOX-5758] - ExceptionInInitializerError when unmapping is not supported
[PDFBOX-5760] - NPE in FIlter.decode() when called with empty list
[PDFBOX-5763] - IllegalArgumentException: -Infinity is not a finite number
[PDFBOX-5764] - Wrong chunksize when using a ByteBuffer to initialize a 
RandomAccessReadBuffer
[PDFBOX-5772] - Inconsistent signature page handling when signing in 
existing signature fields
[PDFBOX-5773] - Add leading "0" for octal values in MacOSRomanEncoding
[PDFBOX-5775] - importPage destroys annotations
[PDFBOX-5776] - DataFormatException: invalid distance too far back
[PDFBOX-5778] - Grayscale JPEG rendered multicolor
[PDFBOX-5781] - OutOfMemoryError in FileSystemFontsProvider.scanFonts
[PDFBOX-5782] - NPE in PageDrawer.getPaint()

New Feature

[PDFBOX-5768] - Enable Native Markdown Extraction in Apache PDFBox

Improvement

[PDFBOX-5729] - GsubWorkerForDevanagari and GsubWorkerForGujarati created
[PDFBOX-5762] - When splitting, keep page destinations that are part of 
target document(s)
[PDFBOX-5783] - Replace Exception with some repair attempt

Task

[PDFBOX-5739] - Add test for PDFBOX-3347
[PDFBOX-5741] - Add test for PDFBOX-4106

Release Contents
----------------

This release consists of a single source archive packaged as a zip file.
The archive can be unpacked with the jar tool from your JDK installation.
See the README.txt file for instructions on how to build this release.

The source archive is accompanied by SHA512 checksums and a PGP signature
that you can use to verify the authenticity of your download.
The public key used for the PGP signature can be found at
https://www.apache.org/dist/pdfbox/KEYS.

About Apache PDFBox
-------------------

Apache PDFBox is an open source Java library for working with PDF documents.
This project allows creation of new PDF documents, manipulation of existing
documents and the ability to extract content from documents. Apache PDFBox
also includes several command line utilities. Apache PDFBox is published
under the Apache License, Version 2.0.

For more information, visit https://pdfbox.apache.org/

About The Apache Software Foundation
------------------------------------

Established in 1999, The Apache Software Foundation provides organizational,
legal, and financial support for more than 100 freely-available,
collaboratively-developed Open Source projects. The pragmatic Apache License
enables individual and commercial users to easily deploy Apache software;
the Foundation's intellectual property framework limits the legal exposure
of its 2,500+ contributors.

For more information, visit https://www.apache.org/

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


Re: How to remove an image resource from a PDF form

Posted by Jurgen Doll <ju...@ivoryemr.co.za>.
Hi Tilman

Thanks for looking. I think I can understand  the font appearing 3 times  
in the resources - that's one for each open & save cycle where I do  
"resources.put( cosName, lucidaFont )" and "pdForm.setDefaultResources(  
resources )". At the moment I workaround that by doing a check first  
before putting. Could that be a PdfBox bug ?

The F3 (x2) I think may be coming from the original PDF form creation  
program (not PdfBox). Could it be one for the text and another for the  
field ?

Thanks, regards
Jurgen



On Tue, 30 Apr 2024 13:22:18 +0200, Tilman Hausherr  
<TH...@t-online.de> wrote:

> Hi,
>
> What I see in the biggest file is that the font appears 3 times in the  
> resources and 2 times in the default resources.
>
> resources.put() forces the name ("LucidaSansUnicode"). So I'm wondering  
> why a different name ("F3") appears in the content stream of the  
> >annotation. There is something else happening, I guess.
>
>
>
> I now remember that there was something years ago on stackoverflow  
> related to the cache algorithm, and the best way to get around this was  
> >to save and reload the file after having made changes in the default  
> resources. And only after that make changes in the fields.
>
> Also change "PDType0Font.load" so that it using 3 parameters, the  
> "embedSubset" should be false, so that the full font is embedded.
>
> But I could also use code with the 0-File:
>
>        PDField field =  
> doc.getDocumentCatalog().getAcroForm().getField("Text1");
>        field.setValue("05 Feb 2024");
>
> and it works because the Lucida font is already configured. Because the  
> font isn't embedded problems can occur if users don't have that font >on  
> their machine.
>
> Tilman
>
> On 30.04.2024 12:13, Jurgen Doll wrote:
>> Hi Tilman
>> I've uploaded the following series of test PDF's (a single text label  
>> and field) to DropBox that show how the PDF size grows with >>each  
>> subsequent save when there's an embedded font.
>> FontTest_0_Original.pdfFontTest_1_Fill_&_Save.pdf 
>> FontTest_2_Open_&_Save.pdfFontTest_3_Resave_(No_Changes).pdf 
>> FontTest_4_Open_&_Save.pdf
>> If I first check for the font with "if ( resources.getFont( cosName )  
>> == null )" then the following PDF is the result and subsequent >>saves  
>> don't grow in size.
>> FontTest_with_Check_(Open_&_Save).pdf
>>
>> https://www.dropbox.com/scl/fo/am1wdjihq94f4h0nyd604/AIGBihk-TA2IXTnwrLz5PPo?>>rlkey=zlpffg4ekrxh46y4q4s4d6b8y&st=nkohx8f5&dl=0
>>
>> Thanks, regardsJurgen
>>
>>
>> On Fri, 26 Apr 2024 16:03:47 +0200, Tilman Hausherr  
>> <TH...@t-online.de> wrote:
>>> Re "bigger each time it's opened and then saved", hard to tell without  
>>> the PDF. Maybe the font you're replacing is >>>used elsewhere due to  
>>> other code that used this font.
>>> If you can't share the PDF, look at it with PDFDebugger or with  
>>> NOTEPAD++. In PDFDebugger don't forget to switch >>>between the page  
>>> view and the internal structure view (in the view menu)
>>> Tilman
>>> On 26.04.2024 15:50, Jurgen Doll wrote:
>>>> Hi Tilman
>>>> My bad, I was working on the image code and just assumed that it was  
>>>> the culprit.It turns out that I must be embedding fonts incorrectly.  
>>>> I use this code each time I open the PDF:
>>>>    var resources = Objects.requireNonNullElseGet(  
>>>> pdForm.getDefaultResources(), >>>>PDResources::new );   var  
>>>> lucidaFont = PDType0Font.load( pdfDoc, LUCIDA_UNICODE_FILE.get() ); 
>>>>    var cosName = COSName.getPDFName( lucidaFont.getName() );
>>>>    resources.put( cosName, lucidaFont ); 
>>>>    pdForm.setDefaultResources( resources );
>>>> The above seems to make the PDF get bigger each time it's opened and  
>>>> then saved.So I've added a check first, like this:
>>>>    if ( resources.getFont( cosName ) == null )   { 
>>>>        resources.put( cosName, lucidaFont ); 
>>>>        pdForm.setDefaultResources( resources );   }
>>>> And now the PDF doesn't seem to be growing any more.
>>>> Thanks,Jurgen
>>
>> ---------------------------------------------------------------------To  
>> unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.orgFor additional  
>> commands, e-mail: users-help@pdfbox.apache.org
>
>



-- 
Using Opera's mail client: http://www.opera.com/mail/

Re: How to remove an image resource from a PDF form

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

What I see in the biggest file is that the font appears 3 times in the 
resources and 2 times in the default resources.

resources.put() forces the name ("LucidaSansUnicode"). So I'm wondering 
why a different name ("F3") appears in the content stream of the 
annotation. There is something else happening, I guess.


I now remember that there was something years ago on stackoverflow 
related to the cache algorithm, and the best way to get around this was 
to save and reload the file after having made changes in the default 
resources. And only after that make changes in the fields.

Also change "PDType0Font.load" so that it using 3 parameters, the 
"embedSubset" should be false, so that the full font is embedded.

But I could also use code with the 0-File:

         PDField field = 
doc.getDocumentCatalog().getAcroForm().getField("Text1");
         field.setValue("05 Feb 2024");

and it works because the Lucida font is already configured. Because the 
font isn't embedded problems can occur if users don't have that font on 
their machine.

Tilman

On 30.04.2024 12:13, Jurgen Doll wrote:
> Hi Tilman
>
> I've uploaded the following series of test PDF's (a single text label 
> and field) to DropBox that show how the PDF size grows with each 
> subsequent save when there's an embedded font.
>
> FontTest_0_Original.pdf
> FontTest_1_Fill_&_Save.pdf
> FontTest_2_Open_&_Save.pdf
> FontTest_3_Resave_(No_Changes).pdf
> FontTest_4_Open_&_Save.pdf
>
> If I first check for the font with "if ( resources.getFont( cosName ) 
> == null )" then the following PDF is the result and subsequent saves 
> don't grow in size.
>
> FontTest_with_Check_(Open_&_Save).pdf
>
>
> https://www.dropbox.com/scl/fo/am1wdjihq94f4h0nyd604/AIGBihk-TA2IXTnwrLz5PPo?rlkey=zlpffg4ekrxh46y4q4s4d6b8y&st=nkohx8f5&dl=0 
>
>
>
> Thanks, regards
> Jurgen
>
>
>
> On Fri, 26 Apr 2024 16:03:47 +0200, Tilman Hausherr 
> <TH...@t-online.de> wrote:
>
>> Re "bigger each time it's opened and then saved", hard to tell 
>> without the PDF. Maybe the font you're replacing is used elsewhere 
>> due to other code that used this font.
>>
>> If you can't share the PDF, look at it with PDFDebugger or with 
>> NOTEPAD++. In PDFDebugger don't forget to switch between the page 
>> view and the internal structure view (in the view menu)
>>
>> Tilman
>>
>> On 26.04.2024 15:50, Jurgen Doll wrote:
>>> Hi Tilman
>>>
>>> My bad, I was working on the image code and just assumed that it was 
>>> the culprit.
>>> It turns out that I must be embedding fonts incorrectly. I use this 
>>> code each time I open the PDF:
>>>
>>>     var resources = Objects.requireNonNullElseGet( 
>>> pdForm.getDefaultResources(), PDResources::new );
>>>     var lucidaFont = PDType0Font.load( pdfDoc, 
>>> LUCIDA_UNICODE_FILE.get() );
>>>     var cosName = COSName.getPDFName( lucidaFont.getName() );
>>>
>>>     resources.put( cosName, lucidaFont );
>>>     pdForm.setDefaultResources( resources );
>>>
>>> The above seems to make the PDF get bigger each time it's opened and 
>>> then saved.
>>> So I've added a check first, like this:
>>>
>>>     if ( resources.getFont( cosName ) == null )
>>>     {
>>>         resources.put( cosName, lucidaFont );
>>>         pdForm.setDefaultResources( resources );
>>>     }
>>>
>>> And now the PDF doesn't seem to be growing any more.
>>>
>>> Thanks,
>>> Jurgen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

Re: How to remove an image resource from a PDF form

Posted by Jurgen Doll <ju...@ivoryemr.co.za>.
Hi Tilman

I've uploaded the following series of test PDF's (a single text label and  
field) to DropBox that show how the PDF size grows with each subsequent  
save when there's an embedded font.

FontTest_0_Original.pdf
FontTest_1_Fill_&_Save.pdf
FontTest_2_Open_&_Save.pdf
FontTest_3_Resave_(No_Changes).pdf
FontTest_4_Open_&_Save.pdf

If I first check for the font with "if ( resources.getFont( cosName ) ==  
null )" then the following PDF is the result and subsequent saves don't  
grow in size.

FontTest_with_Check_(Open_&_Save).pdf


https://www.dropbox.com/scl/fo/am1wdjihq94f4h0nyd604/AIGBihk-TA2IXTnwrLz5PPo?rlkey=zlpffg4ekrxh46y4q4s4d6b8y&st=nkohx8f5&dl=0


Thanks, regards
Jurgen



On Fri, 26 Apr 2024 16:03:47 +0200, Tilman Hausherr  
<TH...@t-online.de> wrote:

> Re "bigger each time it's opened and then saved", hard to tell without  
> the PDF. Maybe the font you're replacing is used elsewhere due to other  
> code that used this font.
>
> If you can't share the PDF, look at it with PDFDebugger or with  
> NOTEPAD++. In PDFDebugger don't forget to switch between the page view  
> and the internal structure view (in the view menu)
>
> Tilman
>
> On 26.04.2024 15:50, Jurgen Doll wrote:
>> Hi Tilman
>>
>> My bad, I was working on the image code and just assumed that it was  
>> the culprit.
>> It turns out that I must be embedding fonts incorrectly. I use this  
>> code each time I open the PDF:
>>
>>     var resources = Objects.requireNonNullElseGet(  
>> pdForm.getDefaultResources(), PDResources::new );
>>     var lucidaFont = PDType0Font.load( pdfDoc,  
>> LUCIDA_UNICODE_FILE.get() );
>>     var cosName = COSName.getPDFName( lucidaFont.getName() );
>>
>>     resources.put( cosName, lucidaFont );
>>     pdForm.setDefaultResources( resources );
>>
>> The above seems to make the PDF get bigger each time it's opened and  
>> then saved.
>> So I've added a check first, like this:
>>
>>     if ( resources.getFont( cosName ) == null )
>>     {
>>         resources.put( cosName, lucidaFont );
>>         pdForm.setDefaultResources( resources );
>>     }
>>
>> And now the PDF doesn't seem to be growing any more.
>>
>> Thanks,
>> Jurgen

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


Re: How to remove an image resource from a PDF form

Posted by Tilman Hausherr <TH...@t-online.de>.
Re "bigger each time it's opened and then saved", hard to tell without 
the PDF. Maybe the font you're replacing is used elsewhere due to other 
code that used this font.

If you can't share the PDF, look at it with PDFDebugger or with 
NOTEPAD++. In PDFDebugger don't forget to switch between the page view 
and the internal structure view (in the view menu)

Tilman

On 26.04.2024 15:50, Jurgen Doll wrote:
> Hi Tilman
>
> My bad, I was working on the image code and just assumed that it was 
> the culprit.
> It turns out that I must be embedding fonts incorrectly. I use this 
> code each time I open the PDF:
>
>     var resources = Objects.requireNonNullElseGet( 
> pdForm.getDefaultResources(), PDResources::new );
>     var lucidaFont = PDType0Font.load( pdfDoc, 
> LUCIDA_UNICODE_FILE.get() );
>     var cosName = COSName.getPDFName( lucidaFont.getName() );
>
>     resources.put( cosName, lucidaFont );
>     pdForm.setDefaultResources( resources );
>
> The above seems to make the PDF get bigger each time it's opened and 
> then saved.
> So I've added a check first, like this:
>
>     if ( resources.getFont( cosName ) == null )
>     {
>         resources.put( cosName, lucidaFont );
>         pdForm.setDefaultResources( resources );
>     }
>
> And now the PDF doesn't seem to be growing any more.
>
> Thanks,
> Jurgen
>
>
>
> On Fri, 26 Apr 2024 14:58:26 +0200, Tilman Hausherr 
> <TH...@t-online.de> wrote:
>
>> Do you save directly or incrementally?
>>
>> If directly then the old one should be gone. If not, please share the 
>> PDF (upload to sharehoster) and tell us why you think it's still there.
>>
>> Tilman
>>
>> On 26.04.2024 12:37, Jurgen Doll wrote:
>>> Hi
>>>
>>> I would like to know how to remove an image resource from a PDF form.
>>>
>>> I use the following code to set an image object on a field:
>>>
>>>     private static void setAppearance( PDDocument pdfDoc, PDField 
>>> field, PDImageXObject image )
>>>     {
>>>         var widget = field.getWidgets().get(0);
>>>         var rect = widget.getRectangle();
>>>
>>>         var formObj = new PDFormXObject( new PDStream( pdfDoc ) );
>>>         formObj.setResources( new PDResources() );
>>>         formObj.setBBox( new PDRectangle
>>>         (
>>>             // The TransformationMatrix below enlarges the image 
>>> slightly,
>>>             // so adjust accordingly here otherwise the image is 
>>> cropped.
>>>             rect.getLowerLeftX(), rect.getLowerLeftY() - 10,
>>>             rect.getWidth(), rect.getHeight() + 20
>>>         ));
>>>         formObj.setFormType(1);
>>>
>>>         var appearanceStream = new PDAppearanceStream( 
>>> formObj.getCOSObject() );
>>>         var pageContentStream = new PDPageContentStream( pdfDoc, 
>>> appearanceStream );
>>>         pageContentStream.drawImage( image, getTransformationMatrix( 
>>> image, widget ) );
>>>         pageContentStream.close();
>>>
>>>         var appearance = new PDAppearanceDictionary();
>>>         appearance.setNormalAppearance( appearanceStream );
>>>         appearance.getCOSObject().setDirect( true );
>>>         widget.setAppearance( appearance );
>>>     }
>>>
>>> To remove the image I do "widget.setAppearance( null )" or to 
>>> replace the image I use the above method to set the new image as the 
>>> appearance. However I've noticed that this doesn't remove the 
>>> previous image object/resource from the PDF. How do I go about 
>>> removing it ?
>>>
>>> Thanks, regards
>>> Jurgen
>>>
>>> ---------------------------------------------------------------------
>>> 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: How to remove an image resource from a PDF form

Posted by Jurgen Doll <ju...@ivoryemr.co.za>.
Hi Tilman

My bad, I was working on the image code and just assumed that it was the  
culprit.
It turns out that I must be embedding fonts incorrectly. I use this code  
each time I open the PDF:

     var resources = Objects.requireNonNullElseGet(  
pdForm.getDefaultResources(), PDResources::new );
     var lucidaFont = PDType0Font.load( pdfDoc, LUCIDA_UNICODE_FILE.get() );
     var cosName = COSName.getPDFName( lucidaFont.getName() );

     resources.put( cosName, lucidaFont );
     pdForm.setDefaultResources( resources );

The above seems to make the PDF get bigger each time it's opened and then  
saved.
So I've added a check first, like this:

     if ( resources.getFont( cosName ) == null )
     {
         resources.put( cosName, lucidaFont );
         pdForm.setDefaultResources( resources );
     }

And now the PDF doesn't seem to be growing any more.

Thanks,
Jurgen



On Fri, 26 Apr 2024 14:58:26 +0200, Tilman Hausherr  
<TH...@t-online.de> wrote:

> Do you save directly or incrementally?
>
> If directly then the old one should be gone. If not, please share the  
> PDF (upload to sharehoster) and tell us why you think it's still there.
>
> Tilman
>
> On 26.04.2024 12:37, Jurgen Doll wrote:
>> Hi
>>
>> I would like to know how to remove an image resource from a PDF form.
>>
>> I use the following code to set an image object on a field:
>>
>>     private static void setAppearance( PDDocument pdfDoc, PDField  
>> field, PDImageXObject image )
>>     {
>>         var widget = field.getWidgets().get(0);
>>         var rect = widget.getRectangle();
>>
>>         var formObj = new PDFormXObject( new PDStream( pdfDoc ) );
>>         formObj.setResources( new PDResources() );
>>         formObj.setBBox( new PDRectangle
>>         (
>>             // The TransformationMatrix below enlarges the image  
>> slightly,
>>             // so adjust accordingly here otherwise the image is  
>> cropped.
>>             rect.getLowerLeftX(), rect.getLowerLeftY() - 10,
>>             rect.getWidth(), rect.getHeight() + 20
>>         ));
>>         formObj.setFormType(1);
>>
>>         var appearanceStream = new PDAppearanceStream(  
>> formObj.getCOSObject() );
>>         var pageContentStream = new PDPageContentStream( pdfDoc,  
>> appearanceStream );
>>         pageContentStream.drawImage( image, getTransformationMatrix(  
>> image, widget ) );
>>         pageContentStream.close();
>>
>>         var appearance = new PDAppearanceDictionary();
>>         appearance.setNormalAppearance( appearanceStream );
>>         appearance.getCOSObject().setDirect( true );
>>         widget.setAppearance( appearance );
>>     }
>>
>> To remove the image I do "widget.setAppearance( null )" or to replace  
>> the image I use the above method to set the new image as the  
>> appearance. However I've noticed that this doesn't remove the previous  
>> image object/resource from the PDF. How do I go about removing it ?
>>
>> Thanks, regards
>> Jurgen
>>
>> ---------------------------------------------------------------------
>> 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
>


-- 
Using Opera's mail client: http://www.opera.com/mail/

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


Re: How to remove an image resource from a PDF form

Posted by Tilman Hausherr <TH...@t-online.de>.
Do you save directly or incrementally?

If directly then the old one should be gone. If not, please share the 
PDF (upload to sharehoster) and tell us why you think it's still there.

Tilman

On 26.04.2024 12:37, Jurgen Doll wrote:
> Hi
>
> I would like to know how to remove an image resource from a PDF form.
>
> I use the following code to set an image object on a field:
>
>     private static void setAppearance( PDDocument pdfDoc, PDField 
> field, PDImageXObject image )
>     {
>         var widget = field.getWidgets().get(0);
>         var rect = widget.getRectangle();
>
>         var formObj = new PDFormXObject( new PDStream( pdfDoc ) );
>         formObj.setResources( new PDResources() );
>         formObj.setBBox( new PDRectangle
>         (
>             // The TransformationMatrix below enlarges the image 
> slightly,
>             // so adjust accordingly here otherwise the image is cropped.
>             rect.getLowerLeftX(), rect.getLowerLeftY() - 10,
>             rect.getWidth(), rect.getHeight() + 20
>         ));
>         formObj.setFormType(1);
>
>         var appearanceStream = new PDAppearanceStream( 
> formObj.getCOSObject() );
>         var pageContentStream = new PDPageContentStream( pdfDoc, 
> appearanceStream );
>         pageContentStream.drawImage( image, getTransformationMatrix( 
> image, widget ) );
>         pageContentStream.close();
>
>         var appearance = new PDAppearanceDictionary();
>         appearance.setNormalAppearance( appearanceStream );
>         appearance.getCOSObject().setDirect( true );
>         widget.setAppearance( appearance );
>     }
>
> To remove the image I do "widget.setAppearance( null )" or to replace 
> the image I use the above method to set the new image as the 
> appearance. However I've noticed that this doesn't remove the previous 
> image object/resource from the PDF. How do I go about removing it ?
>
> Thanks, regards
> Jurgen
>
> ---------------------------------------------------------------------
> 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


How to remove an image resource from a PDF form

Posted by Jurgen Doll <ju...@ivoryemr.co.za>.
Hi

I would like to know how to remove an image resource from a PDF form.

I use the following code to set an image object on a field:

     private static void setAppearance( PDDocument pdfDoc, PDField field,  
PDImageXObject image )
     {
         var widget = field.getWidgets().get(0);
         var rect = widget.getRectangle();

         var formObj = new PDFormXObject( new PDStream( pdfDoc ) );
         formObj.setResources( new PDResources() );
         formObj.setBBox( new PDRectangle
         (
             // The TransformationMatrix below enlarges the image slightly,
             // so adjust accordingly here otherwise the image is cropped.
             rect.getLowerLeftX(), rect.getLowerLeftY() - 10,
             rect.getWidth(), rect.getHeight() + 20
         ));
         formObj.setFormType(1);

         var appearanceStream = new PDAppearanceStream(  
formObj.getCOSObject() );
         var pageContentStream = new PDPageContentStream( pdfDoc,  
appearanceStream );
         pageContentStream.drawImage( image, getTransformationMatrix(  
image, widget ) );
         pageContentStream.close();

         var appearance = new PDAppearanceDictionary();
         appearance.setNormalAppearance( appearanceStream );
         appearance.getCOSObject().setDirect( true );
         widget.setAppearance( appearance );
     }

To remove the image I do "widget.setAppearance( null )" or to replace the  
image I use the above method to set the new image as the appearance.  
However I've noticed that this doesn't remove the previous image  
object/resource from the PDF. How do I go about removing it ?

Thanks, regards
Jurgen

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