c# - Changing the zoom level in all link destinations in PDFs -
a code changes zoom level using itext in java given in @ itext home page. convert c#. after countless hours, have rewritten code find out didn't change link. means must have made errors.
edit:
as requested, please have @ simple pdf example.
my code follows:
using (var reader = new pdfreader(input)) { using (var stamper = new pdfstamper(reader, ms)) { (int = 1; <= reader.numberofpages; i++) { // page of pdf page pdfdictionary page = reader.getpagen(i); // annotations of page pdfarray annotsarray = page.getasarray(pdfname.annots); // if page not have annotations if (annotsarray == null) { continue; } // each annotation (int j = 0; j < annotsarray.size; j++) { // current annotation pdfdictionary annotation = annotsarray.getasdict(j); // test if link pdfdictionary annotationaction = annotation.getasdict(pdfname.a); if ( annotationaction == null || pdfname.link.equals(annotationaction.get(pdfname.s)) ) { pdfarray d = annotation.getasarray(pdfname.dest); if (d != null && d.length == 5 && pdfname.xyz.equals(d.getasname(1))) { d[4] = new pdfnumber(150); } } } } } } original code in java shorter:
public void manipulatepdf(string src, string dest) throws ioexception, documentexception { pdfreader reader = new pdfreader(src); pdfdictionary page = reader.getpagen(11); pdfarray annots = page.getasarray(pdfname.annots); (int = 0; < annots.size(); i++) { pdfdictionary annotation = annots.getasdict(i); if (pdfname.link.equals(annotation.getasname(pdfname.subtype))) { pdfarray d = annotation.getasarray(pdfname.dest); if (d != null && d.size() == 5 && pdfname.xyz.equals(d.getasname(1))) d.set(4, new pdfnumber(0)); } } pdfstamper stamper = new pdfstamper(reader, new fileoutputstream(dest)); stamper.close(); } updated edit 2
thanks @mkl i've came solution.
for (int = 1; <= reader.numberofpages; i++) { pdfdictionary page = reader.getpagen(i); pdfarray annotsarray = page.getasarray(pdfname.annots); if (annotsarray == null) { continue; } (int j = 0; j < annotsarray.size; j++) { pdfdictionary annotation = annotsarray.getasdict(j); pdfdictionary annotationaction = annotation.getasdict(pdfname.a); if (pdfname.goto.equals(annotationaction.get(pdfname.s))) { pdfarray d = annotationaction.getasarray(pdfname.d); if (d != null) { console.writeline(d[4]); d[4] = new pdfnumber(1.20); } } } }
if @ specification of link annotations, see
a dictionary (optional; pdf 1.1) action shall performed when link annotation activated (see 12.6, “actions”).
dest array, name or byte string (optional; not permitted if a entry present) destination shall displayed when annotation activated (see 12.3.2, “destinations”).
(table 173 – additional entries specific link annotation - iso 32000-1)
i.e. both original java code , port handle 1 kind of link annotations, kind using dest entry.
inspecting sample pdf, though, 1 finds link annotations a entry, e.g.
/a << /d [ 1 /xyz 0.000001 842 0.724 ] /s /goto >> thus, code has consider possible options. in particular if pdf manipulate has action defined instead of destination, has process destination of action instead of merely non-existent link destination.
Comments
Post a Comment