[
https://issues.apache.org/jira/browse/PDFBOX-1778?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13823526#comment-13823526
]
Tilman Hausherr commented on PDFBOX-1778:
-----------------------------------------
There's an easy solution for writePDF.writePDF(), replace
{code}
output.write(formatDecimal.format( value ).getBytes("ISO-8859-1"));
{code}
with
{code}
output.write(formatDecimal.format(new
BigDecimal(String.valueOf(value))).getBytes("ISO-8859-1"));
{code}
and of course set back the MaximumFractionDigits to 10.
This test shows the difference:
{code}
DecimalFormat formatDecimal =
(DecimalFormat)NumberFormat.getNumberInstance();
formatDecimal.setMaximumFractionDigits( 10 );
formatDecimal.setGroupingUsed( false );
DecimalFormatSymbols symbols = formatDecimal.getDecimalFormatSymbols();
symbols.setDecimalSeparator( '.' );
formatDecimal.setDecimalFormatSymbols( symbols );
float value = 0.9505f;
System.out.println (formatDecimal.format(value)); //not so good
System.out.println (formatDecimal.format(new
BigDecimal(String.valueOf(value)))); //good
{code}
The output is
0.9505000114
0.9505
Due to lack of time I didn't test Michaels example.
> Rounding issue in generated PDF file
> ------------------------------------
>
> Key: PDFBOX-1778
> URL: https://issues.apache.org/jira/browse/PDFBOX-1778
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel, Signing
> Affects Versions: 1.8.3
> Reporter: vakhtang koroghlishvili
> Assignee: Andreas Lehmkühler
> Priority: Critical
> Fix For: 1.8.3, 2.0.0
>
> Attachments: extreme-values-red.pdf, extreme-values-red.png,
> extreme-values.pdf, extreme-values.png, original.pdf, saved.pdf
>
>
> We have PDF file which was signed by some other application.
> When we try to sign it with PDFbox, previous revision is damaged.
> We did some investigations and found such problem:
> (question on stackoverflow is here:
> http://stackoverflow.com/questions/19903884/pdf-document-is-modified-by-another-revision/19905271?noredirect=1#19905271
> )
> Some PDF tags are changed in new revisions.
> For example values of following tags:
> /WhitePoint
> /Gamma
> /Matrix
> are changed from values like this: 0.9505
> to values like this: 0.9505000114
> We think this is problem of converting float/double inside COSFloat.
> Following code just opens and saves PDF file and this operation changes
> values of mentioned text:
> public void saveTo(String sourceFile, String destFile) throws Exception{
> PDDocument doc = PDDocument.load(new FileInputStream(sourceFile));
> doc.save(new FileOutputStream(destFile));
> }
--
This message was sent by Atlassian JIRA
(v6.1#6144)