[iText-questions] Precision Fix
Hi, We are using iTextSharp to write out pdfs, however there was an issue with precision. We enabled ByteBuffer.HIGH_PRECISION, but also needed to make the following code change to PdfContentBytes.cs (Basically so we can pass in double precision values). public void LineTo(float x, float y) { LineTo((double)x,(double)y); } public void LineTo(double x, double y) { if (inText) { if (IsTagged()) { EndText(); } else { throw new IllegalPdfSyntaxException( MessageLocalization.GetComposedMessage("path.construction.operator.inside.text.object")); } } content.Append(x).Append(' ').Append(y).Append(" l").Append_i(separator); } public void MoveTo(float x, float y) { MoveTo((double)x,(double)y); } public void MoveTo(double x, double y) { if (inText) { if (IsTagged()) { EndText(); } else { throw new IllegalPdfSyntaxException( MessageLocalization.GetComposedMessage("path.construction.operator.inside.text.object")); } } content.Append(x).Append(' ').Append(y).Append(" m").Append_i(separator); } If you'd like to apply those changes (and I guess to the other drawing functions too) that would be great. Kind Regards Mark Duffill Mark Duffill Programmer Development Team -- Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Re: [iText-questions] Precision Fix
Op 8/08/2013 11:42, Mark Duffill schreef: > > Hi, > > We are using iTextSharp to write out pdfs, however there was an issue > with precision. > > We enabled ByteBuffer.HIGH_PRECISION, but also needed to make the > following code change to PdfContentBytes.cs > > (Basically so we can pass in double precision values). > I don't know about iTextSharp, but in iText, the casting is done in the ByteBuffer class: /** * Appends a string representation of a float according * to the Pdf conventions. * @param i the float to be appended * @return a reference to this ByteBuffer object */ public ByteBuffer append(float i) { return append((double)i); } This makes your fix unnecessary, doesn't it? I see that the same happens in iTextSharp: /** * Appends a string representation of a float according * to the Pdf conventions. * @param i the float to be appended * @return a reference to this ByteBuffer object */ public ByteBuffer Append(float i) { return Append((double)i); } Why would we need to cast the float value to double values in each drawing function if the casting is done in ByteBuffer? Please explain. -- Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Re: [iText-questions] Precision Fix
Hi, Yeah I see what you mean, however this is the use case: (pseudo code) Class point { double x; double y; }; Foreach point p in points { Pcb.LineTo((float)p.x,(float)p.y); } When working with very fine detail and accuracy we need to keep the precision. So basically the issue is iTextSharp does not have overloaded MoveTo/LineTo etc methods that take doubles, *forcing* us to cast to floats, thus loosing precision. Hope this makes sense. Thanks Mark -Original Message- From: iText Info [mailto:i...@1t3xt.info] Sent: 08 August 2013 12:13 To: itext-questions@lists.sourceforge.net Subject: Re: [iText-questions] Precision Fix Op 8/08/2013 11:42, Mark Duffill schreef: > > Hi, > > We are using iTextSharp to write out pdfs, however there was an issue > with precision. > > We enabled ByteBuffer.HIGH_PRECISION, but also needed to make the > following code change to PdfContentBytes.cs > > (Basically so we can pass in double precision values). > I don't know about iTextSharp, but in iText, the casting is done in the ByteBuffer class: /** * Appends a string representation of a float according * to the Pdf conventions. * @param i the float to be appended * @return a reference to this ByteBuffer object */ public ByteBuffer append(float i) { return append((double)i); } This makes your fix unnecessary, doesn't it? I see that the same happens in iTextSharp: /** * Appends a string representation of a float according * to the Pdf conventions. * @param i the float to be appended * @return a reference to this ByteBuffer object */ public ByteBuffer Append(float i) { return Append((double)i); } Why would we need to cast the float value to double values in each drawing function if the casting is done in ByteBuffer? Please explain. -- Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
[iText-questions] I'm having trouble signing pdf in my application.
Hello everybody, the problem is that the class asks PrivateKeySignature java.security.RSAPrivatekey as one parameter and returns a sun.security.mscapi.RSAPrivateKey my provider. So when I try to instantiate the class an exception is thrown: SEVERE: null java.lang.ClassCastException: sun.security.mscapi.RSAPrivateKey cannot be cast to java.security.interfaces.RSAKey at sun.security.pkcs11.P11Signature.engineInitSign(P11Signature.java:384) at java.security.Signature$Delegate.engineInitSign(Unknown Source) at java.security.Signature.initSign(Unknown Source) at com.itextpdf.text.pdf.security.PrivateKeySignature.sign(PrivateKeySignature.java:114) at com.itextpdf.text.pdf.security.MakeSignature.signDetached(MakeSignature.java:150) == Meu codigo: BouncyCastleProvider providerBC = new BouncyCastleProvider(); Security.addProvider(providerBC); Provider pkcs11Provider = new SunPKCS11(new ByteArrayInputStream(tokenConfiguration.getBytes())); Security.addProvider(pkcs11Provider); KeyStore ks = KeyStore.getInstance("Windows-MY"); ks.load(null, null); key = (PrivateKey)ks.getKey(alias,password); chain = ks.getCertificateChain(alias); OcspClient ocspClient = new OcspClientBouncyCastle(); TSAClient tsaClient = null; for (int i = 0; i < chain.length; i++) { X509Certificate cert = (X509Certificate) chain[i]; String tsaUrl = CertificateUtil.getTSAURL(cert); if (tsaUrl != null) { tsaClient = new TSAClientBouncyCastle(tsaUrl); break; } } List crlList = new ArrayList(); crlList.add(new CrlClientOnline(chain)); LoggerFactory.getInstance().setLogger(new SysoLogger()); boolean isOK = false; PdfReader reader; try { filenameforsign = this.temp+filenameforsign; reader = new PdfReader(filenameforsign); String arquivoAssinado = filenameforsign.substring(0, filenameforsign.lastIndexOf(".")) + "_signed.pdf"; FileOutputStream fout = new FileOutputStream(arquivoAssinado); PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0'); PdfSignatureAppearance sap = stp.getSignatureAppearance(); //sap.setCrypto( key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.setReason(reason); sap.setLocation(location); sap.setCertificate(chain[0]); sap.setVisibleSignature(new Rectangle(alturaAssinatura, margemEsquerda, alturaAssinatura-50, margemEsquerda+50), reader.getNumberOfPages(), null); //Creating the signature ExternalDigest digest = new BouncyCastleDigest(); ExternalSignature signature = new PrivateKeySignature( key, DigestAlgorithms.SHA256, provider); MakeSignature.signDetached( sap, digest, signature, chain, crlList, ocspClient, tsaClient , 0, MakeSignature.CryptoStandard.CMS); stp.close(); isOK = true; } catch (IOException ex) { ex.printStackTrace(); System.out.println("Erro de IO"); } catch (DocumentException e) { e.printStackTrace(); System.out.println("Erro de Documento"); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(null, "Falha ao receber parĂ¢metros."+ex.getMessage(), "ERRO", JOptionPane.INFORMATION_MESSAGE); } == Alguem ja passed why or know how solve the problem? Hugs. -- View this message in context: http://itext-general.2136553.n4.nabble.com/I-m-having-trouble-signing-pdf-in-my-application-tp4658891.html Sent from the iText - General mailing list archive at Nabble.com. -- Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk ___ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com